Update app.py
Browse files
app.py
CHANGED
@@ -223,61 +223,23 @@ class BasicAgent:
|
|
223 |
# as a last resort, strip everything before the first colon
|
224 |
return raw.split(':', 1)[-1].strip()
|
225 |
|
226 |
-
def __call__(self, question: str, task_id: str = "unknown") -> str:
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
}
|
244 |
-
else:
|
245 |
-
# If not JSON, treat as plain text question
|
246 |
-
state: AgentState = {
|
247 |
-
"question": question,
|
248 |
-
"current_step": "answer",
|
249 |
-
"final_answer": "",
|
250 |
-
"history": [],
|
251 |
-
"needs_search": False,
|
252 |
-
"search_query": "",
|
253 |
-
"task_id": task_id,
|
254 |
-
"logs": {},
|
255 |
-
"file_url": "",
|
256 |
-
"code_blocks": []
|
257 |
-
}
|
258 |
-
|
259 |
-
print(f"\nProcessing task {task_id}")
|
260 |
-
print(f"Question: {state['question']}")
|
261 |
-
print(f"File URL: {state['file_url']}")
|
262 |
-
if state['file_url']:
|
263 |
-
print(f"Raw question data: {question}")
|
264 |
-
|
265 |
-
except (json.JSONDecodeError, KeyError) as e:
|
266 |
-
print(f"Error parsing question data: {e}")
|
267 |
-
print(f"Raw question data: {question}")
|
268 |
-
# Fall back to treating as plain text
|
269 |
-
state: AgentState = {
|
270 |
-
"question": question,
|
271 |
-
"current_step": "answer",
|
272 |
-
"final_answer": "",
|
273 |
-
"history": [],
|
274 |
-
"needs_search": False,
|
275 |
-
"search_query": "",
|
276 |
-
"task_id": task_id,
|
277 |
-
"logs": {},
|
278 |
-
"file_url": "",
|
279 |
-
"code_blocks": []
|
280 |
-
}
|
281 |
|
282 |
final_state = self.workflow.invoke(state)
|
283 |
return final_state["final_answer"]
|
@@ -379,6 +341,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
379 |
api_url = DEFAULT_API_URL
|
380 |
questions_url = f"{api_url}/questions"
|
381 |
submit_url = f"{api_url}/submit"
|
|
|
382 |
|
383 |
# 1. Instantiate Agent
|
384 |
try:
|
@@ -414,12 +377,22 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
414 |
|
415 |
try:
|
416 |
print(f"\nProcessing question {task_id}...")
|
417 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
418 |
|
419 |
# Add to results
|
420 |
answers_payload.append({
|
421 |
"task_id": task_id,
|
422 |
-
"submitted_answer": answer
|
423 |
})
|
424 |
results_log.append({
|
425 |
"Task ID": task_id,
|
|
|
223 |
# as a last resort, strip everything before the first colon
|
224 |
return raw.split(':', 1)[-1].strip()
|
225 |
|
226 |
+
def __call__(self, question: str, task_id: str = "unknown", file_url: str = "") -> str:
|
227 |
+
state: AgentState = {
|
228 |
+
"question": question,
|
229 |
+
"current_step": "answer",
|
230 |
+
"final_answer": "",
|
231 |
+
"history": [],
|
232 |
+
"needs_search": False,
|
233 |
+
"search_query": "",
|
234 |
+
"task_id": task_id,
|
235 |
+
"logs": {},
|
236 |
+
"file_url": file_url,
|
237 |
+
"code_blocks": []
|
238 |
+
}
|
239 |
+
|
240 |
+
print(f"\nProcessing task {task_id}")
|
241 |
+
print(f"Question: {state['question']}")
|
242 |
+
print(f"File URL: {state['file_url']}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
|
244 |
final_state = self.workflow.invoke(state)
|
245 |
return final_state["final_answer"]
|
|
|
341 |
api_url = DEFAULT_API_URL
|
342 |
questions_url = f"{api_url}/questions"
|
343 |
submit_url = f"{api_url}/submit"
|
344 |
+
file_base_url = f"{api_url}/file" # Base URL for file downloads
|
345 |
|
346 |
# 1. Instantiate Agent
|
347 |
try:
|
|
|
377 |
|
378 |
try:
|
379 |
print(f"\nProcessing question {task_id}...")
|
380 |
+
|
381 |
+
# Build file URL if file_name is present
|
382 |
+
file_name = item.get("file_name", "")
|
383 |
+
file_url = f"{file_base_url}/{file_name}" if file_name else ""
|
384 |
+
|
385 |
+
# Call agent with question, task_id, and file_url
|
386 |
+
answer = agent(
|
387 |
+
question=item.get("question", ""),
|
388 |
+
task_id=task_id,
|
389 |
+
file_url=file_url
|
390 |
+
)
|
391 |
|
392 |
# Add to results
|
393 |
answers_payload.append({
|
394 |
"task_id": task_id,
|
395 |
+
"submitted_answer": answer
|
396 |
})
|
397 |
results_log.append({
|
398 |
"Task ID": task_id,
|