Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -320,6 +320,39 @@ def check_cb(cost, salv, life, year, table_state):
|
|
| 320 |
deltas, msg = audit_against_expected(exp, actual)
|
| 321 |
return deltas, msg
|
| 322 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
# ---------- UI ----------
|
| 324 |
with gr.Blocks(title="Jerry • HW Intake (Echo)") as demo:
|
| 325 |
last_params = gr.State({})
|
|
@@ -359,6 +392,20 @@ with gr.Blocks(title="Jerry • HW Intake (Echo)") as demo:
|
|
| 359 |
deltas_df = gr.Dataframe(label="Differences (student − expected)", interactive=False)
|
| 360 |
coach_txt = gr.Markdown()
|
| 361 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
# ---------- Wire events AFTER all components exist ----------
|
| 363 |
btn1.click(
|
| 364 |
handle_docx,
|
|
@@ -391,6 +438,14 @@ with gr.Blocks(title="Jerry • HW Intake (Echo)") as demo:
|
|
| 391 |
btn_build.click(build_cb, [in_cost, in_salv, in_life, in_year], [expected_df])
|
| 392 |
btn_check.click(check_cb, [in_cost, in_salv, in_life, in_year, last_table], [deltas_df, coach_txt])
|
| 393 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
gr.Markdown("— Echo mode finished. When this looks good, we’ll plug in the SL solver + coaching.")
|
| 395 |
|
| 396 |
if __name__ == "__main__":
|
|
|
|
| 320 |
deltas, msg = audit_against_expected(exp, actual)
|
| 321 |
return deltas, msg
|
| 322 |
|
| 323 |
+
# --- Debug utilities ---
|
| 324 |
+
def debug_dump(ocr_text, params, raw_tbl, norm_tbl, last_tbl, image):
|
| 325 |
+
import pandas as pd, io
|
| 326 |
+
|
| 327 |
+
def df_summary(name, df):
|
| 328 |
+
if isinstance(df, pd.DataFrame) and not df.empty:
|
| 329 |
+
head = df.head(5).to_string(index=False)
|
| 330 |
+
return f"**{name}**: shape={df.shape}, cols={list(df.columns)}\n```\n{head}\n```"
|
| 331 |
+
return f"**{name}**: {type(df).__name__} (empty or not a DataFrame)"
|
| 332 |
+
|
| 333 |
+
lines = []
|
| 334 |
+
lines.append(f"**OCR text length**: {len(ocr_text or '')}")
|
| 335 |
+
lines.append(f"**Params keys**: {sorted(list((params or {}).keys()))}")
|
| 336 |
+
lines.append(df_summary("raw_df (Tab 2)", raw_tbl))
|
| 337 |
+
lines.append(df_summary("norm_df (Tab 2)", norm_tbl))
|
| 338 |
+
lines.append(df_summary("last_table (State)", last_tbl))
|
| 339 |
+
report = "\n\n".join(lines)
|
| 340 |
+
|
| 341 |
+
# Return the report and echoes of the DFs and image for visual confirmation
|
| 342 |
+
# (use empty DataFrames if inputs aren't DataFrames)
|
| 343 |
+
def ensure_df(x):
|
| 344 |
+
return x if isinstance(x, pd.DataFrame) else pd.DataFrame()
|
| 345 |
+
|
| 346 |
+
return (
|
| 347 |
+
report,
|
| 348 |
+
ensure_df(raw_tbl),
|
| 349 |
+
ensure_df(norm_tbl),
|
| 350 |
+
ensure_df(last_tbl),
|
| 351 |
+
image # echo the image
|
| 352 |
+
)
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
|
| 356 |
# ---------- UI ----------
|
| 357 |
with gr.Blocks(title="Jerry • HW Intake (Echo)") as demo:
|
| 358 |
last_params = gr.State({})
|
|
|
|
| 392 |
deltas_df = gr.Dataframe(label="Differences (student − expected)", interactive=False)
|
| 393 |
coach_txt = gr.Markdown()
|
| 394 |
|
| 395 |
+
with gr.Tab("Debug"):
|
| 396 |
+
dbg_btn = gr.Button("Dump OCR state")
|
| 397 |
+
dbg_md = gr.Markdown()
|
| 398 |
+
dbg_raw = gr.Dataframe(label="raw_df echo", interactive=False)
|
| 399 |
+
dbg_norm = gr.Dataframe(label="norm_df echo", interactive=False)
|
| 400 |
+
dbg_last = gr.Dataframe(label="last_table (State) echo", interactive=False)
|
| 401 |
+
dbg_img = gr.Image(label="Image echo")
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
|
| 409 |
# ---------- Wire events AFTER all components exist ----------
|
| 410 |
btn1.click(
|
| 411 |
handle_docx,
|
|
|
|
| 438 |
btn_build.click(build_cb, [in_cost, in_salv, in_life, in_year], [expected_df])
|
| 439 |
btn_check.click(check_cb, [in_cost, in_salv, in_life, in_year, last_table], [deltas_df, coach_txt])
|
| 440 |
|
| 441 |
+
|
| 442 |
+
dbg_btn.click(
|
| 443 |
+
debug_dump,
|
| 444 |
+
# inputs come from the components/state already populated by handle_image
|
| 445 |
+
inputs=[ocr_txt, params_json2, raw_df, norm_df, last_table, img_in],
|
| 446 |
+
outputs=[dbg_md, dbg_raw, dbg_norm, dbg_last, dbg_img],
|
| 447 |
+
)
|
| 448 |
+
|
| 449 |
gr.Markdown("— Echo mode finished. When this looks good, we’ll plug in the SL solver + coaching.")
|
| 450 |
|
| 451 |
if __name__ == "__main__":
|