Euryeth commited on
Commit
fbbc9c1
·
verified ·
1 Parent(s): 8aca5f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -3,16 +3,18 @@ from transformers import pipeline
3
  import torch
4
  import os
5
 
 
 
 
 
 
6
  # Use safe float32 for CPU compatibility
7
  torch_dtype = torch.float32
8
 
9
  # Configure cache directory
10
  os.environ['HF_HOME'] = '/tmp/cache'
11
 
12
- # Optional: print token to verify it's passed at runtime
13
- # print("HF Token:", os.environ.get("HUGGINGFACEHUB_API_TOKEN"))
14
-
15
- # Load the model pipeline with auth token picked up automatically
16
  generator = pipeline(
17
  "text-generation",
18
  model="mistralai/Mistral-7B-Instruct-v0.2",
 
3
  import torch
4
  import os
5
 
6
+ # Set HF token if available in environment (provided via Hugging Face Spaces Secrets)
7
+ # This is CRITICAL to access gated models like Mistral-7B-Instruct-v0.2
8
+ from huggingface_hub import login
9
+ login(os.getenv("HUGGINGFACEHUB_API_TOKEN")) # automatically handles secrets
10
+
11
  # Use safe float32 for CPU compatibility
12
  torch_dtype = torch.float32
13
 
14
  # Configure cache directory
15
  os.environ['HF_HOME'] = '/tmp/cache'
16
 
17
+ # Load the model pipeline
 
 
 
18
  generator = pipeline(
19
  "text-generation",
20
  model="mistralai/Mistral-7B-Instruct-v0.2",