Aharneish commited on
Commit
ab98516
·
verified ·
1 Parent(s): 1b899fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -20
app.py CHANGED
@@ -3,7 +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 ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
@@ -14,22 +14,23 @@ class BasicAgent:
14
  def __init__(self):
15
  print("BasicAgent initialized.")
16
  def __call__(self, question: str) -> str:
17
- print(f"BasicAgent received: {question[:50]}...")
18
  return "This is a default answer."
19
 
20
  class EchoAgent:
21
  def __init__(self):
22
  print("EchoAgent initialized.")
23
  def __call__(self, question: str) -> str:
24
- print(f"EchoAgent received: {question[:50]}...")
25
- return f"You said: {question}"
26
 
27
- class LengthAgent:
28
  def __init__(self):
29
- print("LengthAgent initialized.")
30
  def __call__(self, question: str) -> str:
31
- print(f"LengthAgent received: {question[:50]}...")
32
- return f"Length of input: {len(question)}"
 
 
 
33
 
34
  def run_and_submit_all(agent_name: str, profile: gr.OAuthProfile | None = None):
35
  """
@@ -56,10 +57,10 @@ def run_and_submit_all(agent_name: str, profile: gr.OAuthProfile | None = None):
56
  agent = BasicAgent()
57
  elif agent_name == "EchoAgent":
58
  agent = EchoAgent()
59
- elif agent_name == "LengthAgent":
60
- agent = LengthAgent()
61
  else:
62
- raise ValueError(f"Unknown agent selected: {agent_name}")
63
  except Exception as e:
64
  print(f"Error instantiating agent: {e}")
65
  return f"Error initializing agent: {e}", None
@@ -161,24 +162,24 @@ def run_and_submit_all(agent_name: str, profile: gr.OAuthProfile | None = None):
161
 
162
  # --- Build Gradio Interface using Blocks ---
163
  with gr.Blocks() as demo:
164
- gr.Markdown("# Multi-Agent Evaluation Runner")
165
 
166
  gr.LoginButton()
167
-
168
  agent_dropdown = gr.Dropdown(
169
- choices=["BasicAgent", "EchoAgent", "LengthAgent"],
170
- label="Select Agent to Run",
171
  value="BasicAgent"
172
  )
173
 
174
  run_button = gr.Button("Run Evaluation & Submit All Answers")
175
- status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
176
- results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
177
 
178
  run_button.click(
179
- fn=run_and_submit_all,
180
- inputs=[agent_dropdown],
181
- outputs=[status_output, results_table]
182
  )
183
 
184
  if __name__ == "__main__":
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ import wikipidea
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
14
  def __init__(self):
15
  print("BasicAgent initialized.")
16
  def __call__(self, question: str) -> str:
 
17
  return "This is a default answer."
18
 
19
  class EchoAgent:
20
  def __init__(self):
21
  print("EchoAgent initialized.")
22
  def __call__(self, question: str) -> str:
23
+ return f"You asked: {question}"
 
24
 
25
+ class WikipediaAgent:
26
  def __init__(self):
27
+ print("WikipediaAgent initialized.")
28
  def __call__(self, question: str) -> str:
29
+ try:
30
+ summary = wikipedia.summary(question, sentences=1)
31
+ return summary
32
+ except Exception as e:
33
+ return f"Error: {str(e)}"
34
 
35
  def run_and_submit_all(agent_name: str, profile: gr.OAuthProfile | None = None):
36
  """
 
57
  agent = BasicAgent()
58
  elif agent_name == "EchoAgent":
59
  agent = EchoAgent()
60
+ elif agent_name == "WikipediaAgent":
61
+ agent = WikipediaAgent()
62
  else:
63
+ return f"Unknown agent selected: {agent_name}", None
64
  except Exception as e:
65
  print(f"Error instantiating agent: {e}")
66
  return f"Error initializing agent: {e}", None
 
162
 
163
  # --- Build Gradio Interface using Blocks ---
164
  with gr.Blocks() as demo:
165
+ gr.Markdown("# GAIA Agent Evaluator")
166
 
167
  gr.LoginButton()
168
+
169
  agent_dropdown = gr.Dropdown(
170
+ choices=["BasicAgent", "EchoAgent", "WikipediaAgent"],
171
+ label="Select Agent",
172
  value="BasicAgent"
173
  )
174
 
175
  run_button = gr.Button("Run Evaluation & Submit All Answers")
176
+ status_output = gr.Textbox(label="Status / Score", lines=5, interactive=False)
177
+ results_table = gr.DataFrame(label="Agent Answers", wrap=True)
178
 
179
  run_button.click(
180
+ fn=run_and_submit_all,
181
+ inputs=[agent_dropdown],
182
+ outputs=[status_output, results_table]
183
  )
184
 
185
  if __name__ == "__main__":