Update app.py
Browse files
app.py
CHANGED
|
@@ -3,48 +3,25 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool
|
| 7 |
-
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
| 10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 11 |
|
| 12 |
# --- Basic Agent Definition ---
|
| 13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 14 |
-
@tool
|
| 15 |
-
def download_file(task_id: str) -> str:
|
| 16 |
-
"""
|
| 17 |
-
Downloads a file associated with a specific GAIA task.
|
| 18 |
-
Args:
|
| 19 |
-
task_id: The ID of the task (e.g., '3f2b1...')
|
| 20 |
-
"""
|
| 21 |
-
url = f"https://agents-course-unit4-scoring.hf.space/files/{task_id}"
|
| 22 |
-
response = requests.get(url)
|
| 23 |
-
if response.status_code == 200:
|
| 24 |
-
file_path = f"{task_id}_data"
|
| 25 |
-
with open(file_path, "wb") as f:
|
| 26 |
-
f.write(response.content)
|
| 27 |
-
return f"File downloaded to {file_path}. You should now use a tool to read it."
|
| 28 |
-
return "File not found."
|
| 29 |
class BasicAgent:
|
| 30 |
def __init__(self):
|
| 31 |
print("BasicAgent initialized.")
|
| 32 |
self.model = InferenceClientModel()
|
| 33 |
self.agent = CodeAgent(
|
| 34 |
-
tools=[DuckDuckGoSearchTool()
|
| 35 |
model=self.model,
|
| 36 |
add_base_tools=True # Adds useful tools like image generation/visit web page
|
| 37 |
)
|
| 38 |
def __call__(self, question: str) -> str:
|
| 39 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 40 |
-
prompt =
|
| 41 |
-
f"Question: {question}\n\n"
|
| 42 |
-
"Instructions:\n"
|
| 43 |
-
"1. Use tools to find the answer if needed.\n"
|
| 44 |
-
"2. If a file is mentioned, use 'download_file' first.\n"
|
| 45 |
-
"3. Your final output must be ONLY the answer value (e.g., '1969', 'Paris', '4.2').\n"
|
| 46 |
-
"4. Do NOT include phrases like 'The answer is' or 'Final Answer:'."
|
| 47 |
-
)
|
| 48 |
result = self.agent.run(prompt)
|
| 49 |
|
| 50 |
# Clean up the output to ensure it's just the answer (GAIA requires exact match)
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool
|
|
|
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
| 9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
print("BasicAgent initialized.")
|
| 16 |
self.model = InferenceClientModel()
|
| 17 |
self.agent = CodeAgent(
|
| 18 |
+
tools=[DuckDuckGoSearchTool()],
|
| 19 |
model=self.model,
|
| 20 |
add_base_tools=True # Adds useful tools like image generation/visit web page
|
| 21 |
)
|
| 22 |
def __call__(self, question: str) -> str:
|
| 23 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 24 |
+
prompt = f"Answer the following question. Provide ONLY the final answer: {question}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
result = self.agent.run(prompt)
|
| 26 |
|
| 27 |
# Clean up the output to ensure it's just the answer (GAIA requires exact match)
|