Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import gradio as gr
|
|
3 |
import requests
|
4 |
import pandas as pd
|
5 |
import json
|
6 |
-
import io
|
7 |
import re
|
8 |
from langchain_core.messages import HumanMessage
|
9 |
from langgraph_agent import build_graph
|
@@ -95,23 +94,16 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
95 |
print(f"Skipping item with missing task_id or question: {item}")
|
96 |
continue
|
97 |
try:
|
98 |
-
model_answer = agent(question_text, task_id=task_id)
|
99 |
-
|
100 |
-
# Clean trailing quotes/brackets if any
|
101 |
-
if model_answer.endswith("]'") or model_answer.endswith(']"'):
|
102 |
-
model_answer = model_answer[:-2].strip()
|
103 |
if (model_answer.startswith('"') and model_answer.endswith('"')) or \
|
104 |
(model_answer.startswith("'") and model_answer.endswith("'")):
|
105 |
model_answer = model_answer[1:-1].strip()
|
106 |
|
107 |
-
# Placeholder reasoning trace; replace with actual reasoning if available
|
108 |
-
reasoning_trace = f"Reasoning steps for task {task_id}."
|
109 |
-
|
110 |
print(f"Answer for task {task_id}: '{model_answer}'")
|
111 |
answers_payload.append({
|
112 |
"task_id": task_id,
|
113 |
-
"
|
114 |
-
"reasoning_trace": reasoning_trace
|
115 |
})
|
116 |
results_log.append({
|
117 |
"Task ID": task_id,
|
@@ -122,8 +114,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
122 |
print(f"Error running agent on task {task_id}: {e}")
|
123 |
answers_payload.append({
|
124 |
"task_id": task_id,
|
125 |
-
"
|
126 |
-
"reasoning_trace": ""
|
127 |
})
|
128 |
results_log.append({
|
129 |
"Task ID": task_id,
|
@@ -135,17 +126,10 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
135 |
print("Agent did not produce any answers to submit.")
|
136 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
137 |
|
138 |
-
# Serialize to JSON Lines string
|
139 |
-
json_lines_str = "\n".join(json.dumps(ans, ensure_ascii=False) for ans in answers_payload)
|
140 |
-
file_like = io.BytesIO(json_lines_str.encode("utf-8"))
|
141 |
-
file_like.name = "submission.jsonl"
|
142 |
-
|
143 |
data = {
|
144 |
"username": username.strip(),
|
145 |
-
"agent_code": agent_code
|
146 |
-
|
147 |
-
files = {
|
148 |
-
"file": (file_like.name, file_like, "application/jsonl")
|
149 |
}
|
150 |
|
151 |
print(f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'...")
|
@@ -155,7 +139,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
155 |
|
156 |
print(f"Submitting answers to: {submit_url}")
|
157 |
try:
|
158 |
-
response = requests.post(submit_url,
|
159 |
response.raise_for_status()
|
160 |
result_data = response.json()
|
161 |
final_status = (
|
|
|
3 |
import requests
|
4 |
import pandas as pd
|
5 |
import json
|
|
|
6 |
import re
|
7 |
from langchain_core.messages import HumanMessage
|
8 |
from langgraph_agent import build_graph
|
|
|
94 |
print(f"Skipping item with missing task_id or question: {item}")
|
95 |
continue
|
96 |
try:
|
97 |
+
model_answer = agent(question_text, task_id=task_id).strip()
|
98 |
+
# Clean trailing quotes if any
|
|
|
|
|
|
|
99 |
if (model_answer.startswith('"') and model_answer.endswith('"')) or \
|
100 |
(model_answer.startswith("'") and model_answer.endswith("'")):
|
101 |
model_answer = model_answer[1:-1].strip()
|
102 |
|
|
|
|
|
|
|
103 |
print(f"Answer for task {task_id}: '{model_answer}'")
|
104 |
answers_payload.append({
|
105 |
"task_id": task_id,
|
106 |
+
"submitted_answer": model_answer
|
|
|
107 |
})
|
108 |
results_log.append({
|
109 |
"Task ID": task_id,
|
|
|
114 |
print(f"Error running agent on task {task_id}: {e}")
|
115 |
answers_payload.append({
|
116 |
"task_id": task_id,
|
117 |
+
"submitted_answer": f"AGENT ERROR: {e}"
|
|
|
118 |
})
|
119 |
results_log.append({
|
120 |
"Task ID": task_id,
|
|
|
126 |
print("Agent did not produce any answers to submit.")
|
127 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
128 |
|
|
|
|
|
|
|
|
|
|
|
129 |
data = {
|
130 |
"username": username.strip(),
|
131 |
+
"agent_code": agent_code,
|
132 |
+
"answers": answers_payload
|
|
|
|
|
133 |
}
|
134 |
|
135 |
print(f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'...")
|
|
|
139 |
|
140 |
print(f"Submitting answers to: {submit_url}")
|
141 |
try:
|
142 |
+
response = requests.post(submit_url, json=data, timeout=60)
|
143 |
response.raise_for_status()
|
144 |
result_data = response.json()
|
145 |
final_status = (
|