Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,19 +6,24 @@ import os
|
|
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")
|
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 |
-
|
17 |
)
|
18 |
tokenizer = AutoTokenizer.from_pretrained(
|
19 |
MODEL_PATH,
|
20 |
-
|
21 |
)
|
|
|
22 |
|
23 |
# β
Define sentiment labels
|
24 |
labels = ["Negative", "Neutral", "Positive"]
|
|
|
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")
|
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 |
+
print("π Authenticating with Hugging Face...")
|
15 |
+
os.system(f"huggingface-cli login --token {HF_API_TOKEN}")
|
16 |
+
|
17 |
+
print("π Loading Model...")
|
18 |
model = BertForSequenceClassification.from_pretrained(
|
19 |
MODEL_PATH,
|
20 |
+
token=HF_API_TOKEN # Explicit authentication
|
21 |
)
|
22 |
tokenizer = AutoTokenizer.from_pretrained(
|
23 |
MODEL_PATH,
|
24 |
+
token=HF_API_TOKEN # Explicit authentication
|
25 |
)
|
26 |
+
print("β
Model Loaded Successfully!")
|
27 |
|
28 |
# β
Define sentiment labels
|
29 |
labels = ["Negative", "Neutral", "Positive"]
|