pavansuresh commited on
Commit
32d99a2
·
verified ·
1 Parent(s): 3f4d43c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -68,24 +68,21 @@ def process_image(input_img, brightness_threshold=150):
68
  cv2.imwrite(temp_img_file.name, annotated_img)
69
 
70
  # Save PDF report temporarily
71
- with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as temp_pdf_file:
72
- create_pdf_report(coverage_percent, extracted_texts, temp_img_file.name, temp_pdf_file.name)
73
-
74
- # Read PDF bytes for download
75
- with open(temp_pdf_file.name, "rb") as f:
76
- pdf_bytes = f.read()
77
 
78
  # Convert annotated image back to RGB for display
79
  annotated_img_rgb = cv2.cvtColor(annotated_img, cv2.COLOR_BGR2RGB)
80
 
81
- # Clean up temp files
82
- os.unlink(temp_img_file.name)
83
- os.unlink(temp_pdf_file.name)
84
-
85
  report_text = f"UV Sterilization Coverage: {coverage_percent:.2f}%\n\nExtracted Texts:\n"
86
  report_text += "\n".join(extracted_texts) if extracted_texts else "No text detected."
87
 
88
- return annotated_img_rgb, report_text, pdf_bytes
 
 
 
 
89
 
90
  iface = gr.Interface(
91
  fn=process_image,
 
68
  cv2.imwrite(temp_img_file.name, annotated_img)
69
 
70
  # Save PDF report temporarily
71
+ temp_pdf_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
72
+ temp_pdf_file.close() # Close so FPDF can write to it
73
+ create_pdf_report(coverage_percent, extracted_texts, temp_img_file.name, temp_pdf_file.name)
 
 
 
74
 
75
  # Convert annotated image back to RGB for display
76
  annotated_img_rgb = cv2.cvtColor(annotated_img, cv2.COLOR_BGR2RGB)
77
 
 
 
 
 
78
  report_text = f"UV Sterilization Coverage: {coverage_percent:.2f}%\n\nExtracted Texts:\n"
79
  report_text += "\n".join(extracted_texts) if extracted_texts else "No text detected."
80
 
81
+ # Delete annotated image file to avoid temp buildup
82
+ os.unlink(temp_img_file.name)
83
+
84
+ # Return annotated image, report text, and PDF file path
85
+ return annotated_img_rgb, report_text, temp_pdf_file.name
86
 
87
  iface = gr.Interface(
88
  fn=process_image,