Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -496,17 +496,22 @@ def _stage_zip(upload, into_dir: Path) -> Path:
|
|
| 496 |
except Exception:
|
| 497 |
pass
|
| 498 |
|
| 499 |
-
# --- 7)
|
|
|
|
|
|
|
|
|
|
| 500 |
excels = []
|
| 501 |
for ext in (".xlsx", ".xls", ".xlsm"):
|
| 502 |
-
excels.extend(
|
| 503 |
excels = [p for p in excels if not p.name.startswith("~$")]
|
| 504 |
if not excels:
|
| 505 |
_validation_error(
|
| 506 |
-
"The
|
| 507 |
-
"Your ZIP has the right structure, but <code>
|
| 508 |
-
"contains no Excel files. Put your
|
| 509 |
-
"
|
|
|
|
|
|
|
| 510 |
)
|
| 511 |
|
| 512 |
# Stash the resolved layout on the upload object via attribute trick —
|
|
@@ -669,9 +674,9 @@ with tab_inputs:
|
|
| 669 |
)
|
| 670 |
st.caption(
|
| 671 |
"Required ZIP layout: "
|
| 672 |
-
"**`Input/`**
|
| 673 |
-
"**`Output/`** · "
|
| 674 |
-
"**`Summary/`**. "
|
| 675 |
"One ZIP per run."
|
| 676 |
)
|
| 677 |
|
|
@@ -1011,16 +1016,23 @@ if ss.trigger_run:
|
|
| 1011 |
# Strict single-ZIP validation + extract Input/Output/Summary
|
| 1012 |
staged_root = _stage_zip(ai_zip, tmp_path / "staged")
|
| 1013 |
layout = ss.zip_layout
|
| 1014 |
-
|
| 1015 |
-
|
|
|
|
| 1016 |
summary_dir = Path(layout["summary"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1017 |
tie_path = HERE / "resources" / "TIE_Requirements.xlsx"
|
| 1018 |
|
| 1019 |
def _progress_cb(info):
|
| 1020 |
ss.progress_rows.append(info)
|
| 1021 |
|
| 1022 |
summary, error = _run_batch_in_subprocess(
|
| 1023 |
-
ai_dir=ai_dir, out_dir=
|
| 1024 |
email=bna_email, password=bna_password,
|
| 1025 |
lang=lang, log_box=log_box, progress_callback=_progress_cb,
|
| 1026 |
)
|
|
@@ -1029,17 +1041,18 @@ if ss.trigger_run:
|
|
| 1029 |
ss.run_status = "error"
|
| 1030 |
ss.run_error_msg = error
|
| 1031 |
else:
|
| 1032 |
-
# Move
|
| 1033 |
-
#
|
| 1034 |
-
#
|
|
|
|
| 1035 |
try:
|
| 1036 |
-
for f in
|
| 1037 |
-
|
|
|
|
|
|
|
|
|
|
| 1038 |
except Exception:
|
| 1039 |
pass
|
| 1040 |
-
# Repackage the whole Input/Output/Summary tree (sans
|
| 1041 |
-
# the original Input/ payload) so the researcher can
|
| 1042 |
-
# download an organized result archive.
|
| 1043 |
zip_bytes = _zip_directory(staged_root)
|
| 1044 |
ss.last_zip_bytes = zip_bytes
|
| 1045 |
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
|
| 496 |
except Exception:
|
| 497 |
pass
|
| 498 |
|
| 499 |
+
# --- 7) Output/ must have at least one Excel file ------------------
|
| 500 |
+
# The AI pipeline's output Excels live under Output/ (possibly nested
|
| 501 |
+
# under per-project subfolders). The Comparator walks Output/ recursively
|
| 502 |
+
# for any .xlsx / .xls / .xlsm.
|
| 503 |
excels = []
|
| 504 |
for ext in (".xlsx", ".xls", ".xlsm"):
|
| 505 |
+
excels.extend(output_dir.rglob(f"*{ext}"))
|
| 506 |
excels = [p for p in excels if not p.name.startswith("~$")]
|
| 507 |
if not excels:
|
| 508 |
_validation_error(
|
| 509 |
+
"The Output/ folder has no AI Excels",
|
| 510 |
+
"Your ZIP has the right structure, but <code>Output/</code> "
|
| 511 |
+
"(or any of its sub-folders) contains no Excel files. Put your "
|
| 512 |
+
"AI output Excels (<code>.xlsx</code>) anywhere inside "
|
| 513 |
+
"<code>Output/</code> — they can be in per-project sub-folders "
|
| 514 |
+
"if you prefer — then re-zip and upload again.",
|
| 515 |
)
|
| 516 |
|
| 517 |
# Stash the resolved layout on the upload object via attribute trick —
|
|
|
|
| 674 |
)
|
| 675 |
st.caption(
|
| 676 |
"Required ZIP layout: "
|
| 677 |
+
"**`Input/`** · "
|
| 678 |
+
"**`Output/`** (your AI output Excels — sub-folders OK) · "
|
| 679 |
+
"**`Summary/`** (or `Summary.xlsx`). "
|
| 680 |
"One ZIP per run."
|
| 681 |
)
|
| 682 |
|
|
|
|
| 1016 |
# Strict single-ZIP validation + extract Input/Output/Summary
|
| 1017 |
staged_root = _stage_zip(ai_zip, tmp_path / "staged")
|
| 1018 |
layout = ss.zip_layout
|
| 1019 |
+
# AI source Excels are inside Output/ (the AI pipeline's
|
| 1020 |
+
# outputs become the Comparator's inputs).
|
| 1021 |
+
ai_dir = Path(layout["output"])
|
| 1022 |
summary_dir = Path(layout["summary"])
|
| 1023 |
+
# Engine writes per-project results into a separate temp
|
| 1024 |
+
# directory so we don't pollute the researcher's Output/
|
| 1025 |
+
# folder (which they may want preserved as-is). After the
|
| 1026 |
+
# run we move everything into Summary/ for the download.
|
| 1027 |
+
engine_out = tmp_path / "engine_results"
|
| 1028 |
+
engine_out.mkdir(parents=True, exist_ok=True)
|
| 1029 |
tie_path = HERE / "resources" / "TIE_Requirements.xlsx"
|
| 1030 |
|
| 1031 |
def _progress_cb(info):
|
| 1032 |
ss.progress_rows.append(info)
|
| 1033 |
|
| 1034 |
summary, error = _run_batch_in_subprocess(
|
| 1035 |
+
ai_dir=ai_dir, out_dir=engine_out, tie_path=tie_path,
|
| 1036 |
email=bna_email, password=bna_password,
|
| 1037 |
lang=lang, log_box=log_box, progress_callback=_progress_cb,
|
| 1038 |
)
|
|
|
|
| 1041 |
ss.run_status = "error"
|
| 1042 |
ss.run_error_msg = error
|
| 1043 |
else:
|
| 1044 |
+
# Move ALL engine artifacts (per-project comparison
|
| 1045 |
+
# ZIPs + batch_summary_*.xlsx) into Summary/ so the
|
| 1046 |
+
# researcher's downloaded ZIP keeps Input/ and Output/
|
| 1047 |
+
# exactly as they uploaded them.
|
| 1048 |
try:
|
| 1049 |
+
for f in engine_out.iterdir():
|
| 1050 |
+
try:
|
| 1051 |
+
f.replace(summary_dir / f.name)
|
| 1052 |
+
except Exception:
|
| 1053 |
+
pass
|
| 1054 |
except Exception:
|
| 1055 |
pass
|
|
|
|
|
|
|
|
|
|
| 1056 |
zip_bytes = _zip_directory(staged_root)
|
| 1057 |
ss.last_zip_bytes = zip_bytes
|
| 1058 |
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
|