Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -20,6 +20,9 @@ HF_TOKEN = os.getenv("HF_TOKEN")
|
|
| 20 |
if not HF_TOKEN:
|
| 21 |
raise RuntimeError("Hugging Face token is missing! Please set the HF_TOKEN environment variable.")
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
app = FastAPI()
|
| 24 |
|
| 25 |
# Model names
|
|
@@ -31,15 +34,13 @@ ENGLISH_MODEL_NAME = "siebert/sentiment-roberta-large-english"
|
|
| 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 |
|
| 38 |
multilingual_model = pipeline(
|
| 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}")
|
|
@@ -48,8 +49,7 @@ except Exception as e:
|
|
| 48 |
try:
|
| 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}")
|
|
|
|
| 20 |
if not HF_TOKEN:
|
| 21 |
raise RuntimeError("Hugging Face token is missing! Please set the HF_TOKEN environment variable.")
|
| 22 |
|
| 23 |
+
# Set the Hugging Face token in the environment variable
|
| 24 |
+
os.environ["HUGGINGFACE_HUB_TOKEN"] = HF_TOKEN
|
| 25 |
+
|
| 26 |
app = FastAPI()
|
| 27 |
|
| 28 |
# Model names
|
|
|
|
| 34 |
try:
|
| 35 |
multilingual_tokenizer = AutoTokenizer.from_pretrained(
|
| 36 |
MULTILINGUAL_TOKENIZER_NAME,
|
|
|
|
| 37 |
cache_dir=cache_dir
|
| 38 |
)
|
| 39 |
|
| 40 |
multilingual_model = pipeline(
|
| 41 |
"sentiment-analysis",
|
| 42 |
model=MULTILINGUAL_MODEL_NAME,
|
| 43 |
+
tokenizer=multilingual_tokenizer
|
|
|
|
| 44 |
)
|
| 45 |
except Exception as e:
|
| 46 |
raise RuntimeError(f"Failed to load multilingual model: {e}")
|
|
|
|
| 49 |
try:
|
| 50 |
english_model = pipeline(
|
| 51 |
"sentiment-analysis",
|
| 52 |
+
model=ENGLISH_MODEL_NAME
|
|
|
|
| 53 |
)
|
| 54 |
except Exception as e:
|
| 55 |
raise RuntimeError(f"Failed to load English sentiment model: {e}")
|