Spaces:
Runtime error
Runtime error
Commit
·
467e254
1
Parent(s):
81917a3
first attempt
Browse files- app.py +30 -4
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -3,6 +3,9 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
|
@@ -12,12 +15,35 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
-
print("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 18 |
-
fixed_answer = "This is a default answer."
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from smolagents import CodeAgent, OpenAIServerModel, ToolCallingAgent
|
| 7 |
+
from smolagents import DuckDuckGoSearchTool, FinalAnswerTool
|
| 8 |
+
|
| 9 |
|
| 10 |
# (Keep Constants as is)
|
| 11 |
# --- Constants ---
|
|
|
|
| 15 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 16 |
class BasicAgent:
|
| 17 |
def __init__(self):
|
| 18 |
+
print("Agent initialized.")
|
| 19 |
+
|
| 20 |
+
self.model = OpenAIServerModel(
|
| 21 |
+
model_id="deepseek-r1-distill-llama-3b-tools",
|
| 22 |
+
api_base="http://localhost:1234/v1",
|
| 23 |
+
api_key="lm-studio"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Initialize the web search tool
|
| 27 |
+
search_tool = DuckDuckGoSearchTool(max_results=5, headers={'User-Agent': 'Mozilla/5.0'})
|
| 28 |
+
final_answer_tool = FinalAnswerTool()
|
| 29 |
+
|
| 30 |
+
self.agent = ToolCallingAgent(
|
| 31 |
+
tools=[search_tool,final_answer_tool],
|
| 32 |
+
model=self.model,
|
| 33 |
+
planning_interval=3,
|
| 34 |
+
max_steps=3,
|
| 35 |
+
add_base_tools=True
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
def __call__(self, question: str) -> str:
|
| 41 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 42 |
+
# fixed_answer = "This is a default answer."
|
| 43 |
+
answer = self.agent.run(question)
|
| 44 |
+
|
| 45 |
+
print(f"Agent returning: {answer}")
|
| 46 |
+
return answer
|
| 47 |
|
| 48 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 49 |
"""
|
requirements.txt
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
gradio
|
|
|
|
| 2 |
requests
|
|
|
|
| 1 |
gradio
|
| 2 |
+
gradio[oauth]
|
| 3 |
requests
|