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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
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") # 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"]
 
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"]