jeffrey1963 commited on
Commit
409c1a5
·
verified ·
1 Parent(s): 8dcc7c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -16
app.py CHANGED
@@ -240,33 +240,28 @@ def handle_docx(file):
240
  # (df_norm if df_norm is not None else pd.DataFrame()),
241
  # )
242
 
243
-
244
-
245
  def handle_image(img):
246
  if img is None:
247
- # Always return DataFrames, never None
248
- empty = pd.DataFrame()
249
- return "(no image)", {}, empty, empty, 0.0, 0.0, 10, pd.Timestamp.now().year, {}, empty
250
 
251
  from PIL import Image as PILImage
252
  pil = img if isinstance(img, PILImage.Image) else PILImage.fromarray(img)
253
 
254
- ocr_text = _image_to_text(pil) or ""
255
- params = _extract_params(ocr_text)
256
- df_raw = _table_from_ocr_text(ocr_text) or pd.DataFrame() # ← coerce None → DF
257
- df_norm = _normalize_depr_columns(df_raw) if not df_raw.empty else pd.DataFrame()
258
 
259
  cost, salv, life, year = _params_tuple(params)
260
 
261
- # Return exactly what the UI expects, and store norm into last_table
262
  return (
263
- (ocr_text if ocr_text.strip() else "(empty OCR)"),
264
- params,
265
- df_raw,
266
- df_norm,
267
- cost, salv, life, year,
268
  params,
269
- df_norm # last_table state
 
 
 
 
270
  )
271
 
272
 
 
240
  # (df_norm if df_norm is not None else pd.DataFrame()),
241
  # )
242
 
 
 
243
  def handle_image(img):
244
  if img is None:
245
+ return "(no image)", {}, pd.DataFrame(), pd.DataFrame(), 0.0, 0.0, 10, pd.Timestamp.now().year, {}, pd.DataFrame()
 
 
246
 
247
  from PIL import Image as PILImage
248
  pil = img if isinstance(img, PILImage.Image) else PILImage.fromarray(img)
249
 
250
+ ocr_text = _image_to_text(pil)
251
+ params = _extract_params(ocr_text or "")
252
+ df_raw = _table_from_ocr_text(ocr_text or "")
253
+ df_norm = _normalize_depr_columns(df_raw) if df_raw is not None else pd.DataFrame()
254
 
255
  cost, salv, life, year = _params_tuple(params)
256
 
 
257
  return (
258
+ ocr_text or "(empty OCR)",
 
 
 
 
259
  params,
260
+ df_raw, # raw table shown in OCR tab
261
+ df_norm, # normalized table shown in OCR tab
262
+ cost, salv, life, year, # auto-fill numbers
263
+ params, # save params state
264
+ df_norm # 🔹 save normalized table to last_table (same as docx)
265
  )
266
 
267