hariharan220 commited on
Commit
db743ff
Β·
verified Β·
1 Parent(s): 684a78c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -5,24 +5,28 @@ 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")
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
 
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