Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -220,26 +220,52 @@ def handle_docx(file):
|
|
| 220 |
(df_norm if df_norm is not None else pd.DataFrame()),
|
| 221 |
)
|
| 222 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
def handle_image(img):
|
| 224 |
if img is None:
|
| 225 |
-
return "(no image)", {},
|
|
|
|
| 226 |
from PIL import Image as PILImage
|
| 227 |
pil = img if isinstance(img, PILImage.Image) else PILImage.fromarray(img)
|
|
|
|
| 228 |
ocr_text = _image_to_text(pil)
|
| 229 |
params = _extract_params(ocr_text or "")
|
| 230 |
df_raw = _table_from_ocr_text(ocr_text or "")
|
| 231 |
-
df_norm = _normalize_depr_columns(df_raw) if df_raw is not None else
|
|
|
|
| 232 |
cost, salv, life, year = _params_tuple(params)
|
|
|
|
| 233 |
return (
|
| 234 |
ocr_text or "(empty OCR)",
|
| 235 |
params,
|
| 236 |
-
df_raw,
|
| 237 |
-
|
| 238 |
-
cost, salv, life, year,
|
| 239 |
-
params,
|
| 240 |
-
|
| 241 |
)
|
| 242 |
|
|
|
|
|
|
|
| 243 |
def fill_from_state(p):
|
| 244 |
p = p or {}
|
| 245 |
return (
|
|
|
|
| 220 |
(df_norm if df_norm is not None else pd.DataFrame()),
|
| 221 |
)
|
| 222 |
|
| 223 |
+
#def handle_image(img):
|
| 224 |
+
# if img is None:
|
| 225 |
+
# return "(no image)", {}, None, pd.DataFrame(), 0.0, 0.0, 10, pd.Timestamp.now().year, {}, pd.DataFrame()
|
| 226 |
+
# from PIL import Image as PILImage
|
| 227 |
+
# pil = img if isinstance(img, PILImage.Image) else PILImage.fromarray(img)
|
| 228 |
+
# ocr_text = _image_to_text(pil)
|
| 229 |
+
# params = _extract_params(ocr_text or "")
|
| 230 |
+
# df_raw = _table_from_ocr_text(ocr_text or "")
|
| 231 |
+
# df_norm = _normalize_depr_columns(df_raw) if df_raw is not None else None
|
| 232 |
+
# cost, salv, life, year = _params_tuple(params)
|
| 233 |
+
# return (
|
| 234 |
+
# ocr_text or "(empty OCR)",
|
| 235 |
+
# params,
|
| 236 |
+
# df_raw,
|
| 237 |
+
# (df_norm if df_norm is not None else pd.DataFrame()),
|
| 238 |
+
# cost, salv, life, year,
|
| 239 |
+
# params,
|
| 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 |
+
|
| 268 |
+
|
| 269 |
def fill_from_state(p):
|
| 270 |
p = p or {}
|
| 271 |
return (
|