mmichiels13 commited on
Commit
6f7960f
·
verified ·
1 Parent(s): 12a86eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -31
app.py CHANGED
@@ -129,49 +129,50 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
129
  return f"An unexpected error occurred fetching questions: {e}", None
130
 
131
  # 3. Run your Agent
132
- from concurrent.futures import ThreadPoolExecutor, as_completed
133
 
134
- results_log = []
135
- answers_payload = []
136
- print(f"Running agent on {len(questions_data)} questions...")
137
-
138
- def process_question(item):
139
- task_id = item.get("task_id")
140
- question_text = item.get("question")
141
- if not task_id or question_text is None:
142
- print(f"Skipping item with missing task_id or question: {item}")
143
- return None, None, None
144
- try:
145
- submitted_answer = agent(question_text)
146
- return task_id, question_text, submitted_answer
147
- except Exception as e:
148
- print(f"Error running agent on task {task_id}: {e}")
149
- return task_id, question_text, f"AGENT ERROR: {e}"
150
-
151
- with ThreadPoolExecutor(max_workers=5) as executor:
152
- futures = {executor.submit(process_question, item): item for item in questions_data}
153
- for future in as_completed(futures):
154
- task_id, question_text, submitted_answer = future.result()
155
- if task_id is None:
156
- continue
157
- answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
158
- results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
159
  # results_log = []
160
  # answers_payload = []
161
  # print(f"Running agent on {len(questions_data)} questions...")
162
- # for item in questions_data:
 
163
  # task_id = item.get("task_id")
164
  # question_text = item.get("question")
165
  # if not task_id or question_text is None:
166
  # print(f"Skipping item with missing task_id or question: {item}")
167
- # continue
168
  # try:
169
  # submitted_answer = agent(question_text)
 
 
 
 
 
 
 
 
 
 
 
170
  # answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
171
  # results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
172
- # except Exception as e:
173
- # print(f"Error running agent on task {task_id}: {e}")
174
- # results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
 
176
  if not answers_payload:
177
  print("Agent did not produce any answers to submit.")
 
129
  return f"An unexpected error occurred fetching questions: {e}", None
130
 
131
  # 3. Run your Agent
132
+ # from concurrent.futures import ThreadPoolExecutor, as_completed
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  # results_log = []
135
  # answers_payload = []
136
  # print(f"Running agent on {len(questions_data)} questions...")
137
+
138
+ # def process_question(item):
139
  # task_id = item.get("task_id")
140
  # question_text = item.get("question")
141
  # if not task_id or question_text is None:
142
  # print(f"Skipping item with missing task_id or question: {item}")
143
+ # return None, None, None
144
  # try:
145
  # submitted_answer = agent(question_text)
146
+ # return task_id, question_text, submitted_answer
147
+ # except Exception as e:
148
+ # print(f"Error running agent on task {task_id}: {e}")
149
+ # return task_id, question_text, f"AGENT ERROR: {e}"
150
+
151
+ # with ThreadPoolExecutor(max_workers=5) as executor:
152
+ # futures = {executor.submit(process_question, item): item for item in questions_data}
153
+ # for future in as_completed(futures):
154
+ # task_id, question_text, submitted_answer = future.result()
155
+ # if task_id is None:
156
+ # continue
157
  # answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
158
  # results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
159
+
160
+ results_log = []
161
+ answers_payload = []
162
+ print(f"Running agent on {len(questions_data)} questions...")
163
+ for item in questions_data:
164
+ task_id = item.get("task_id")
165
+ question_text = item.get("question")
166
+ if not task_id or question_text is None:
167
+ print(f"Skipping item with missing task_id or question: {item}")
168
+ continue
169
+ try:
170
+ submitted_answer = agent(question_text)
171
+ answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
172
+ results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
173
+ except Exception as e:
174
+ print(f"Error running agent on task {task_id}: {e}")
175
+ results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
176
 
177
  if not answers_payload:
178
  print("Agent did not produce any answers to submit.")