Spaces:
Paused
Paused
dharmendra
commited on
Commit
·
7d7d860
1
Parent(s):
a23c36a
Attempting explicit Hugging Face Hub login for gated repo access
Browse files
app.py
CHANGED
@@ -12,6 +12,8 @@ import asyncio
|
|
12 |
import json
|
13 |
from langchain_community.llms import HuggingFacePipeline
|
14 |
import uvicorn
|
|
|
|
|
15 |
|
16 |
app = FastAPI()
|
17 |
|
@@ -21,6 +23,18 @@ HUGGINGFACEHUB_API_TOKEN = os.environ.get("HUGGINGFACEHUB_API_TOKEN")
|
|
21 |
if HUGGINGFACEHUB_API_TOKEN is None:
|
22 |
raise ValueError("HUGGINGFACEHUB_API_TOKEN environment variable not set.")
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
# --- UPDATED: Use Mistral 7B Instruct v0.3 model ---
|
25 |
model_id = "mistralai/Mistral-7B-Instruct-v0.3"
|
26 |
|
|
|
12 |
import json
|
13 |
from langchain_community.llms import HuggingFacePipeline
|
14 |
import uvicorn
|
15 |
+
# Import the login function from huggingface_hub
|
16 |
+
from huggingface_hub import login
|
17 |
|
18 |
app = FastAPI()
|
19 |
|
|
|
23 |
if HUGGINGFACEHUB_API_TOKEN is None:
|
24 |
raise ValueError("HUGGINGFACEHUB_API_TOKEN environment variable not set.")
|
25 |
|
26 |
+
# --- NEW: Explicitly log in to Hugging Face Hub ---
|
27 |
+
# This ensures the environment is authenticated before trying to load models.
|
28 |
+
try:
|
29 |
+
login(token=HUGGINGFACEHUB_API_TOKEN)
|
30 |
+
print("Successfully logged into Hugging Face Hub.")
|
31 |
+
except Exception as e:
|
32 |
+
print(f"Failed to log into Hugging Face Hub: {e}")
|
33 |
+
# You might want to raise an HTTPException here or handle this more gracefully
|
34 |
+
# depending on whether you want the app to start without model access.
|
35 |
+
# For now, we'll let the subsequent model loading attempt to fail if it must.
|
36 |
+
|
37 |
+
|
38 |
# --- UPDATED: Use Mistral 7B Instruct v0.3 model ---
|
39 |
model_id = "mistralai/Mistral-7B-Instruct-v0.3"
|
40 |
|