vettri06 commited on
Commit
6cb7a4a
·
1 Parent(s): 68247ea

Harden analysis result rendering

Browse files
doc_intelligence/src/app/streamlit_app.py CHANGED
@@ -485,6 +485,7 @@ with tab_extract:
485
  "then restart the Space and try again."
486
  )
487
  pipeline = get_end_to_end_pipeline(model_choice, t1_thresh, t2_thresh, ocr_model_choice)
 
488
  with st.spinner("Processing document layout, extracting tokens with OCR.space, and running classification..."):
489
  computed_result = pipeline.process_document(doc_path, doc_id=doc_id)
490
  st.session_state["analysis_results"][doc_id] = computed_result
@@ -558,7 +559,7 @@ with tab_extract:
558
  {"Category": k.replace("_", " ").title(), "Probability": v}
559
  for k, v in result.get("class_probabilities", {}).items()
560
  ])
561
- st.bar_chart(probs_df.set_index("Category"), height=110)
562
 
563
  # Routing Decision Panel
564
  if result["needs_review"]:
@@ -598,11 +599,10 @@ with tab_extract:
598
  })
599
 
600
  df_extracted = pd.DataFrame(fields_data)
601
- edited_df = st.data_editor(
602
  df_extracted[["Field Name", "Extracted Value", "Confidence"]],
603
- width="stretch",
604
- num_rows="dynamic",
605
- key="editor_fields"
606
  )
607
 
608
  # Export & Download Actions
 
485
  "then restart the Space and try again."
486
  )
487
  pipeline = get_end_to_end_pipeline(model_choice, t1_thresh, t2_thresh, ocr_model_choice)
488
+ print(f"[ANALYSIS] {doc_id}: request accepted", flush=True)
489
  with st.spinner("Processing document layout, extracting tokens with OCR.space, and running classification..."):
490
  computed_result = pipeline.process_document(doc_path, doc_id=doc_id)
491
  st.session_state["analysis_results"][doc_id] = computed_result
 
559
  {"Category": k.replace("_", " ").title(), "Probability": v}
560
  for k, v in result.get("class_probabilities", {}).items()
561
  ])
562
+ st.dataframe(probs_df, width="stretch", hide_index=True)
563
 
564
  # Routing Decision Panel
565
  if result["needs_review"]:
 
599
  })
600
 
601
  df_extracted = pd.DataFrame(fields_data)
602
+ st.dataframe(
603
  df_extracted[["Field Name", "Extracted Value", "Confidence"]],
604
+ width="stretch",
605
+ hide_index=True
 
606
  )
607
 
608
  # Export & Download Actions
doc_intelligence/src/pipeline/end_to_end.py CHANGED
@@ -37,7 +37,9 @@ class DocumentIntelligencePipeline:
37
  t0 = time.time()
38
 
39
  # 1. OCR (with optional preprocessing)
 
40
  ocr_words, _ = self.ocr_engine.extract_with_cache(image_or_pdf_path, doc_id=doc_id)
 
41
 
42
  # Build DocumentRecord for inference
43
  doc_rec = DocumentRecord(
@@ -55,6 +57,7 @@ class DocumentIntelligencePipeline:
55
  predicted_class = self.classifier.classes_[class_idx]
56
  class_confidence = float(class_probs[class_idx])
57
  class_probabilities = {c: round(float(p), 4) for c, p in zip(self.classifier.classes_, class_probs)}
 
58
 
59
  # 3. Stage 2: Class-specific Field Extraction
60
  extractor = self.extractors.get(predicted_class)
@@ -67,6 +70,7 @@ class DocumentIntelligencePipeline:
67
  raw_fields = extractor.extract(doc_rec)
68
  else:
69
  raw_fields = {}
 
70
 
71
  # 4. Post-processing & Business Validation
72
  normalized_fields, validation_res = postprocess_extracted_fields(predicted_class, raw_fields)
 
37
  t0 = time.time()
38
 
39
  # 1. OCR (with optional preprocessing)
40
+ print(f"[ANALYSIS] {doc_id}: OCR started", flush=True)
41
  ocr_words, _ = self.ocr_engine.extract_with_cache(image_or_pdf_path, doc_id=doc_id)
42
+ print(f"[ANALYSIS] {doc_id}: OCR completed with {len(ocr_words)} words", flush=True)
43
 
44
  # Build DocumentRecord for inference
45
  doc_rec = DocumentRecord(
 
57
  predicted_class = self.classifier.classes_[class_idx]
58
  class_confidence = float(class_probs[class_idx])
59
  class_probabilities = {c: round(float(p), 4) for c, p in zip(self.classifier.classes_, class_probs)}
60
+ print(f"[ANALYSIS] {doc_id}: classified as {predicted_class}", flush=True)
61
 
62
  # 3. Stage 2: Class-specific Field Extraction
63
  extractor = self.extractors.get(predicted_class)
 
70
  raw_fields = extractor.extract(doc_rec)
71
  else:
72
  raw_fields = {}
73
+ print(f"[ANALYSIS] {doc_id}: field extraction completed", flush=True)
74
 
75
  # 4. Post-processing & Business Validation
76
  normalized_fields, validation_res = postprocess_extracted_fields(predicted_class, raw_fields)