Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1533,54 +1533,22 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 1533 |
correct_answer = item.get("answer", "N/A") # Get correct answer from API
|
| 1534 |
|
| 1535 |
# Initialize file variables for the current question
|
| 1536 |
-
|
| 1537 |
-
|
| 1538 |
-
|
| 1539 |
-
|
| 1540 |
-
|
| 1541 |
-
file_download_url =
|
| 1542 |
-
|
| 1543 |
-
|
| 1544 |
-
original_filename = file_path_from_api.split('/')[-1]
|
| 1545 |
-
|
| 1546 |
-
# Save to current directory instead of /tmp
|
| 1547 |
-
local_file_path = original_filename
|
| 1548 |
-
|
| 1549 |
-
print(f"📥 Downloading file for task {task_id}...")
|
| 1550 |
-
print(f" URL: {file_download_url}")
|
| 1551 |
-
print(f" Original filename: {original_filename}")
|
| 1552 |
-
print(f" Saving to: {local_file_path}")
|
| 1553 |
-
|
| 1554 |
-
try:
|
| 1555 |
-
file_response = requests.get(file_download_url, timeout=15)
|
| 1556 |
-
file_response.raise_for_status()
|
| 1557 |
-
|
| 1558 |
-
# Save the raw bytes content to the local file path
|
| 1559 |
with open(local_file_path, 'wb') as f:
|
| 1560 |
f.write(file_response.content)
|
| 1561 |
-
|
| 1562 |
-
|
| 1563 |
-
|
| 1564 |
-
|
| 1565 |
-
# Verify file exists and is readable
|
| 1566 |
-
if not os.path.exists(local_file_path):
|
| 1567 |
-
print(f"⚠️ Warning: File saved but cannot be found at {local_file_path}")
|
| 1568 |
-
local_file_path = None
|
| 1569 |
-
else:
|
| 1570 |
-
print(f"✓ File accessible at: {os.path.abspath(local_file_path)}")
|
| 1571 |
-
|
| 1572 |
-
except requests.exceptions.RequestException as e:
|
| 1573 |
-
error_message = f"[FILE DOWNLOAD ERROR: Could not fetch file: {e}]"
|
| 1574 |
-
print(f"⚠️ {error_message}")
|
| 1575 |
-
local_file_path = None
|
| 1576 |
-
except Exception as e:
|
| 1577 |
-
error_message = f"[FILE SAVE ERROR: {e}]"
|
| 1578 |
-
print(f"⚠️ {error_message}")
|
| 1579 |
local_file_path = None
|
| 1580 |
-
|
| 1581 |
-
|
| 1582 |
-
print(f"⚠️ Skipping item with missing task_id or question: {item}")
|
| 1583 |
-
continue
|
| 1584 |
|
| 1585 |
try:
|
| 1586 |
# Pass file_path to agent
|
|
|
|
| 1533 |
correct_answer = item.get("answer", "N/A") # Get correct answer from API
|
| 1534 |
|
| 1535 |
# Initialize file variables for the current question
|
| 1536 |
+
# Try to download file for EVERY task (not just if file_path exists)
|
| 1537 |
+
file_download_url = f"{DEFAULT_API_URL}/files/{task_id}"
|
| 1538 |
+
local_file_path = f"{task_id}.tmp" # or detect extension
|
| 1539 |
+
|
| 1540 |
+
try:
|
| 1541 |
+
file_response = requests.get(file_download_url, timeout=15)
|
| 1542 |
+
if file_response.status_code == 200:
|
| 1543 |
+
# File exists, save it
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1544 |
with open(local_file_path, 'wb') as f:
|
| 1545 |
f.write(file_response.content)
|
| 1546 |
+
print(f"✅ Downloaded file for {task_id}")
|
| 1547 |
+
else:
|
| 1548 |
+
# No file for this task, that's fine
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1549 |
local_file_path = None
|
| 1550 |
+
except:
|
| 1551 |
+
local_file_path = None
|
|
|
|
|
|
|
| 1552 |
|
| 1553 |
try:
|
| 1554 |
# Pass file_path to agent
|