github-actions[bot] commited on
Commit
7b7afd3
·
1 Parent(s): 060dc2a

Sync from GitHub: c53fa41ee77ecd3146256db14b6ffe13f033cd54

Browse files
Files changed (1) hide show
  1. app.py +37 -4
app.py CHANGED
@@ -240,13 +240,46 @@ async def process_invoice(
240
  # Process invoice
241
  result = InferenceProcessor.process_invoice(temp_file, doc_id)
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  # Return simplified response matching frontend expectations
244
  return JSONResponse(content={
245
- "extracted_text": result.get("extracted_text", ""),
246
- "signature_coords": result.get("signature_coords", []),
247
- "stamp_coords": result.get("stamp_coords", []),
248
  "doc_id": result.get("doc_id", doc_id),
249
- "processing_time": result.get("processing_time_sec", 0)
 
 
250
  }, media_type="application/json; charset=utf-8")
251
 
252
  except Exception as e:
 
240
  # Process invoice
241
  result = InferenceProcessor.process_invoice(temp_file, doc_id)
242
 
243
+ # Extract fields from result
244
+ fields = result.get("fields", {})
245
+ signature_info = fields.get("signature", {})
246
+ stamp_info = fields.get("stamp", {})
247
+
248
+ # Build text representation of extracted fields
249
+ extracted_text_parts = []
250
+ if fields.get("dealer_name"):
251
+ extracted_text_parts.append(f"Dealer Name: {fields['dealer_name']}")
252
+ if fields.get("model_name"):
253
+ extracted_text_parts.append(f"Model Name: {fields['model_name']}")
254
+ if fields.get("horse_power"):
255
+ extracted_text_parts.append(f"Horse Power: {fields['horse_power']}")
256
+ if fields.get("asset_cost"):
257
+ extracted_text_parts.append(f"Asset Cost: {fields['asset_cost']}")
258
+
259
+ extracted_text = "\n".join(extracted_text_parts) if extracted_text_parts else "No structured data extracted"
260
+
261
+ # Get coordinates
262
+ signature_coords = []
263
+ if signature_info.get("present") and signature_info.get("bbox"):
264
+ bbox = signature_info["bbox"]
265
+ # Convert [x1, y1, x2, y2] format
266
+ signature_coords = [[bbox[0], bbox[1], bbox[2], bbox[3]]]
267
+
268
+ stamp_coords = []
269
+ if stamp_info.get("present") and stamp_info.get("bbox"):
270
+ bbox = stamp_info["bbox"]
271
+ # Convert [x1, y1, x2, y2] format
272
+ stamp_coords = [[bbox[0], bbox[1], bbox[2], bbox[3]]]
273
+
274
  # Return simplified response matching frontend expectations
275
  return JSONResponse(content={
276
+ "extracted_text": extracted_text,
277
+ "signature_coords": signature_coords,
278
+ "stamp_coords": stamp_coords,
279
  "doc_id": result.get("doc_id", doc_id),
280
+ "processing_time": result.get("processing_time_sec", 0),
281
+ "confidence": result.get("confidence", 0),
282
+ "fields": fields # Include raw fields for reference
283
  }, media_type="application/json; charset=utf-8")
284
 
285
  except Exception as e: