EfektMotyla commited on
Commit
cf3ea01
·
verified ·
1 Parent(s): ac5bc5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -5
app.py CHANGED
@@ -15,7 +15,6 @@ aspect_model = AutoModelForTokenClassification.from_pretrained("EfektMotyla/bert
15
  sentiment_tokenizer = AutoTokenizer.from_pretrained("EfektMotyla/absa-roberta")
16
  sentiment_model = AutoModelForSequenceClassification.from_pretrained("EfektMotyla/absa-roberta").to(device)
17
 
18
- # === Lżejsze tłumaczenie Hugging Face pipeline ===
19
  pl_to_en_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-pl-en", device=0 if torch.cuda.is_available() else -1)
20
  en_to_pl_translator = pipeline("translation", model="gsarti/opus-mt-tc-en-pl", device=0 if torch.cuda.is_available() else -1)
21
 
@@ -156,7 +155,7 @@ aspect_aliases = {
156
  "temperature": "komfort",
157
  "air conditioning": "komfort",
158
 
159
- # 🔁 OGÓLNE WRAŻENIE / WARTOŚĆ
160
  "recommendation": "ogólna ocena",
161
  "return": "ogólna ocena",
162
  "again": "ogólna ocena",
@@ -228,7 +227,6 @@ def analyze(text_pl, progress=gr.Progress()):
228
  if not aspects_en:
229
  return "Nie wykryto żadnych aspektów."
230
 
231
- # ✅ Usuń duplikaty (i sortuj dla powtarzalności)
232
  unique_aspects = sorted(set([asp.lower() for asp in aspects_en]))
233
  results = []
234
  seen_pl_aspects = set()
@@ -243,7 +241,7 @@ def analyze(text_pl, progress=gr.Progress()):
243
  predicted_class_id = int(logits.argmax().cpu())
244
  sentiment_label = {0: "negatywny", 1: "neutralny", 2: "pozytywny", 3: "konfliktowy"}[predicted_class_id]
245
 
246
- # Tłumaczenie aspektu przez słownik lub model
247
  if asp in aspect_aliases:
248
  asp_pl = aspect_aliases[asp]
249
  else:
@@ -256,7 +254,7 @@ def analyze(text_pl, progress=gr.Progress()):
256
  return "\n".join(results)
257
 
258
  except Exception as e:
259
- return f"Błąd podczas analizy: {e}"
260
 
261
  # === Gradio UI ===
262
  demo = gr.Interface(
 
15
  sentiment_tokenizer = AutoTokenizer.from_pretrained("EfektMotyla/absa-roberta")
16
  sentiment_model = AutoModelForSequenceClassification.from_pretrained("EfektMotyla/absa-roberta").to(device)
17
 
 
18
  pl_to_en_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-pl-en", device=0 if torch.cuda.is_available() else -1)
19
  en_to_pl_translator = pipeline("translation", model="gsarti/opus-mt-tc-en-pl", device=0 if torch.cuda.is_available() else -1)
20
 
 
155
  "temperature": "komfort",
156
  "air conditioning": "komfort",
157
 
158
+ # OGÓLNE WRAŻENIE / WARTOŚĆ
159
  "recommendation": "ogólna ocena",
160
  "return": "ogólna ocena",
161
  "again": "ogólna ocena",
 
227
  if not aspects_en:
228
  return "Nie wykryto żadnych aspektów."
229
 
 
230
  unique_aspects = sorted(set([asp.lower() for asp in aspects_en]))
231
  results = []
232
  seen_pl_aspects = set()
 
241
  predicted_class_id = int(logits.argmax().cpu())
242
  sentiment_label = {0: "negatywny", 1: "neutralny", 2: "pozytywny", 3: "konfliktowy"}[predicted_class_id]
243
 
244
+ # Tłumaczenie aspektu przez słownik lub model
245
  if asp in aspect_aliases:
246
  asp_pl = aspect_aliases[asp]
247
  else:
 
254
  return "\n".join(results)
255
 
256
  except Exception as e:
257
+ return f"Błąd podczas analizy: {e}"
258
 
259
  # === Gradio UI ===
260
  demo = gr.Interface(