jeffrey1963 commited on
Commit
6321be3
·
verified ·
1 Parent(s): 0eff467

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -3
app.py CHANGED
@@ -256,11 +256,27 @@ def build_cb(cost, salv, life, year):
256
  return pd.DataFrame([{"error": str(e)}])
257
  return df
258
 
259
- def check_cb(cost, salv, life, year, table):
260
  exp = build_sl_schedule(float(cost), float(salv), int(life), int(year))
261
- deltas, msg = audit_against_expected(exp, table if isinstance(table, pd.DataFrame) else pd.DataFrame())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  return deltas, msg
263
 
 
 
264
  # ---------- UI ----------
265
  with gr.Blocks(title="Jerry • HW Intake (Echo)") as demo:
266
  last_params = gr.State({})
@@ -328,7 +344,13 @@ with gr.Blocks(title="Jerry • HW Intake (Echo)") as demo:
328
  ],
329
  )
330
 
331
- btn_use.click(fill_from_state, inputs=last_params, outputs=[in_cost, in_salv, in_life, in_year])
 
 
 
 
 
 
332
  btn_build.click(build_cb, [in_cost, in_salv, in_life, in_year], [expected_df])
333
  btn_check.click(check_cb, [in_cost, in_salv, in_life, in_year, last_table], [deltas_df, coach_txt])
334
 
 
256
  return pd.DataFrame([{"error": str(e)}])
257
  return df
258
 
259
+ def check_cb(cost, salv, life, year, table_docx, table_img):
260
  exp = build_sl_schedule(float(cost), float(salv), int(life), int(year))
261
+
262
+ # prefer the image-normalized table if present, else the docx table
263
+ actual = None
264
+ for t in (table_img, table_docx):
265
+ if isinstance(t, pd.DataFrame) and not t.empty:
266
+ actual = t.copy()
267
+ break
268
+
269
+ # if columns aren't standardized yet, normalize them
270
+ if isinstance(actual, pd.DataFrame) and not actual.empty:
271
+ needed = {"Year","Begin BV","Depreciation","Accum Dep","End BV"}
272
+ if not needed.issubset(set(actual.columns)):
273
+ actual = _normalize_depr_columns(actual)
274
+
275
+ deltas, msg = audit_against_expected(exp, actual if isinstance(actual, pd.DataFrame) else pd.DataFrame())
276
  return deltas, msg
277
 
278
+
279
+
280
  # ---------- UI ----------
281
  with gr.Blocks(title="Jerry • HW Intake (Echo)") as demo:
282
  last_params = gr.State({})
 
344
  ],
345
  )
346
 
347
+ # btn_use.click(fill_from_state, inputs=last_params, outputs=[in_cost, in_salv, in_life, in_year])
348
+ btn_check.click(
349
+ check_cb,
350
+ [in_cost, in_salv, in_life, in_year, table_df, norm_df], # <- pass both tables
351
+ [deltas_df, coach_txt]
352
+ )
353
+
354
  btn_build.click(build_cb, [in_cost, in_salv, in_life, in_year], [expected_df])
355
  btn_check.click(check_cb, [in_cost, in_salv, in_life, in_year, last_table], [deltas_df, coach_txt])
356