jeffrey1963 commited on
Commit
b9c537c
·
verified ·
1 Parent(s): 65de223

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -17
app.py CHANGED
@@ -256,34 +256,25 @@ 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_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 not isinstance(actual, pd.DataFrame) or actual.empty:
270
  return pd.DataFrame(), "No student table found to check."
271
 
272
- # 🔧 CRUCIAL: Re-normalize & force numerics because Gradio returns strings
273
- actual = _normalize_depr_columns(actual)
274
- for c in ["Year","Begin BV","Depreciation","Accum Dep","End BV"]:
275
  actual[c] = pd.to_numeric(actual[c], errors="coerce")
276
  actual = actual.dropna(subset=["Year"]).reset_index(drop=True)
277
 
278
- # Ensure exp Year is numeric too
279
- exp["Year"] = pd.to_numeric(exp["Year"], errors="coerce")
280
-
281
  deltas, msg = audit_against_expected(exp, actual)
282
  return deltas, msg
283
 
284
 
285
-
286
-
287
  # ---------- UI ----------
288
  with gr.Blocks(title="Jerry • HW Intake (Echo)") as demo:
289
  last_params = gr.State({})
 
256
  return pd.DataFrame([{"error": str(e)}])
257
  return df
258
 
259
+ def check_cb(cost, salv, life, year, table_state):
260
+ # expected (numeric)
261
  exp = build_sl_schedule(float(cost), float(salv), int(life), int(year))
262
+ exp["Year"] = pd.to_numeric(exp["Year"], errors="coerce")
263
 
264
+ # nothing to check?
265
+ if not isinstance(table_state, pd.DataFrame) or table_state.empty:
 
 
 
 
 
 
266
  return pd.DataFrame(), "No student table found to check."
267
 
268
+ # 👇 Gradio returns strings re-normalize and coerce here every time
269
+ actual = _normalize_depr_columns(table_state)
270
+ for c in ["Year", "Begin BV", "Depreciation", "Accum Dep", "End BV"]:
271
  actual[c] = pd.to_numeric(actual[c], errors="coerce")
272
  actual = actual.dropna(subset=["Year"]).reset_index(drop=True)
273
 
 
 
 
274
  deltas, msg = audit_against_expected(exp, actual)
275
  return deltas, msg
276
 
277
 
 
 
278
  # ---------- UI ----------
279
  with gr.Blocks(title="Jerry • HW Intake (Echo)") as demo:
280
  last_params = gr.State({})