EfektMotyla commited on
Commit
94eceb2
·
verified ·
1 Parent(s): 38026de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -83,12 +83,25 @@ aspect_aliases = {
83
  "value": "cena", "experience": "doświadczenie", "recommendation": "ogólna ocena",
84
  "children": "dzieci", "family": "rodzina", "pet": "zwierzęta"
85
  }
86
- def translate_pl_to_en(texts):
87
- return [res["translation_text"] for res in pl_to_en(texts)]
 
 
 
 
 
 
 
88
 
89
 
90
- def translate_en_to_pl(texts):
91
- return [res["translation_text"] for res in en_to_pl(texts)]
 
 
 
 
 
 
92
 
93
 
94
  def extract_aspects(text_en: str):
 
83
  "value": "cena", "experience": "doświadczenie", "recommendation": "ogólna ocena",
84
  "children": "dzieci", "family": "rodzina", "pet": "zwierzęta"
85
  }
86
+ # ───────────────────── tłumaczenia ──────────────────────
87
+ def translate_pl_to_en(texts: list[str]) -> list[str]:
88
+ inputs = pl_to_en_tok(texts,
89
+ return_tensors="pt",
90
+ padding=True,
91
+ truncation=True).to(device)
92
+ with torch.no_grad():
93
+ generated = pl_to_en_mod.generate(**inputs)
94
+ return pl_to_en_tok.batch_decode(generated, skip_special_tokens=True)
95
 
96
 
97
+ def translate_en_to_pl(texts: list[str]) -> list[str]:
98
+ inputs = en_to_pl_tok(texts,
99
+ return_tensors="pt",
100
+ padding=True,
101
+ truncation=True).to(device)
102
+ with torch.no_grad():
103
+ generated = en_to_pl_mod.generate(**inputs)
104
+ return en_to_pl_tok.batch_decode(generated, skip_special_tokens=True)
105
 
106
 
107
  def extract_aspects(text_en: str):