Update app.py
#452
by gokul789340 - opened
app.py
CHANGED
|
@@ -3,6 +3,7 @@ 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 +13,50 @@ 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 |
-
|
| 18 |
-
|
| 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, DuckDuckGoSearchTool, HfApiModel
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
|
|
|
| 13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 14 |
class BasicAgent:
|
| 15 |
def __init__(self):
|
| 16 |
+
print("Initializing GAIA Agent...")
|
| 17 |
+
|
| 18 |
+
self.agent = CodeAgent(
|
| 19 |
+
tools=[DuckDuckGoSearchTool()],
|
| 20 |
+
model=HfApiModel(),
|
| 21 |
+
max_steps=25
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
def __call__(self, question: str) -> str:
|
| 25 |
+
prompt = f"""
|
| 26 |
+
You are solving a GAIA benchmark question.
|
| 27 |
+
|
| 28 |
+
Instructions:
|
| 29 |
+
- Use web search whenever needed.
|
| 30 |
+
- Verify facts before answering.
|
| 31 |
+
- Calculate instead of estimating.
|
| 32 |
+
- Search before guessing.
|
| 33 |
+
- Return ONLY the final answer.
|
| 34 |
+
- No explanations.
|
| 35 |
+
- No markdown.
|
| 36 |
+
- No prefixes.
|
| 37 |
+
- No suffixes.
|
| 38 |
+
- No extra text.
|
| 39 |
+
|
| 40 |
+
Question:
|
| 41 |
+
{question}
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
try:
|
| 45 |
+
answer = self.agent.run(prompt)
|
| 46 |
+
|
| 47 |
+
if answer is None:
|
| 48 |
+
return ""
|
| 49 |
+
|
| 50 |
+
answer = str(answer).strip()
|
| 51 |
+
|
| 52 |
+
if "FINAL ANSWER:" in answer:
|
| 53 |
+
answer = answer.split("FINAL ANSWER:")[-1].strip()
|
| 54 |
+
|
| 55 |
+
return answer
|
| 56 |
+
|
| 57 |
+
except Exception as e:
|
| 58 |
+
print(f"Agent error: {e}")
|
| 59 |
+
return ""
|
| 60 |
|
| 61 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 62 |
"""
|