Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,49 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from smolagents import CodeAgent
|
| 3 |
-
from smolagents.models import TransformersModel # β USE THIS
|
| 4 |
from retriever import guest_info_tool
|
| 5 |
from tools import all_tools
|
| 6 |
|
| 7 |
-
print("π© Starting Alfred
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
print(f"
|
| 19 |
|
| 20 |
def ask_alfred(query):
|
| 21 |
try:
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from smolagents import CodeAgent, InferenceClientModel
|
|
|
|
| 4 |
from retriever import guest_info_tool
|
| 5 |
from tools import all_tools
|
| 6 |
|
| 7 |
+
print("π© Starting Alfred...")
|
| 8 |
|
| 9 |
+
# ============================================================================
|
| 10 |
+
# AUTO-GET TOKEN FROM SPACES SECRETS
|
| 11 |
+
# ============================================================================
|
| 12 |
+
# HuggingFace Spaces automatically sets HF_TOKEN from your secrets
|
| 13 |
+
# You don't need to type it in code!
|
| 14 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 15 |
|
| 16 |
+
if HF_TOKEN:
|
| 17 |
+
print(f"β
Found HF_TOKEN (first 10 chars): {HF_TOKEN[:10]}...")
|
| 18 |
+
|
| 19 |
+
# Set for huggingface_hub library
|
| 20 |
+
os.environ["HUGGINGFACE_HUB_TOKEN"] = HF_TOKEN
|
| 21 |
+
|
| 22 |
+
# Try InferenceClientModel
|
| 23 |
+
try:
|
| 24 |
+
model = InferenceClientModel()
|
| 25 |
+
print("β
InferenceClientModel created with token")
|
| 26 |
+
except Exception as e:
|
| 27 |
+
print(f"β InferenceClientModel failed: {e}")
|
| 28 |
+
# Fallback
|
| 29 |
+
from smolagents.models import TransformersModel
|
| 30 |
+
model = TransformersModel("microsoft/phi-2")
|
| 31 |
+
else:
|
| 32 |
+
print("β No HF_TOKEN found in environment!")
|
| 33 |
+
print("π‘ Add it in Space Settings β Repository secrets")
|
| 34 |
+
|
| 35 |
+
# Use local model instead
|
| 36 |
+
from smolagents.models import TransformersModel
|
| 37 |
+
model = TransformersModel("microsoft/phi-2")
|
| 38 |
+
print("π Using local model as fallback")
|
| 39 |
+
|
| 40 |
+
# ============================================================================
|
| 41 |
+
# CREATE AGENT
|
| 42 |
+
# ============================================================================
|
| 43 |
+
all_agent_tools = [guest_info_tool] + all_tools
|
| 44 |
+
alfred = CodeAgent(tools=all_agent_tools, model=model)
|
| 45 |
|
| 46 |
+
print(f"π€ Alfred ready with {len(all_agent_tools)} tools")
|
| 47 |
|
| 48 |
def ask_alfred(query):
|
| 49 |
try:
|