Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool
|
| 7 |
from huggingface_hub import InferenceClient
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
|
@@ -11,18 +11,40 @@ 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 |
class BasicAgent:
|
| 15 |
def __init__(self):
|
| 16 |
print("BasicAgent initialized.")
|
| 17 |
-
self.model =
|
| 18 |
self.agent = CodeAgent(
|
| 19 |
-
tools=[DuckDuckGoSearchTool()],
|
| 20 |
-
model=
|
| 21 |
add_base_tools=True # Adds useful tools like image generation/visit web page
|
| 22 |
)
|
| 23 |
def __call__(self, question: str) -> str:
|
| 24 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 25 |
-
prompt =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
result = self.agent.run(prompt)
|
| 27 |
|
| 28 |
# 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, tool
|
| 7 |
from huggingface_hub import InferenceClient
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
|
|
|
| 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(), download_file],
|
| 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)
|