Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -81,7 +81,7 @@ def run_and_submit_all(nb_questions: int, profile: gr.OAuthProfile | None):
|
|
| 81 |
|
| 82 |
# for testing keep only some questions
|
| 83 |
questions_data = questions_data[:nb_questions]
|
| 84 |
-
|
| 85 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 86 |
for item in questions_data:
|
| 87 |
task_id = item.get("task_id")
|
|
@@ -90,6 +90,7 @@ def run_and_submit_all(nb_questions: int, profile: gr.OAuthProfile | None):
|
|
| 90 |
file_question_url = None
|
| 91 |
if file_name:
|
| 92 |
file_question_url = f"{file_url}/{task_id}"
|
|
|
|
| 93 |
if not task_id or question_text is None:
|
| 94 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 95 |
continue
|
|
@@ -99,13 +100,13 @@ def run_and_submit_all(nb_questions: int, profile: gr.OAuthProfile | None):
|
|
| 99 |
agent_question += f"\n\nFile URL: {file_question_url}"
|
| 100 |
|
| 101 |
submitted_answer = agent(agent_question)
|
| 102 |
-
|
| 103 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 104 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 105 |
except Exception as e:
|
| 106 |
print(f"Error running agent on task {task_id}: {e}")
|
| 107 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 108 |
-
|
| 109 |
if not answers_payload:
|
| 110 |
print("Agent did not produce any answers to submit.")
|
| 111 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
|
@@ -114,12 +115,14 @@ def run_and_submit_all(nb_questions: int, profile: gr.OAuthProfile | None):
|
|
| 114 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
| 115 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
| 116 |
print(status_update)
|
| 117 |
-
|
| 118 |
# 5. Submit
|
| 119 |
print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
|
| 120 |
try:
|
|
|
|
| 121 |
response = requests.post(submit_url, json=submission_data, timeout=60)
|
| 122 |
response.raise_for_status()
|
|
|
|
| 123 |
result_data = response.json()
|
| 124 |
final_status = (
|
| 125 |
f"Submission Successful!\n"
|
|
@@ -181,7 +184,7 @@ with gr.Blocks() as demo:
|
|
| 181 |
"""
|
| 182 |
)
|
| 183 |
|
| 184 |
-
|
| 185 |
|
| 186 |
nb_questions = gr.Number(value=20)
|
| 187 |
|
|
@@ -193,7 +196,7 @@ with gr.Blocks() as demo:
|
|
| 193 |
|
| 194 |
run_button.click(
|
| 195 |
fn=run_and_submit_all,
|
| 196 |
-
inputs=[nb_questions
|
| 197 |
outputs=[status_output, results_table]
|
| 198 |
)
|
| 199 |
|
|
|
|
| 81 |
|
| 82 |
# for testing keep only some questions
|
| 83 |
questions_data = questions_data[:nb_questions]
|
| 84 |
+
print('1')
|
| 85 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 86 |
for item in questions_data:
|
| 87 |
task_id = item.get("task_id")
|
|
|
|
| 90 |
file_question_url = None
|
| 91 |
if file_name:
|
| 92 |
file_question_url = f"{file_url}/{task_id}"
|
| 93 |
+
print('2')
|
| 94 |
if not task_id or question_text is None:
|
| 95 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 96 |
continue
|
|
|
|
| 100 |
agent_question += f"\n\nFile URL: {file_question_url}"
|
| 101 |
|
| 102 |
submitted_answer = agent(agent_question)
|
| 103 |
+
print('3')
|
| 104 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 105 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 106 |
except Exception as e:
|
| 107 |
print(f"Error running agent on task {task_id}: {e}")
|
| 108 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 109 |
+
print('4')
|
| 110 |
if not answers_payload:
|
| 111 |
print("Agent did not produce any answers to submit.")
|
| 112 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
|
|
|
| 115 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
| 116 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
| 117 |
print(status_update)
|
| 118 |
+
print('5')
|
| 119 |
# 5. Submit
|
| 120 |
print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
|
| 121 |
try:
|
| 122 |
+
print('6')
|
| 123 |
response = requests.post(submit_url, json=submission_data, timeout=60)
|
| 124 |
response.raise_for_status()
|
| 125 |
+
print('7')
|
| 126 |
result_data = response.json()
|
| 127 |
final_status = (
|
| 128 |
f"Submission Successful!\n"
|
|
|
|
| 184 |
"""
|
| 185 |
)
|
| 186 |
|
| 187 |
+
gr.LoginButton()
|
| 188 |
|
| 189 |
nb_questions = gr.Number(value=20)
|
| 190 |
|
|
|
|
| 196 |
|
| 197 |
run_button.click(
|
| 198 |
fn=run_and_submit_all,
|
| 199 |
+
inputs=[nb_questions],
|
| 200 |
outputs=[status_output, results_table]
|
| 201 |
)
|
| 202 |
|