EfektMotyla commited on
Commit
668f19f
Β·
verified Β·
1 Parent(s): 87cce36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -20,6 +20,10 @@ ROOT = Path(__file__).parent
20
 
21
  aspect_dir = ROOT / "bert-aspect-ner"
22
  sentiment_dir = ROOT / "absa-roberta"
 
 
 
 
23
  # ────────────────────── modele lokalne ─────────────────────
24
  aspect_tokenizer = AutoTokenizer.from_pretrained(
25
  str(aspect_dir), local_files_only=True, use_fast=False # ← jeΕ›li brak tokenizer.json
@@ -36,13 +40,15 @@ sentiment_model = AutoModelForSequenceClassification.from_pretrained(
36
  ).to(device)
37
 
38
  # ────────────────────── modele tΕ‚umaczeΕ„ (on-line) ─────────
 
 
39
 
40
- model_name = "Helsinki-NLP/opus-mt-pl-en"
41
- pl_to_en_tokenizer = MarianTokenizer.from_pretrained("translation-pl-en")
42
- pl_to_en_model = MarianMTModel.from_pretrained("translation-pl-en").to(device)
43
 
44
- en_to_pl_tokenizer = MarianTokenizer.from_pretrained("translation-en-pl")
45
- en_to_pl_model = MarianMTModel.from_pretrained("translation-en-pl").to(device)
46
 
47
  # πŸ” Funkcje tΕ‚umaczeΕ„
48
  def translate_pl_to_en(texts):
 
20
 
21
  aspect_dir = ROOT / "bert-aspect-ner"
22
  sentiment_dir = ROOT / "absa-roberta"
23
+
24
+
25
+ device = "cuda" if torch.cuda.is_available() else "cpu"
26
+ hf_token = os.getenv("HF_TOKEN")
27
  # ────────────────────── modele lokalne ─────────────────────
28
  aspect_tokenizer = AutoTokenizer.from_pretrained(
29
  str(aspect_dir), local_files_only=True, use_fast=False # ← jeΕ›li brak tokenizer.json
 
40
  ).to(device)
41
 
42
  # ────────────────────── modele tΕ‚umaczeΕ„ (on-line) ─────────
43
+ pl_to_en_dir = snapshot_download("Helsinki-NLP/opus-mt-pl-en", token=hf_token)
44
+ en_to_pl_dir = snapshot_download("gsarti/opus-mt-tc-en-pl", token=hf_token)
45
 
46
+ # πŸ“š Ładowanie tokenizerΓ³w i modeli
47
+ pl_to_en_tokenizer = MarianTokenizer.from_pretrained(pl_to_en_dir)
48
+ pl_to_en_model = MarianMTModel.from_pretrained(pl_to_en_dir).to(device)
49
 
50
+ en_to_pl_tokenizer = MarianTokenizer.from_pretrained(en_to_pl_dir)
51
+ en_to_pl_model = MarianMTModel.from_pretrained(en_to_pl_dir).to(device)
52
 
53
  # πŸ” Funkcje tΕ‚umaczeΕ„
54
  def translate_pl_to_en(texts):