Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,24 +5,28 @@ import os
|
|
5 |
|
6 |
MODEL_PATH = "hariharan220/finbert-stock-sentiment"
|
7 |
|
8 |
-
# β
Load Hugging Face API
|
9 |
-
|
10 |
-
if not
|
11 |
raise ValueError("β ERROR: Hugging Face API Key (HF_API_KEY) is missing. Set it in your environment variables.")
|
12 |
|
13 |
-
# β
|
14 |
-
|
15 |
-
os.
|
|
|
16 |
|
17 |
-
print("π
|
|
|
|
|
18 |
model = BertForSequenceClassification.from_pretrained(
|
19 |
MODEL_PATH,
|
20 |
-
token=
|
21 |
)
|
22 |
tokenizer = AutoTokenizer.from_pretrained(
|
23 |
MODEL_PATH,
|
24 |
-
token=
|
25 |
)
|
|
|
26 |
print("β
Model Loaded Successfully!")
|
27 |
|
28 |
# β
Define sentiment labels
|
|
|
5 |
|
6 |
MODEL_PATH = "hariharan220/finbert-stock-sentiment"
|
7 |
|
8 |
+
# β
Load Hugging Face API Key from environment variables
|
9 |
+
HF_API_KEY = os.getenv("HF_API_KEY")
|
10 |
+
if not HF_API_KEY:
|
11 |
raise ValueError("β ERROR: Hugging Face API Key (HF_API_KEY) is missing. Set it in your environment variables.")
|
12 |
|
13 |
+
# β
Configure authentication for Hugging Face
|
14 |
+
os.environ["HF_HOME"] = "/root/.cache/huggingface"
|
15 |
+
os.environ["HF_API_TOKEN"] = HF_API_KEY # Explicitly set API key
|
16 |
+
os.environ["HUGGINGFACE_HUB_TOKEN"] = HF_API_KEY
|
17 |
|
18 |
+
print("π Authenticating with Hugging Face...")
|
19 |
+
|
20 |
+
# β
Load the model with authentication
|
21 |
model = BertForSequenceClassification.from_pretrained(
|
22 |
MODEL_PATH,
|
23 |
+
token=HF_API_KEY # Explicit authentication
|
24 |
)
|
25 |
tokenizer = AutoTokenizer.from_pretrained(
|
26 |
MODEL_PATH,
|
27 |
+
token=HF_API_KEY # Explicit authentication
|
28 |
)
|
29 |
+
|
30 |
print("β
Model Loaded Successfully!")
|
31 |
|
32 |
# β
Define sentiment labels
|