Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,16 +2,23 @@ from fastapi import FastAPI
|
|
2 |
from transformers import BertForSequenceClassification, AutoTokenizer
|
3 |
import torch
|
4 |
import os
|
5 |
-
# β
Ensure HF_API_KEY is set
|
6 |
-
HF_TOKEN = os.getenv("HF_API_KEY")
|
7 |
|
8 |
-
if not HF_TOKEN:
|
9 |
-
raise ValueError("β HF_API_KEY is missing! Set it in Hugging Face Spaces Secrets.")
|
10 |
-
|
11 |
-
# β
Load trained FinBERT model
|
12 |
MODEL_PATH = "hariharan220/finbert-stock-sentiment"
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# β
Define sentiment labels
|
17 |
labels = ["Negative", "Neutral", "Positive"]
|
|
|
2 |
from transformers import BertForSequenceClassification, AutoTokenizer
|
3 |
import torch
|
4 |
import os
|
|
|
|
|
5 |
|
|
|
|
|
|
|
|
|
6 |
MODEL_PATH = "hariharan220/finbert-stock-sentiment"
|
7 |
+
|
8 |
+
# β
Load Hugging Face API token from environment variable
|
9 |
+
HF_API_TOKEN = os.getenv("HF_API_KEY") # Change from HF_API_TOKEN to HF_API_KEY
|
10 |
+
if not HF_API_TOKEN:
|
11 |
+
raise ValueError("β ERROR: Hugging Face API Key (HF_API_KEY) is missing. Set it in your environment variables.")
|
12 |
+
|
13 |
+
# β
Authenticate when loading model
|
14 |
+
model = BertForSequenceClassification.from_pretrained(
|
15 |
+
MODEL_PATH,
|
16 |
+
use_auth_token=HF_API_TOKEN
|
17 |
+
)
|
18 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
19 |
+
MODEL_PATH,
|
20 |
+
use_auth_token=HF_API_TOKEN
|
21 |
+
)
|
22 |
|
23 |
# β
Define sentiment labels
|
24 |
labels = ["Negative", "Neutral", "Positive"]
|