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