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 |
from langchain_core.messages import HumanMessage
|
| 8 |
from langgraph_agent import build_graph
|
| 9 |
|
|
@@ -117,7 +116,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 117 |
answers_payload.append({
|
| 118 |
"task_id": task_id,
|
| 119 |
"model_answer": submitted_answer,
|
| 120 |
-
# "reasoning_trace": None #
|
| 121 |
})
|
| 122 |
results_log.append({
|
| 123 |
"Task ID": task_id,
|
|
@@ -141,28 +140,18 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 141 |
print("Agent did not produce any answers to submit.")
|
| 142 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 143 |
|
| 144 |
-
#
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
# Prepare file-like object for upload
|
| 148 |
-
file_like = io.BytesIO(json_lines_str.encode("utf-8"))
|
| 149 |
-
file_like.name = "submission.jsonl" # Filename required for multipart upload
|
| 150 |
-
|
| 151 |
-
# Prepare multipart form data
|
| 152 |
-
files = {
|
| 153 |
-
"file": (file_like.name, file_like, "application/jsonl")
|
| 154 |
-
}
|
| 155 |
-
data = {
|
| 156 |
"username": username.strip(),
|
| 157 |
-
"agent_code": agent_code
|
|
|
|
| 158 |
}
|
| 159 |
|
| 160 |
print(f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'...")
|
| 161 |
|
| 162 |
-
# 5. Submit
|
| 163 |
-
print(f"Submitting answers to: {submit_url}")
|
| 164 |
try:
|
| 165 |
-
response = requests.post(submit_url,
|
| 166 |
response.raise_for_status()
|
| 167 |
result_data = response.json()
|
| 168 |
final_status = (
|
|
|
|
| 3 |
import requests
|
| 4 |
import pandas as pd
|
| 5 |
import json
|
|
|
|
| 6 |
from langchain_core.messages import HumanMessage
|
| 7 |
from langgraph_agent import build_graph
|
| 8 |
|
|
|
|
| 116 |
answers_payload.append({
|
| 117 |
"task_id": task_id,
|
| 118 |
"model_answer": submitted_answer,
|
| 119 |
+
# "reasoning_trace": None # optional, add if available
|
| 120 |
})
|
| 121 |
results_log.append({
|
| 122 |
"Task ID": task_id,
|
|
|
|
| 140 |
print("Agent did not produce any answers to submit.")
|
| 141 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 142 |
|
| 143 |
+
# 4. Prepare submission JSON object
|
| 144 |
+
submission_data = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
"username": username.strip(),
|
| 146 |
+
"agent_code": agent_code,
|
| 147 |
+
"answers": answers_payload
|
| 148 |
}
|
| 149 |
|
| 150 |
print(f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'...")
|
| 151 |
|
| 152 |
+
# 5. Submit answers as JSON body
|
|
|
|
| 153 |
try:
|
| 154 |
+
response = requests.post(submit_url, json=submission_data, timeout=60)
|
| 155 |
response.raise_for_status()
|
| 156 |
result_data = response.json()
|
| 157 |
final_status = (
|