gabejavitt commited on
Commit
baf7b41
Β·
verified Β·
1 Parent(s): e8bd4b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -17
app.py CHANGED
@@ -1320,27 +1320,45 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
1320
  answers_payload = []
1321
  print(f"Running agent on {len(questions_data)} questions...")
1322
  for item in questions_data:
 
1323
  task_id = item.get("task_id")
1324
  question_text = item.get("question")
1325
- file_path_from_api = item["file_path"]
1326
- file_download_url = f"{DEFAULT_API_URL}/files/{task_id}"
1327
- file_info = []
1328
- # Extract the original file name to preserve the extension (e.g., .pdf, .jpg)
1329
- original_filename = file_path_from_api.split('/')[-1]
1330
 
1331
- # 🌟 NEW: Save the file to the /tmp directory
1332
- local_file_path = os.path.join("/tmp", original_filename)
1333
- try:
1334
- file_response = requests.get(file_download_url, timeout=15)
1335
- file_response.raise_for_status()
 
 
 
 
 
 
1336
 
1337
- # 🌟 CRITICAL: Write the raw bytes content to the local file path
1338
- with open(local_file_path, 'wb') as f:
1339
- f.write(file_response.content)
1340
- print(f"βœ… Downloaded file to: {local_file_path}")
1341
- file_info = local_file_path
1342
- except requests.exceptions.RequestException as e:
1343
- error_message = f"[FILE DOWNLOAD ERROR: Could not fetch file from {file_download_url}: {e}]"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1344
 
1345
  if not task_id or question_text is None:
1346
  print(f"Skipping item with missing task_id or question: {item}")
 
1320
  answers_payload = []
1321
  print(f"Running agent on {len(questions_data)} questions...")
1322
  for item in questions_data:
1323
+
1324
  task_id = item.get("task_id")
1325
  question_text = item.get("question")
 
 
 
 
 
1326
 
1327
+ # 🌟 Initialize file variables for the current question
1328
+ local_file_path = None
1329
+ file_info = ""
1330
+
1331
+ # 🌟 CRITICAL: Check if 'file_path' exists in the item dictionary
1332
+ if item.get("file_path"):
1333
+ file_path_from_api = item["file_path"]
1334
+ file_download_url = f"{DEFAULT_API_URL}/files/{task_id}"
1335
+
1336
+ # Extract the original file name to preserve the extension
1337
+ original_filename = file_path_from_api.split('/')[-1]
1338
 
1339
+ # Set the path where the file will be saved locally
1340
+ local_file_path = os.path.join("/tmp", original_filename)
1341
+
1342
+ # --- (Add streaming update here for file download status) ---
1343
+
1344
+ try:
1345
+ file_response = requests.get(file_download_url, timeout=15)
1346
+ file_response.raise_for_status()
1347
+
1348
+ # Save the raw bytes content to the local file path
1349
+ with open(local_file_path, 'wb') as f:
1350
+ f.write(file_response.content)
1351
+
1352
+ print(f"βœ… Downloaded file to: {local_file_path}")
1353
+
1354
+ # Set the context string to be passed to the agent
1355
+ file_info = f"\n\n[FILE ATTACHED: {local_file_path}]"
1356
+
1357
+ except requests.exceptions.RequestException as e:
1358
+ error_message = f"[FILE DOWNLOAD ERROR: Could not fetch file: {e}]"
1359
+ print(f"⚠️ {error_message}")
1360
+ # Still provide the error message as context to the agent
1361
+ file_info = f"\n\n{error_message}"
1362
 
1363
  if not task_id or question_text is None:
1364
  print(f"Skipping item with missing task_id or question: {item}")