Spaces:
Runtime error
Runtime error
Ерёменко Иван commited on
Commit ·
37991fe
1
Parent(s): 9275aec
Add better token detection and error message
Browse files- Try multiple token environment variables (HUGGINGFACE_API_TOKEN, HF_TOKEN, HUGGINGFACE_HUB_TOKEN)
- Add clear error message if no token is found
- Help user understand they need to set token in Space settings
app.py
CHANGED
|
@@ -10,7 +10,12 @@ try:
|
|
| 10 |
)
|
| 11 |
tools = mcp_client.get_tools()
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
agent = CodeAgent(tools=[*tools], model=model, additional_authorized_imports=["json", "ast", "urllib", "base64"])
|
| 15 |
|
| 16 |
demo = gr.ChatInterface(
|
|
|
|
| 10 |
)
|
| 11 |
tools = mcp_client.get_tools()
|
| 12 |
|
| 13 |
+
# Пробуем разные варианты токенов
|
| 14 |
+
token = os.getenv("HUGGINGFACE_API_TOKEN") or os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_HUB_TOKEN")
|
| 15 |
+
if not token:
|
| 16 |
+
raise Exception("Не найден токен! Установите переменную HUGGINGFACE_API_TOKEN в настройках Space")
|
| 17 |
+
|
| 18 |
+
model = InferenceClientModel(token=token)
|
| 19 |
agent = CodeAgent(tools=[*tools], model=model, additional_authorized_imports=["json", "ast", "urllib", "base64"])
|
| 20 |
|
| 21 |
demo = gr.ChatInterface(
|