Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel
|
|
|
|
| 3 |
import time
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
|
| 8 |
-
#
|
|
|
|
|
|
|
|
|
|
| 9 |
tools = [DuckDuckGoSearchTool()]
|
| 10 |
|
| 11 |
-
#
|
| 12 |
agent = CodeAgent(tools=tools, model=model)
|
| 13 |
|
| 14 |
-
#
|
| 15 |
def get_questions():
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
#
|
| 23 |
def answer_all():
|
| 24 |
questions = get_questions()
|
|
|
|
|
|
|
|
|
|
| 25 |
answers = []
|
| 26 |
for q in questions:
|
| 27 |
task_id = q.get("task_id")
|
|
@@ -29,30 +37,44 @@ def answer_all():
|
|
| 29 |
print(f"[{task_id}] β {question}")
|
| 30 |
try:
|
| 31 |
response = agent.run(question).strip()
|
|
|
|
| 32 |
except Exception as e:
|
| 33 |
response = f"Error generating answer: {e}"
|
|
|
|
| 34 |
answers.append({
|
| 35 |
"task_id": task_id,
|
| 36 |
"submitted_answer": response
|
| 37 |
})
|
| 38 |
-
time.sleep(1) #
|
| 39 |
return answers, None
|
| 40 |
|
| 41 |
-
# Submit
|
| 42 |
def submit_to_leaderboard(username, code_link):
|
| 43 |
results, error = answer_all()
|
| 44 |
if error:
|
| 45 |
return error
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
-
# Gradio UI
|
| 51 |
with gr.Blocks() as demo:
|
| 52 |
-
gr.Markdown("## π€ GAIA Agent Submission Portal\
|
| 53 |
username = gr.Textbox(label="πΉ HuggingFace Username", placeholder="e.g. PavanKumarGurram")
|
| 54 |
code_url = gr.Textbox(label="π Public Link to Your Space (code view)", placeholder="e.g. https://huggingface.co/spaces/PavanKumarGurram/gaia-agent-pavan/tree/main")
|
| 55 |
-
submit_btn = gr.Button("π Submit My Agent
|
| 56 |
output = gr.Textbox(label="π’ Submission Result", lines=10)
|
| 57 |
|
| 58 |
submit_btn.click(fn=submit_to_leaderboard, inputs=[username, code_url], outputs=output)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel
|
| 3 |
+
import requests
|
| 4 |
import time
|
| 5 |
|
| 6 |
+
# β
Correct GAIA API endpoint via Hugging Face proxy (fixes DNS error)
|
| 7 |
+
GAIA_API = "https://huggingface.co/api/spaces/huggingface-projects/gaia-benchmark/api"
|
| 8 |
|
| 9 |
+
# β
Set up your model
|
| 10 |
+
model = InferenceClientModel(model="openai/gpt-3.5-turbo") # Uses OpenAI GPT-3.5 via Inference API
|
| 11 |
+
|
| 12 |
+
# β
Set up tools
|
| 13 |
tools = [DuckDuckGoSearchTool()]
|
| 14 |
|
| 15 |
+
# β
Create your agent
|
| 16 |
agent = CodeAgent(tools=tools, model=model)
|
| 17 |
|
| 18 |
+
# β
Fetch questions from GAIA API
|
| 19 |
def get_questions():
|
| 20 |
+
try:
|
| 21 |
+
response = requests.get(f"{GAIA_API}/questions")
|
| 22 |
+
response.raise_for_status()
|
| 23 |
+
return response.json()
|
| 24 |
+
except Exception as e:
|
| 25 |
+
return {"error": f"Failed to fetch questions: {e}"}
|
| 26 |
|
| 27 |
+
# β
Use the agent to answer all questions
|
| 28 |
def answer_all():
|
| 29 |
questions = get_questions()
|
| 30 |
+
if "error" in questions:
|
| 31 |
+
return [], questions["error"]
|
| 32 |
+
|
| 33 |
answers = []
|
| 34 |
for q in questions:
|
| 35 |
task_id = q.get("task_id")
|
|
|
|
| 37 |
print(f"[{task_id}] β {question}")
|
| 38 |
try:
|
| 39 |
response = agent.run(question).strip()
|
| 40 |
+
print(f"π§ Answer: {response}\n")
|
| 41 |
except Exception as e:
|
| 42 |
response = f"Error generating answer: {e}"
|
| 43 |
+
print(response)
|
| 44 |
answers.append({
|
| 45 |
"task_id": task_id,
|
| 46 |
"submitted_answer": response
|
| 47 |
})
|
| 48 |
+
time.sleep(1) # Delay to avoid rate limits
|
| 49 |
return answers, None
|
| 50 |
|
| 51 |
+
# β
Submit answers to GAIA leaderboard
|
| 52 |
def submit_to_leaderboard(username, code_link):
|
| 53 |
results, error = answer_all()
|
| 54 |
if error:
|
| 55 |
return error
|
| 56 |
|
| 57 |
+
payload = {
|
| 58 |
+
"username": username,
|
| 59 |
+
"agent_code": code_link,
|
| 60 |
+
"answers": results
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
try:
|
| 64 |
+
res = requests.post(f"{GAIA_API}/submit", json=payload)
|
| 65 |
+
if res.status_code == 200:
|
| 66 |
+
return f"β
Submission Successful!\n\n{res.json()}"
|
| 67 |
+
else:
|
| 68 |
+
return f"β Submission Failed: {res.status_code}\n{res.text}"
|
| 69 |
+
except Exception as e:
|
| 70 |
+
return f"β Error during submission: {e}"
|
| 71 |
|
| 72 |
+
# β
Gradio UI for submission
|
| 73 |
with gr.Blocks() as demo:
|
| 74 |
+
gr.Markdown("## π€ GAIA Agent Submission Portal\nSubmit your agent and join the leaderboard!")
|
| 75 |
username = gr.Textbox(label="πΉ HuggingFace Username", placeholder="e.g. PavanKumarGurram")
|
| 76 |
code_url = gr.Textbox(label="π Public Link to Your Space (code view)", placeholder="e.g. https://huggingface.co/spaces/PavanKumarGurram/gaia-agent-pavan/tree/main")
|
| 77 |
+
submit_btn = gr.Button("π Submit My Agent")
|
| 78 |
output = gr.Textbox(label="π’ Submission Result", lines=10)
|
| 79 |
|
| 80 |
submit_btn.click(fn=submit_to_leaderboard, inputs=[username, code_url], outputs=output)
|