Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
|
| 5 |
+
import requests
|
| 6 |
+
|
| 7 |
+
# Step 1: Setup Model
|
| 8 |
+
model = HfApiModel(model="openai/gpt-3.5-turbo") # Replace with your own if needed
|
| 9 |
+
|
| 10 |
+
# Step 2: Setup Tools
|
| 11 |
+
tools = [DuckDuckGoSearchTool()]
|
| 12 |
+
|
| 13 |
+
# Step 3: Create Agent
|
| 14 |
+
agent = CodeAgent(tools=tools, model=model)
|
| 15 |
+
|
| 16 |
+
# Step 4: GAIA API endpoints
|
| 17 |
+
GAIA_API = "https://gaia-benchmark-api.com"
|
| 18 |
+
|
| 19 |
+
def get_questions():
|
| 20 |
+
response = requests.get(f"{GAIA_API}/questions")
|
| 21 |
+
return response.json()
|
| 22 |
+
|
| 23 |
+
def answer_all():
|
| 24 |
+
questions = get_questions()
|
| 25 |
+
answers = []
|
| 26 |
+
for q in questions:
|
| 27 |
+
task_id = q["task_id"]
|
| 28 |
+
question = q["question"]
|
| 29 |
+
print(f"Answering Task: {task_id} ➜ {question}")
|
| 30 |
+
answer = agent.run(question)
|
| 31 |
+
answers.append({"task_id": task_id, "submitted_answer": answer.strip()})
|
| 32 |
+
return answers
|
| 33 |
+
|
| 34 |
+
def submit_to_leaderboard(username, code_link):
|
| 35 |
+
answers = answer_all()
|
| 36 |
+
payload = {
|
| 37 |
+
"username": username,
|
| 38 |
+
"agent_code": code_link,
|
| 39 |
+
"answers": answers
|
| 40 |
+
}
|
| 41 |
+
res = requests.post(f"{GAIA_API}/submit", json=payload)
|
| 42 |
+
if res.status_code == 200:
|
| 43 |
+
return res.json()
|
| 44 |
+
else:
|
| 45 |
+
return f"Error: {res.status_code} - {res.text}"
|
| 46 |
+
|
| 47 |
+
# Gradio UI
|
| 48 |
+
with gr.Blocks() as demo:
|
| 49 |
+
gr.Markdown("## 🚀 GAIA Agent Submission")
|
| 50 |
+
username = gr.Textbox(label="Your HuggingFace Username")
|
| 51 |
+
code_url = gr.Textbox(label="Link to this Space (code view)")
|
| 52 |
+
submit_btn = gr.Button("Submit My Agent")
|
| 53 |
+
|
| 54 |
+
output = gr.Textbox(label="Result", lines=10)
|
| 55 |
+
|
| 56 |
+
submit_btn.click(submit_to_leaderboard, inputs=[username, code_url], outputs=output)
|
| 57 |
+
|
| 58 |
+
demo.launch()
|