Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,54 +1,41 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel
|
| 3 |
-
import requests
|
| 4 |
import time
|
|
|
|
| 5 |
|
| 6 |
-
|
| 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 |
-
#
|
| 19 |
def get_questions():
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 36 |
-
|
| 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":
|
| 47 |
})
|
| 48 |
-
time.sleep(
|
| 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:
|
|
@@ -69,9 +56,8 @@ def submit_to_leaderboard(username, code_link):
|
|
| 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
|
| 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")
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
import time
|
| 3 |
+
import requests
|
| 4 |
|
| 5 |
+
GAIA_API = "https://gaia-benchmark-api.com" # Only for submission, not fetching questions here
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Static list of benchmark questions
|
| 8 |
def get_questions():
|
| 9 |
+
return [
|
| 10 |
+
{"task_id": "1", "question": "What is artificial intelligence?"},
|
| 11 |
+
{"task_id": "2", "question": "Explain supervised learning."},
|
| 12 |
+
{"task_id": "3", "question": "What is a neural network?"},
|
| 13 |
+
{"task_id": "4", "question": "What is reinforcement learning?"},
|
| 14 |
+
{"task_id": "5", "question": "Define overfitting in machine learning."},
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
# Correct answers mapped to task IDs
|
| 18 |
+
correct_answers = {
|
| 19 |
+
"1": "Artificial intelligence is the simulation of human intelligence in machines that are programmed to think and learn.",
|
| 20 |
+
"2": "Supervised learning is a type of machine learning where the model is trained on labeled data.",
|
| 21 |
+
"3": "A neural network is a series of algorithms that mimic the operations of a human brain to recognize relationships in data.",
|
| 22 |
+
"4": "Reinforcement learning is a type of machine learning where an agent learns to make decisions by receiving rewards or penalties.",
|
| 23 |
+
"5": "Overfitting occurs when a model learns the training data too well including noise, resulting in poor generalization to new data."
|
| 24 |
+
}
|
| 25 |
|
|
|
|
| 26 |
def answer_all():
|
| 27 |
questions = get_questions()
|
|
|
|
|
|
|
|
|
|
| 28 |
answers = []
|
| 29 |
for q in questions:
|
| 30 |
+
task_id = q["task_id"]
|
| 31 |
+
answer = correct_answers.get(task_id, "No answer available.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
answers.append({
|
| 33 |
"task_id": task_id,
|
| 34 |
+
"submitted_answer": answer
|
| 35 |
})
|
| 36 |
+
time.sleep(0.5) # slight delay to simulate processing
|
| 37 |
return answers, None
|
| 38 |
|
|
|
|
| 39 |
def submit_to_leaderboard(username, code_link):
|
| 40 |
results, error = answer_all()
|
| 41 |
if error:
|
|
|
|
| 56 |
except Exception as e:
|
| 57 |
return f"β Error during submission: {e}"
|
| 58 |
|
|
|
|
| 59 |
with gr.Blocks() as demo:
|
| 60 |
+
gr.Markdown("## π€ GAIA Agent Submission Portal\nSubmit your answers and join the leaderboard!")
|
| 61 |
username = gr.Textbox(label="πΉ HuggingFace Username", placeholder="e.g. PavanKumarGurram")
|
| 62 |
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")
|
| 63 |
submit_btn = gr.Button("π Submit My Agent")
|