keynes42 commited on
Commit
9d68037
·
verified ·
1 Parent(s): 9e16544

Update app.py

Browse files

Update run_and_submit_all to ensure the agent automatically downloads attachments from URL and file name.

Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -314,7 +314,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
314
  return f"An unexpected error occurred fetching questions: {e}", None
315
 
316
  # Find those with attachments
317
- # questions_data = [questions_data[i] for i in [3,9,11,13,19]]
318
 
319
  # 3. Run your Agent
320
  results_log = []
@@ -328,10 +328,25 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
328
  # Check for an associated filename and enhance the prompt
329
  file_name = item.get("file_name")
330
  if file_name:
331
- # Construct a new prompt that includes the filename information
332
- prompt_addition = f"\n[System Note: The file you need to analyze for this task is named '{file_name}'.]"
333
- question_text = question_text + prompt_addition
334
- print(f"Enhanced prompt for task {task_id}: {question_text}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
335
 
336
  if not task_id or question_text is None:
337
  print(f"Skipping item with missing task_id or question: {item}")
 
314
  return f"An unexpected error occurred fetching questions: {e}", None
315
 
316
  # Find those with attachments
317
+ questions_data = [questions_data[i] for i in [3,9,11,13,19]]
318
 
319
  # 3. Run your Agent
320
  results_log = []
 
328
  # Check for an associated filename and enhance the prompt
329
  file_name = item.get("file_name")
330
  if file_name:
331
+ print(f"Task {task_id} requires file: '{file_name}'. Downloading...")
332
+ file_download_url = f"{api_url}/get_file/{file_name}"
333
+ # Make the request to download the file and save locally
334
+ try:
335
+ file_response = requests.get(file_download_url, timeout=30)
336
+ file_response.raise_for_status() # Check for download errors
337
+
338
+ # Save the file locally so the agent's tools can find it
339
+ with open(file_name, "wb") as f:
340
+ f.write(file_response.content)
341
+ print(f"Successfully downloaded and saved '{file_name}' locally.")
342
+
343
+ # Now, enrich the prompt with the filename
344
+ question_text = question_text + f"\n\n[System Note: The file you need to analyze for this task is named '{file_name}'.]"
345
+
346
+ except requests.exceptions.RequestException as e:
347
+ print(f"Error downloading file for task {task_id}: {e}")
348
+ # If download fails, inform the agent it's missing
349
+ question_text = question_text + f"\n\n[System Note: A file named '{file_name}' was required for this task, but it could not be downloaded. Please report that the file is inaccessible.]"
350
 
351
  if not task_id or question_text is None:
352
  print(f"Skipping item with missing task_id or question: {item}")