Joachim M. Vis commited on
Commit
9eb9c82
·
verified ·
1 Parent(s): 1934c7f

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +48 -35
  2. app_no_oauth.py +226 -0
  3. space_config.json +2 -3
app.py CHANGED
@@ -224,47 +224,60 @@ except ImportError:
224
  except Exception as e:
225
  logger.warning(f"Error importing huggingface_hub: {e}")
226
 
227
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
228
- gr.Markdown("# GAIA Agent Evaluation Runner")
229
- with gr.Tabs():
230
- with gr.TabItem("Run Evaluation"):
231
- gr.Markdown(
232
- """
233
- **Instructions:**
 
 
234
 
235
- 1. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
236
- 2. Click 'Run Evaluation & Submit All Answers' to fetch questions, run the GAIA agent, submit answers, and see the score.
237
- 3. The progress bar will show you the current status of the evaluation.
238
- 4. Results will appear in the table below once processing is complete.
239
 
240
- **Note:** Running the evaluation may take some time as the agent processes all questions. Please be patient.
241
- """
242
- )
243
 
244
- with gr.Row():
245
- with gr.Column(scale=1):
246
- gr.LoginButton()
247
- with gr.Column(scale=2):
248
- run_button = gr.Button("Run Evaluation & Submit All Answers",
249
- variant="primary", size="lg")
 
 
 
 
 
 
 
 
 
 
 
250
 
251
- status_output = gr.Textbox(
252
- label="Run Status / Submission Result",
253
- lines=6,
254
- interactive=False,
255
- elem_id="status_output"
 
 
 
 
 
 
 
 
256
  )
257
 
258
- results_accordion = gr.Accordion("Results", open=False, elem_id="results_accordion")
259
- with results_accordion:
260
- results_table = gr.DataFrame(
261
- label="Questions and Agent Answers",
262
- wrap=True,
263
- elem_id="results_table"
264
- )
265
-
266
- with gr.Row():
267
- with gr.Column():
268
  gr.Markdown("### Result Statistics")
269
  stats_output = gr.JSON(label="Statistics", visible=True)
270
 
 
224
  except Exception as e:
225
  logger.warning(f"Error importing huggingface_hub: {e}")
226
 
227
+ # Create Gradio interface with optional OAuth
228
+ try:
229
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
230
+ gr.Markdown("# GAIA Agent Evaluation Runner")
231
+ with gr.Tabs():
232
+ with gr.TabItem("Run Evaluation"):
233
+ gr.Markdown(
234
+ """
235
+ **Instructions:**
236
 
237
+ 1. If available, log in to your Hugging Face account using the button below. This uses your HF username for submission.
238
+ 2. Click 'Run Evaluation & Submit All Answers' to fetch questions, run the GAIA agent, submit answers, and see the score.
239
+ 3. The progress bar will show you the current status of the evaluation.
240
+ 4. Results will appear in the table below once processing is complete.
241
 
242
+ **Note:** Running the evaluation may take some time as the agent processes all questions. Please be patient.
243
+ """
244
+ )
245
 
246
+ with gr.Row():
247
+ with gr.Column(scale=1):
248
+ try:
249
+ gr.LoginButton()
250
+ except Exception as e:
251
+ logger.warning(f"OAuth login button could not be created: {e}")
252
+ gr.Markdown("*Login not available in this environment*")
253
+ with gr.Column(scale=2):
254
+ run_button = gr.Button("Run Evaluation & Submit All Answers",
255
+ variant="primary", size="lg")
256
+ except Exception as e:
257
+ logger.error(f"Error creating Gradio interface: {e}")
258
+ # Fallback to a simpler interface without OAuth
259
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
260
+ gr.Markdown("# GAIA Agent Evaluation Runner (Simplified Mode)")
261
+ gr.Markdown("**Note:** Running in simplified mode without OAuth authentication.")
262
+ run_button = gr.Button("Run Evaluation & Submit All Answers", variant="primary", size="lg")
263
 
264
+ status_output = gr.Textbox(
265
+ label="Run Status / Submission Result",
266
+ lines=6,
267
+ interactive=False,
268
+ elem_id="status_output"
269
+ )
270
+
271
+ results_accordion = gr.Accordion("Results", open=False, elem_id="results_accordion")
272
+ with results_accordion:
273
+ results_table = gr.DataFrame(
274
+ label="Questions and Agent Answers",
275
+ wrap=True,
276
+ elem_id="results_table"
277
  )
