Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
# π
|
| 1332 |
-
local_file_path =
|
| 1333 |
-
|
| 1334 |
-
|
| 1335 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1336 |
|
| 1337 |
-
#
|
| 1338 |
-
|
| 1339 |
-
|
| 1340 |
-
|
| 1341 |
-
|
| 1342 |
-
|
| 1343 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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}")
|