GopiBNA commited on
Commit
d024be9
·
verified ·
1 Parent(s): 444bdff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -20
app.py CHANGED
@@ -496,17 +496,22 @@ def _stage_zip(upload, into_dir: Path) -> Path:
496
  except Exception:
497
  pass
498
 
499
- # --- 7) Input/ must have at least one Excel file -------------------
 
 
 
500
  excels = []
501
  for ext in (".xlsx", ".xls", ".xlsm"):
502
- excels.extend(input_dir.rglob(f"*{ext}"))
503
  excels = [p for p in excels if not p.name.startswith("~$")]
504
  if not excels:
505
  _validation_error(
506
- "The Input/ folder is empty",
507
- "Your ZIP has the right structure, but <code>Input/</code> "
508
- "contains no Excel files. Put your AI Excels (<code>.xlsx</code>) "
509
- "into the Input folder, re-zip, and upload again.",
 
 
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/`** (your AI Excels) · "
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
- ai_dir = Path(layout["input"])
1015
- out_dir = Path(layout["output"])
 
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=out_dir, tie_path=tie_path,
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 the batch summary xlsx (written into out_dir by
1033
- # batch_runner) into Summary/ so the researcher's ZIP
1034
- # layout stays clean.
 
1035
  try:
1036
- for f in out_dir.glob("batch_summary_*.xlsx"):
1037
- f.replace(summary_dir / f.name)
 
 
 
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")