Ehrii commited on
Commit
54b27c2
·
1 Parent(s): f78408f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +6 -3
main.py CHANGED
@@ -31,7 +31,7 @@ ENGLISH_MODEL_NAME = "siebert/sentiment-roberta-large-english"
31
  try:
32
  multilingual_tokenizer = AutoTokenizer.from_pretrained(
33
  MULTILINGUAL_TOKENIZER_NAME,
34
- use_auth_token=HF_TOKEN,
35
  cache_dir=cache_dir
36
  )
37
 
@@ -39,7 +39,7 @@ try:
39
  "sentiment-analysis",
40
  model=MULTILINGUAL_MODEL_NAME,
41
  tokenizer=multilingual_tokenizer,
42
- token=HF_TOKEN
43
  )
44
  except Exception as e:
45
  raise RuntimeError(f"Failed to load multilingual model: {e}")
@@ -49,7 +49,7 @@ try:
49
  english_model = pipeline(
50
  "sentiment-analysis",
51
  model=ENGLISH_MODEL_NAME,
52
- token=HF_TOKEN
53
  )
54
  except Exception as e:
55
  raise RuntimeError(f"Failed to load English sentiment model: {e}")
@@ -81,7 +81,10 @@ def analyze_sentiment(request: SentimentRequest):
81
  raise HTTPException(status_code=400, detail="Text input cannot be empty.")
82
 
83
  language = detect_language(text)
 
 
84
  model = english_model if language == "en" else multilingual_model
 
85
  result = model(text)
86
 
87
  return SentimentResponse(
 
31
  try:
32
  multilingual_tokenizer = AutoTokenizer.from_pretrained(
33
  MULTILINGUAL_TOKENIZER_NAME,
34
+ token=HF_TOKEN, # Pass token here
35
  cache_dir=cache_dir
36
  )
37
 
 
39
  "sentiment-analysis",
40
  model=MULTILINGUAL_MODEL_NAME,
41
  tokenizer=multilingual_tokenizer,
42
+ token=HF_TOKEN # Pass token here
43
  )
44
  except Exception as e:
45
  raise RuntimeError(f"Failed to load multilingual model: {e}")
 
49
  english_model = pipeline(
50
  "sentiment-analysis",
51
  model=ENGLISH_MODEL_NAME,
52
+ token=HF_TOKEN # Pass token here
53
  )
54
  except Exception as e:
55
  raise RuntimeError(f"Failed to load English sentiment model: {e}")
 
81
  raise HTTPException(status_code=400, detail="Text input cannot be empty.")
82
 
83
  language = detect_language(text)
84
+
85
+ # Use English model if detected language is English; otherwise, use multilingual model
86
  model = english_model if language == "en" else multilingual_model
87
+
88
  result = model(text)
89
 
90
  return SentimentResponse(