278
 
279
+ with gr.Row():
280
+ with gr.Column():
 
 
 
 
 
 
 
 
281
  gr.Markdown("### Result Statistics")
282
  stats_output = gr.JSON(label="Statistics", visible=True)
283
 
app_no_oauth.py ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import requests
4
+ import inspect
5
+ import pandas as pd
6
+ import logging
7
+ import time
8
+ from typing import Dict, Any, List, Optional, Tuple, Union
9
+
10
+ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
+
12
+ from agent import GAIAAgent
13
+ from agent.config import VERBOSE
14
+
15
+ logger = logging.getLogger("gaia_app")
16
+ if VERBOSE:
17
+ logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
18
+ else:
19
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
20
+
21
+ def run_and_submit_all(username: str = "anonymous", progress=gr.Progress()) -> Tuple[str, Optional[pd.DataFrame]]:
22
+ """
23
+ Fetches all questions, runs the GAIA Agent on them, submits all answers,
24
+ and displays the results with progress tracking.
25
+
26
+ Args:
27
+ username: Username for submission (default: anonymous)
28
+ progress: Gradio progress tracker
29
+
30
+ Returns:
31
+ Tuple of (status message, results dataframe)
32
+ """
33
+ api_url = os.environ.get("GAIA_API_URL", DEFAULT_API_URL)
34
+
35
+ try:
36
+ # Step 1: Fetch questions
37
+ progress(0, desc="Fetching questions...")
38
+ questions_response = requests.get(f"{api_url}/questions")
39
+ questions_response.raise_for_status()
40
+ questions = questions_response.json()
41
+
42
+ if not questions:
43
+ return "Error: No questions received from the API.", None
44
+
45
+ # Step 2: Initialize agent and prepare for processing
46
+ progress(0.1, desc="Initializing GAIA Agent...")
47
+ agent = GAIAAgent()
48
+
49
+ # Step 3: Process each question
50
+ results = []
51
+ total_questions = len(questions)
52
+
53
+ for i, question in enumerate(questions):
54
+ question_id = question.get("id", f"q{i+1}")
55
+ question_text = question.get("question", "")
56
+
57
+ progress_value = 0.1 + (0.7 * (i / total_questions))
58
+ progress(progress_value, desc=f"Processing question {i+1}/{total_questions}: {question_text[:30]}...")
59
+
60
+ # Run the agent on the question
61
+ try:
62
+ start_time = time.time()
63
+ answer = agent.run(question_text)
64
+ end_time = time.time()
65
+ processing_time = end_time - start_time
66
+
67
+ results.append({
68
+ "question_id": question_id,
69
+ "question": question_text,
70
+ "answer": answer,
71
+ "processing_time": f"{processing_time:.2f}s"
72
+ })
73
+
74
+ logger.info(f"Processed question {question_id} in {processing_time:.2f}s")
75
+ except Exception as e:
76
+ error_msg = f"Error processing question {question_id}: {str(e)}"
77
+ logger.error(error_msg)
78
+ results.append({
79
+ "question_id": question_id,
80
+ "question": question_text,
81
+ "answer": f"ERROR: {str(e)}",
82
+ "processing_time": "N/A"
83
+ })
84
+
85
+ # Step 4: Submit all answers
86
+ progress(0.8, desc="Submitting answers...")
87
+
88
+ answers_payload = {
89
+ "username": username,
90
+ "answers": {item["question_id"]: item["answer"] for item in results}
91
+ }
92
+
93
+ submission_response = requests.post(
94
+ f"{api_url}/submit",
95
+ json=answers_payload
96
+ )
97
+
98
+ # Step 5: Process submission response
99
+ progress(0.9, desc="Processing submission results...")
100
+
101
+ if submission_response.status_code == 200:
102
+ submission_data = submission_response.json()
103
+ score = submission_data.get("score", "N/A")
104
+ feedback = submission_data.get("feedback", {})
105
+
106
+ # Add score and feedback to results
107
+ for item in results:
108
+ question_id = item["question_id"]
109
+ item["score"] = feedback.get(question_id, {}).get("score", "N/A")
110
+ item["feedback"] = feedback.get(question_id, {}).get("feedback", "")
111
+
112
+ # Create DataFrame for display
113
+ results_df = pd.DataFrame(results)
114
+
115
+ status_message = f"Submission successful! Overall score: {score}"
116
+ logger.info(status_message)
117
+
118
+ progress(1.0, desc="Complete!")
119
+ return status_message, results_df
120
+ else:
121
+ error_message = f"Submission failed with status code {submission_response.status_code}: {submission_response.text}"
122
+ logger.error(error_message)
123
+ progress(1.0, desc="Failed!")
124
+ return error_message, pd.DataFrame(results)
125
+
126
+ except Exception as e:
127
+ error_message = f"Error during evaluation process: {str(e)}"
128
+ logger.error(error_message)
129
+ progress(1.0, desc="Failed!")
130
+ return error_message, None
131
+
132
+ # Create Gradio interface without OAuth
133
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
134
+ gr.Markdown("# GAIA Agent Evaluation Runner (No OAuth)")
135
+
136
+ with gr.Tabs():
137
+ with gr.TabItem("Run Evaluation"):
138
+ gr.Markdown(
139
+ """
140
+ **Instructions:**
141
+
142
+ 1. Enter your username (optional) for submission tracking.
143
+ 2. Click 'Run Evaluation & Submit All Answers' to fetch questions, run the GAIA agent, submit answers, and see the score.
144
+ 3. The progress bar will show you the current status of the evaluation.
145
+ 4. Results will appear in the table below once processing is complete.
146
+
147
+ **Note:** Running the evaluation may take some time as the agent processes all questions. Please be patient.
148
+ """
149
+ )
150
+
151
+ with gr.Row():
152
+ with gr.Column(scale=1):
153
+ username_input = gr.Textbox(
154
+ label="Username (optional)",
155
+ placeholder="Enter username for submission",
156
+ value="anonymous"
157
+ )
158
+ with gr.Column(scale=2):
159
+ run_button = gr.Button("Run Evaluation & Submit All Answers",
160
+ variant="primary", size="lg")
161
+
162
+ status_output = gr.Textbox(
163
+ label="Run Status / Submission Result",
164
+ lines=6,
165
+ interactive=False,
166
+ elem_id="status_output"
167
+ )
168
+
169
+ results_accordion = gr.Accordion("Results", open=False, elem_id="results_accordion")
170
+ with results_accordion:
171
+ results_table = gr.DataFrame(
172
+ label="Questions and Agent Answers",
173
+ wrap=True,
174
+ elem_id="results_table"
175
+ )
176
+
177
+ with gr.Row():
178
+ with gr.Column():
179
+ score_chart = gr.Plot(
180
+ label="Score Distribution",
181
+ elem_id="score_chart"
182
+ )
183
+ with gr.Column():
184
+ time_chart = gr.Plot(
185
+ label="Processing Time",
186
+ elem_id="time_chart"
187
+ )
188
+
189
+ with gr.TabItem("About"):
190
+ gr.Markdown(
191
+ """
192
+ ## About GAIA Agent Evaluation
193
+
194
+ This application runs the GAIA (Generative AI Assistant) agent on a set of evaluation questions
195
+ and submits the answers for scoring. The agent uses various tools and APIs to answer questions
196
+ about factual information.
197
+
198
+ ### Features
199
+
200
+ - Fetches evaluation questions from the scoring API
201
+ - Runs the GAIA agent on each question
202
+ - Submits answers for scoring
203
+ - Displays results with feedback
204
+
205
+ ### Technical Details
206
+
207
+ The GAIA agent is built using:
208
+
209
+ - LangChain for agent orchestration
210
+ - Various search tools and APIs
211
+ - Supabase for memory storage
212
+
213
+ For more information, see the project documentation.
214
+ """
215
+ )
216
+
217
+ # Set up event handlers
218
+ run_button.click(
219
+ fn=run_and_submit_all,
220
+ inputs=[username_input],
221
+ outputs=[status_output, results_table]
222
+ )
223
+
224
+ # Launch the app
225
+ if __name__ == "__main__":
226
+ demo.launch()
space_config.json CHANGED
@@ -6,8 +6,7 @@
6
  "sdk": "gradio",
7
  "sdk_version": "3.36.1",
8
  "python_version": "3.9",
9
- "app_file": "app.py",
10
  "pinned": false,
11
- "license": "mit",
12
- "hf_oauth": true
13
  }
 
6
  "sdk": "gradio",
7
  "sdk_version": "3.36.1",
8
  "python_version": "3.9",
9
+ "app_file": "app_no_oauth.py",
10
  "pinned": false,
11
+ "license": "mit"
 
12
  }