PavanKumarGurram commited on
Commit
be87e9f
Β·
verified Β·
1 Parent(s): 38f60c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -18
app.py CHANGED
@@ -1,27 +1,35 @@
1
  import gradio as gr
2
  from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel
 
3
  import time
4
 
5
- # Step 1: Setup Model
6
- model = InferenceClientModel(model="openai/gpt-3.5-turbo") # βœ… Model interface
7
 
8
- # Step 2: Setup Tools
 
 
 
9
  tools = [DuckDuckGoSearchTool()]
10
 
11
- # Step 3: Create Agent
12
  agent = CodeAgent(tools=tools, model=model)
13
 
14
- # 🚨 Mock GAIA Questions (Since API is unreachable)
15
  def get_questions():
16
- return [
17
- {"task_id": "001", "question": "What is Python used for?"},
18
- {"task_id": "002", "question": "Explain the concept of inheritance in object-oriented programming."},
19
- {"task_id": "003", "question": "What is the difference between AI and ML?"}
20
- ]
 
21
 
22
- # Answer all questions using your agent
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) # Optional delay
39
  return answers, None
40
 
41
- # Submit your agent's answers (mocked result)
42
  def submit_to_leaderboard(username, code_link):
43
  results, error = answer_all()
44
  if error:
45
  return error
46
 
47
- # Simulated submission result
48
- return f"βœ… Submission Successful!\n\nSubmitted {len(results)} answers for {username}.\n[Mock submission only]"
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
- # Gradio UI
51
  with gr.Blocks() as demo:
52
- gr.Markdown("## πŸ€– GAIA Agent Submission Portal\nThis is a **mock version** due to unreachable API.")
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 (Mock)")
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)