Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -250,49 +250,49 @@ with gr.Blocks(title="Jerry • HW Intake (Echo)") as demo:
|
|
| 250 |
norm_df = gr.Dataframe(label="Detected table (normalized)", interactive=False)
|
| 251 |
btn2.click(handle_image, inputs=img_in, outputs=[ocr_txt, params_json2, raw_df, norm_df])
|
| 252 |
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
|
| 297 |
# When params state changes, prefill inputs
|
| 298 |
last_params.change(lambda p: fill_from_state(p), inputs=last_params,
|
|
|
|
| 250 |
norm_df = gr.Dataframe(label="Detected table (normalized)", interactive=False)
|
| 251 |
btn2.click(handle_image, inputs=img_in, outputs=[ocr_txt, params_json2, raw_df, norm_df])
|
| 252 |
|
| 253 |
+
with gr.Tab("Straight-Line • Solve & Check"):
|
| 254 |
+
gr.Markdown("Enter params (auto-filled if detected) → build the correct SL schedule → compare to your uploaded table.")
|
| 255 |
+
with gr.Row():
|
| 256 |
+
in_cost = gr.Number(label="Cost", value=0.0)
|
| 257 |
+
in_salv = gr.Number(label="Salvage", value=0.0)
|
| 258 |
+
in_life = gr.Number(label="Life (years)", value=10, precision=0)
|
| 259 |
+
in_year = gr.Number(label="Start year", value=2025, precision=0)
|
| 260 |
+
btn_build = gr.Button("Build expected schedule")
|
| 261 |
+
expected_df = gr.Dataframe(label="Expected (SL) schedule", interactive=False)
|
| 262 |
+
btn_check = gr.Button("Check against uploaded table")
|
| 263 |
+
deltas_df = gr.Dataframe(label="Differences (student − expected)", interactive=False)
|
| 264 |
+
coach_txt = gr.Markdown()
|
| 265 |
+
|
| 266 |
+
def fill_from_state(p):
|
| 267 |
+
# prefill controls when we have parsed params
|
| 268 |
+
p = p or {}
|
| 269 |
+
return (
|
| 270 |
+
p.get("cost", 0.0),
|
| 271 |
+
p.get("salvage", 0.0),
|
| 272 |
+
p.get("life", 10),
|
| 273 |
+
p.get("start_year", pd.Timestamp.now().year),
|
| 274 |
+
)
|
| 275 |
+
|
| 276 |
+
def build_cb(cost, salv, life, year):
|
| 277 |
+
try:
|
| 278 |
+
df = build_sl_schedule(float(cost), float(salv), int(life), int(year))
|
| 279 |
+
except Exception as e:
|
| 280 |
+
return pd.DataFrame([{"error": str(e)}])
|
| 281 |
+
return df
|
| 282 |
+
|
| 283 |
+
def check_cb(cost, salv, life, year, table):
|
| 284 |
+
exp = build_sl_schedule(float(cost), float(salv), int(life), int(year))
|
| 285 |
+
deltas, msg = audit_against_expected(exp, table if isinstance(table, pd.DataFrame) else pd.DataFrame())
|
| 286 |
+
return deltas, msg
|
| 287 |
+
|
| 288 |
+
# Wire up
|
| 289 |
+
btn_build.click(build_cb, [in_cost, in_salv, in_life, in_year], [expected_df])
|
| 290 |
+
btn_check.click(check_cb, [in_cost, in_salv, in_life, in_year, last_table], [deltas_df, coach_txt])
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
|
| 296 |
|
| 297 |
# When params state changes, prefill inputs
|
| 298 |
last_params.change(lambda p: fill_from_state(p), inputs=last_params,
|