Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1529,61 +1529,32 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 1529 |
question_text = item.get("question")
|
| 1530 |
correct_answer = item.get("answer", "N/A") # Get correct answer from API
|
| 1531 |
|
| 1532 |
-
#
|
| 1533 |
-
|
| 1534 |
-
|
| 1535 |
-
local_file_path = None
|
| 1536 |
|
| 1537 |
try:
|
| 1538 |
-
|
| 1539 |
-
if
|
| 1540 |
-
#
|
| 1541 |
-
|
| 1542 |
-
if 'Content-Disposition' in file_response.headers:
|
| 1543 |
-
cd = file_response.headers['Content-Disposition']
|
| 1544 |
-
filename_match = re.findall('filename="?([^"]+)"?', cd)
|
| 1545 |
-
if filename_match:
|
| 1546 |
-
filename = filename_match[0]
|
| 1547 |
|
| 1548 |
-
|
| 1549 |
-
|
| 1550 |
-
|
| 1551 |
-
|
| 1552 |
-
|
| 1553 |
-
|
| 1554 |
-
|
| 1555 |
-
|
| 1556 |
-
|
| 1557 |
-
|
| 1558 |
-
'text/csv': '.csv',
|
| 1559 |
-
'application/pdf': '.pdf',
|
| 1560 |
-
'text/x-python': '.py',
|
| 1561 |
-
'application/x-python-code': '.py',
|
| 1562 |
-
}
|
| 1563 |
-
ext = ext_map.get(content_type, '')
|
| 1564 |
-
filename = f"{task_id}{ext}"
|
| 1565 |
-
|
| 1566 |
-
# Save to current directory
|
| 1567 |
-
local_file_path = filename
|
| 1568 |
-
|
| 1569 |
-
with open(local_file_path, 'wb') as f:
|
| 1570 |
-
for chunk in file_response.iter_content(chunk_size=8192):
|
| 1571 |
-
f.write(chunk)
|
| 1572 |
-
|
| 1573 |
-
file_size = os.path.getsize(local_file_path)
|
| 1574 |
-
abs_path = os.path.abspath(local_file_path)
|
| 1575 |
-
|
| 1576 |
-
print(f"✅ Downloaded: {filename} ({file_size} bytes)")
|
| 1577 |
-
print(f" Saved to: {abs_path}")
|
| 1578 |
-
elif file_response.status_code == 404:
|
| 1579 |
-
print(f"ℹ️ No file found for task {task_id} (404), proceeding without file.")
|
| 1580 |
else:
|
| 1581 |
-
print(f"⚠️ Warning:
|
| 1582 |
|
| 1583 |
except Exception as e:
|
| 1584 |
-
|
| 1585 |
-
|
| 1586 |
-
|
| 1587 |
try:
|
| 1588 |
# Pass file_path to agent
|
| 1589 |
submitted_answer = agent(question_text, local_file_path)
|
|
|
|
| 1529 |
question_text = item.get("question")
|
| 1530 |
correct_answer = item.get("answer", "N/A") # Get correct answer from API
|
| 1531 |
|
| 1532 |
+
# Look for file locally in files/ directory
|
| 1533 |
+
local_file_path = None
|
| 1534 |
+
files_dir = "files"
|
|
|
|
| 1535 |
|
| 1536 |
try:
|
| 1537 |
+
# Check if files directory exists
|
| 1538 |
+
if os.path.exists(files_dir):
|
| 1539 |
+
# Look for any file that starts with the task_id
|
| 1540 |
+
matching_files = [f for f in os.listdir(files_dir) if f.startswith(task_id)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1541 |
|
| 1542 |
+
if matching_files:
|
| 1543 |
+
# Use the first matching file
|
| 1544 |
+
local_file_path = os.path.join(files_dir, matching_files[0])
|
| 1545 |
+
file_size = os.path.getsize(local_file_path)
|
| 1546 |
+
abs_path = os.path.abspath(local_file_path)
|
| 1547 |
+
|
| 1548 |
+
print(f"✅ Found file: {matching_files[0]} ({file_size} bytes)")
|
| 1549 |
+
print(f" Path: {abs_path}")
|
| 1550 |
+
else:
|
| 1551 |
+
print(f"ℹ️ No file found for task {task_id}, proceeding without file.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1552 |
else:
|
| 1553 |
+
print(f"⚠️ Warning: '{files_dir}' directory not found.")
|
| 1554 |
|
| 1555 |
except Exception as e:
|
| 1556 |
+
print(f"❌ Error looking for file: {e}")
|
| 1557 |
+
|
|
|
|
| 1558 |
try:
|
| 1559 |
# Pass file_path to agent
|
| 1560 |
submitted_answer = agent(question_text, local_file_path)
|