Ehrii commited on
Commit
9ba2aea
·
1 Parent(s): 509e078

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -9
main.py CHANGED
@@ -7,7 +7,7 @@ from langdetect import detect, DetectorFactory
7
  # Ensure consistent language detection results
8
  DetectorFactory.seed = 0
9
 
10
- # Use /tmp for Hugging Face cache to avoid permission errors
11
  os.environ["HF_HOME"] = "/tmp/huggingface_cache"
12
  os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface_cache"
13
 
@@ -24,23 +24,22 @@ app = FastAPI()
24
 
25
  # Model names
26
  MULTILINGUAL_MODEL_NAME = "Ehrii/sentiment"
27
- MULTILINGUAL_TOKENIZER_NAME = "tabularisai/multilingual-sentiment-analysis" # Correct tokenizer
28
  ENGLISH_MODEL_NAME = "siebert/sentiment-roberta-large-english"
29
 
30
  # Load multilingual sentiment model
31
  try:
32
  multilingual_tokenizer = AutoTokenizer.from_pretrained(
33
- MULTILINGUAL_TOKENIZER_NAME, # Use correct tokenizer
34
- token=HF_TOKEN,
35
  cache_dir=cache_dir
36
  )
37
-
38
  multilingual_model = pipeline(
39
  "sentiment-analysis",
40
  model=MULTILINGUAL_MODEL_NAME,
41
  tokenizer=multilingual_tokenizer,
42
- token=HF_TOKEN,
43
- cache_dir=cache_dir
44
  )
45
  except Exception as e:
46
  raise RuntimeError(f"Failed to load multilingual model: {e}")
@@ -50,8 +49,7 @@ try:
50
  english_model = pipeline(
51
  "sentiment-analysis",
52
  model=ENGLISH_MODEL_NAME,
53
- token=HF_TOKEN,
54
- cache_dir=cache_dir
55
  )
56
  except Exception as e:
57
  raise RuntimeError(f"Failed to load English sentiment model: {e}")
 
7
  # Ensure consistent language detection results
8
  DetectorFactory.seed = 0
9
 
10
+ # Set Hugging Face cache directory
11
  os.environ["HF_HOME"] = "/tmp/huggingface_cache"
12
  os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface_cache"
13
 
 
24
 
25
  # Model names
26
  MULTILINGUAL_MODEL_NAME = "Ehrii/sentiment"
27
+ MULTILINGUAL_TOKENIZER_NAME = "tabularisai/multilingual-sentiment-analysis"
28
  ENGLISH_MODEL_NAME = "siebert/sentiment-roberta-large-english"
29
 
30
  # Load multilingual sentiment model
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
+
38
  multilingual_model = pipeline(
39
  "sentiment-analysis",
40
  model=MULTILINGUAL_MODEL_NAME,
41
  tokenizer=multilingual_tokenizer,
42
+ use_auth_token=HF_TOKEN
 
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
+ use_auth_token=HF_TOKEN
 
53
  )
54
  except Exception as e:
55
  raise RuntimeError(f"Failed to load English sentiment model: {e}")