Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,62 +1,34 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
| 3 |
-
from smolagents import CodeAgent, InferenceClientModel
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 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:
|
| 50 |
-
return alfred.run(query)
|
| 51 |
-
except Exception as e:
|
| 52 |
-
return f"Error: {str(e)}"
|
| 53 |
-
|
| 54 |
-
demo = gr.Interface(
|
| 55 |
-
fn=ask_alfred,
|
| 56 |
-
inputs=gr.Textbox(label="Ask Alfred"),
|
| 57 |
-
outputs=gr.Textbox(label="Response"),
|
| 58 |
-
title="π© Alfred's Gala Assistant"
|
| 59 |
)
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py - Clean version
|
| 2 |
import gradio as gr
|
| 3 |
+
from smolagents import GradioUI, CodeAgent, InferenceClientModel
|
| 4 |
+
|
| 5 |
+
# Import our custom tools
|
| 6 |
+
from tools import DuckDuckGoSearchTool, WeatherInfoTool, HubStatsTool
|
| 7 |
+
from retriever import load_guest_dataset
|
| 8 |
+
|
| 9 |
+
# Initialize
|
| 10 |
+
model = InferenceClientModel() # Updated
|
| 11 |
+
search_tool = DuckDuckGoSearchTool()
|
| 12 |
+
weather_info_tool = WeatherInfoTool()
|
| 13 |
+
hub_stats_tool = HubStatsTool()
|
| 14 |
+
guest_tool = load_guest_dataset()
|
| 15 |
+
|
| 16 |
+
# Enhance tool descriptions
|
| 17 |
+
guest_tool.description = "USE THIS FOR GALA GUESTS! Database with names, relations, descriptions, emails of attendees. Examples: 'Lady Ada Lovelace', 'guest list', 'who is coming'. NEVER use web search for guests."
|
| 18 |
+
|
| 19 |
+
# Create agent
|
| 20 |
+
alfred = CodeAgent(
|
| 21 |
+
tools=[guest_tool, weather_info_tool, hub_stats_tool, search_tool],
|
| 22 |
+
model=model,
|
| 23 |
+
add_base_tools=True,
|
| 24 |
+
planning_interval=3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
)
|
| 26 |
|
| 27 |
if __name__ == "__main__":
|
| 28 |
+
# Quick test
|
| 29 |
+
print("Testing...")
|
| 30 |
+
response = alfred.run("Tell me about Lady Ada Lovelace at the gala")
|
| 31 |
+
print(f"Response: {response[:300]}...")
|
| 32 |
+
|
| 33 |
+
# Launch UI
|
| 34 |
+
GradioUI(alfred).launch()
|