Aharneish commited on
Commit
03f1283
·
verified ·
1 Parent(s): 81917a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -23
app.py CHANGED
@@ -14,10 +14,22 @@ class BasicAgent:
14
  def __init__(self):
15
  print("BasicAgent initialized.")
16
  def __call__(self, question: str) -> str:
17
- print(f"Agent received question (first 50 chars): {question[:50]}...")
18
- fixed_answer = "This is a default answer."
19
- print(f"Agent returning fixed answer: {fixed_answer}")
20
- return fixed_answer
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
@@ -39,8 +51,15 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
39
  submit_url = f"{api_url}/submit"
40
 
41
  # 1. Instantiate Agent ( modify this part to create your agent)
42
- try:
43
- agent = BasicAgent()
 
 
 
 
 
 
 
44
  except Exception as e:
45
  print(f"Error instantiating agent: {e}")
46
  return f"Error initializing agent: {e}", None
@@ -142,32 +161,23 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
142
 
143
  # --- Build Gradio Interface using Blocks ---
144
  with gr.Blocks() as demo:
145
- gr.Markdown("# Basic Agent Evaluation Runner")
146
- gr.Markdown(
147
- """
148
- **Instructions:**
149
-
150
- 1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
151
- 2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
152
- 3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
153
-
154
- ---
155
- **Disclaimers:**
156
- Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
157
- This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
158
- """
159
- )
160
 
161
  gr.LoginButton()
162
 
163
- run_button = gr.Button("Run Evaluation & Submit All Answers")
 
 
 
 
164
 
 
165
  status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
166
- # Removed max_rows=10 from DataFrame constructor
167
  results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
168
 
169
  run_button.click(
170
  fn=run_and_submit_all,
 
171
  outputs=[status_output, results_table]
172
  )
173
 
 
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( profile: gr.OAuthProfile | None):
35
  """
 
51
  submit_url = f"{api_url}/submit"
52
 
53
  # 1. Instantiate Agent ( modify this part to create your agent)
54
+ try:
55
+ if agent_name == "BasicAgent":
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
 
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=[gr.OAuthProfile(), agent_dropdown],
181
  outputs=[status_output, results_table]
182
  )
183