Update app.py
#563
by ModelByNikhil - 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 ---
|
|
@@ -13,11 +14,37 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
print("BasicAgent initialized.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
-
print(f"Agent received question
|
| 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 ---
|
|
|
|
| 14 |
class BasicAgent:
|
| 15 |
def __init__(self):
|
| 16 |
print("BasicAgent initialized.")
|
| 17 |
+
model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct")
|
| 18 |
+
|
| 19 |
+
self.agent = CodeAgent(
|
| 20 |
+
tools=[DuckDuckGoSearchTool()],
|
| 21 |
+
model=model,
|
| 22 |
+
max_steps=10,
|
| 23 |
+
additional_authorized_imports=["requests", "pandas", "numpy", "time"]
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
def __call__(self, question: str) -> str:
|
| 28 |
+
print(f"Agent received question: {question[:50]}...")
|
| 29 |
+
|
| 30 |
+
prompt = f"""
|
| 31 |
+
You are an expert AI agent. Answer the following question.
|
| 32 |
+
You must perform internet searches if you don't know the answer.
|
| 33 |
+
|
| 34 |
+
CRITICAL RULE: You MUST provide ONLY the final exact answer.
|
| 35 |
+
Do not include extra words like "The answer is" or "Final answer:".
|
| 36 |
+
If the answer is a number, just output the number. If it's a name, just output the name.
|
| 37 |
+
|
| 38 |
+
Question: {question}
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
try:
|
| 42 |
+
result = self.agent.run(prompt)
|
| 43 |
+
|
| 44 |
+
return str(result).strip()
|
| 45 |
+
except Exception as e:
|
| 46 |
+
print(f"Agent failed to answer: {e}")
|
| 47 |
+
return "Error"
|
| 48 |
|
| 49 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 50 |
"""
|