EfektMotyla commited on
Commit
e69a3fb
verified
1 Parent(s): bc5909d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -7,6 +7,7 @@ from transformers import (
7
  )
8
  import torch
9
  import os
 
10
 
11
  hf_token = os.getenv("HF_TOKEN")
12
 
@@ -24,8 +25,19 @@ sentiment_model = AutoModelForSequenceClassification.from_pretrained(
24
  "EfektMotyla/absa-roberta", token=hf_token
25
  ).to(device)
26
 
27
- pl_to_en = pipeline("translation", model="Helsinki-NLP/opus-mt-pl-en", device=0 if device == "cuda" else -1)
28
- en_to_pl = pipeline("translation", model="gsarti/opus-mt-tc-en-pl", device=0 if device == "cuda" else -1)
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  # === Dane wej艣ciowe i wyj艣ciowe ===
31
  class Comment(BaseModel):
@@ -84,6 +96,8 @@ def extract_aspects(text_en):
84
  return list(set([a.lower() for a in aspects]))
85
 
86
  # === G艂贸wna funkcja API ===
 
 
87
  @app.post("/analyze", response_model=AnalysisResult)
88
  def analyze_comment(comment: Comment):
89
  text_pl = comment.text
 
7
  )
8
  import torch
9
  import os
10
+ device = "cuda" if torch.cuda.is_available() else "cpu"
11
 
12
  hf_token = os.getenv("HF_TOKEN")
13
 
 
25
  "EfektMotyla/absa-roberta", token=hf_token
26
  ).to(device)
27
 
28
+ pl_to_en = pipeline(
29
+ "translation",
30
+ model="Helsinki-NLP/opus-mt-pl-en",
31
+ device=0 if device == "cuda" else -1,
32
+ token=hf_token
33
+ )
34
+
35
+ en_to_pl = pipeline(
36
+ "translation",
37
+ model="gsarti/opus-mt-tc-en-pl",
38
+ device=0 if device == "cuda" else -1,
39
+ token=hf_token
40
+ )
41
 
42
  # === Dane wej艣ciowe i wyj艣ciowe ===
43
  class Comment(BaseModel):
 
96
  return list(set([a.lower() for a in aspects]))
97
 
98
  # === G艂贸wna funkcja API ===
99
+ app = FastAPI()
100
+
101
  @app.post("/analyze", response_model=AnalysisResult)
102
  def analyze_comment(comment: Comment):
103
  text_pl = comment.text