Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -89,10 +89,7 @@ class ExcelToTextTool(Tool):
|
|
| 89 |
if not path.exists():
|
| 90 |
return f"Error: Excel file not found at {path}"
|
| 91 |
try:
|
| 92 |
-
if sheet_name
|
| 93 |
-
sheet = 0
|
| 94 |
-
else:
|
| 95 |
-
sheet = int(sheet_name) if sheet_name.isdigit() else sheet_name
|
| 96 |
df = pd.read_excel(path, sheet_name=sheet)
|
| 97 |
if hasattr(pd.DataFrame, "to_markdown"):
|
| 98 |
return df.to_markdown(index=False)
|
|
@@ -102,13 +99,10 @@ class ExcelToTextTool(Tool):
|
|
| 102 |
|
| 103 |
def download_file_if_any(base_api_url: str, task_id: str) -> str | None:
|
| 104 |
url = f"{base_api_url}/files/{task_id}"
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
resp.raise_for_status()
|
| 110 |
-
except requests.exceptions.HTTPError:
|
| 111 |
-
raise
|
| 112 |
cdisp = resp.headers.get("content-disposition", "")
|
| 113 |
filename = task_id
|
| 114 |
if "filename=" in cdisp:
|
|
@@ -172,11 +166,11 @@ def run_and_submit_all(username: str):
|
|
| 172 |
q = item.get("question")
|
| 173 |
if not (task_id and q):
|
| 174 |
continue
|
| 175 |
-
file_path = None
|
| 176 |
try:
|
| 177 |
file_path = download_file_if_any(api_url, task_id)
|
| 178 |
except Exception as fe:
|
| 179 |
print(f"[file fetch error] {task_id}: {fe}")
|
|
|
|
| 180 |
prompt = q + (f"\n\n---\nFile at: {file_path}\n---\n\n" if file_path else "")
|
| 181 |
try:
|
| 182 |
ans = agent(prompt)
|
|
@@ -188,9 +182,13 @@ def run_and_submit_all(username: str):
|
|
| 188 |
if not payload:
|
| 189 |
return "No answers generated.", pd.DataFrame(results_log)
|
| 190 |
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
try:
|
| 193 |
-
r = requests.post(submit_url, json=
|
| 194 |
r.raise_for_status()
|
| 195 |
res = r.json()
|
| 196 |
status = (
|
|
|
|
| 89 |
if not path.exists():
|
| 90 |
return f"Error: Excel file not found at {path}"
|
| 91 |
try:
|
| 92 |
+
sheet = 0 if not sheet_name else (int(sheet_name) if sheet_name.isdigit() else sheet_name)
|
|
|
|
|
|
|
|
|
|
| 93 |
df = pd.read_excel(path, sheet_name=sheet)
|
| 94 |
if hasattr(pd.DataFrame, "to_markdown"):
|
| 95 |
return df.to_markdown(index=False)
|
|
|
|
| 99 |
|
| 100 |
def download_file_if_any(base_api_url: str, task_id: str) -> str | None:
|
| 101 |
url = f"{base_api_url}/files/{task_id}"
|
| 102 |
+
resp = requests.get(url, timeout=30)
|
| 103 |
+
if resp.status_code == 404:
|
| 104 |
+
return None
|
| 105 |
+
resp.raise_for_status()
|
|
|
|
|
|
|
|
|
|
| 106 |
cdisp = resp.headers.get("content-disposition", "")
|
| 107 |
filename = task_id
|
| 108 |
if "filename=" in cdisp:
|
|
|
|
| 166 |
q = item.get("question")
|
| 167 |
if not (task_id and q):
|
| 168 |
continue
|
|
|
|
| 169 |
try:
|
| 170 |
file_path = download_file_if_any(api_url, task_id)
|
| 171 |
except Exception as fe:
|
| 172 |
print(f"[file fetch error] {task_id}: {fe}")
|
| 173 |
+
file_path = None
|
| 174 |
prompt = q + (f"\n\n---\nFile at: {file_path}\n---\n\n" if file_path else "")
|
| 175 |
try:
|
| 176 |
ans = agent(prompt)
|
|
|
|
| 182 |
if not payload:
|
| 183 |
return "No answers generated.", pd.DataFrame(results_log)
|
| 184 |
|
| 185 |
+
submission = {
|
| 186 |
+
"username": username.strip(),
|
| 187 |
+
"agent_code": agent_code,
|
| 188 |
+
"answers": payload
|
| 189 |
+
}
|
| 190 |
try:
|
| 191 |
+
r = requests.post(submit_url, json=submission, timeout=60)
|
| 192 |
r.raise_for_status()
|
| 193 |
res = r.json()
|
| 194 |
status = (
|