naman1102 commited on
Commit
a1148b5
·
1 Parent(s): 7002459

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -57
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
- # Parse question to get both text and file_url
228
- try:
229
- # First try to parse as JSON
230
- if isinstance(question, str) and question.strip().startswith('{'):
231
- question_data = json.loads(question)
232
- state: AgentState = {
233
- "question": question_data.get("question", ""),
234
- "current_step": "answer",
235
- "final_answer": "",
236
- "history": [],
237
- "needs_search": False,
238
- "search_query": "",
239
- "task_id": task_id,
240
- "logs": {},
241
- "file_url": question_data.get("file_url", ""),
242
- "code_blocks": question_data.get("code_blocks", [])
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
- answer = agent(item.get("question", ""), task_id)
 
 
 
 
 
 
 
 
 
 
418
 
419
  # Add to results
420
  answers_payload.append({
421
  "task_id": task_id,
422
- "submitted_answer": answer # Plain string, not JSON encoded
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,