Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,6 +71,34 @@ def analyze_uv_coverage(img, brightness_threshold=150, kernel_size=5, apply_blur
|
|
| 71 |
annotated_img = cv2.addWeighted(img, 0.6, overlay, 0.4, 0)
|
| 72 |
return annotated_img, coverage_percent
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
def save_record_to_salesforce(annotated_image_url, coverage_percent, original_image_pil, compliance_threshold=80):
|
| 75 |
sf = Salesforce(
|
| 76 |
username=os.getenv('SF_USERNAME'),
|
|
|
|
| 71 |
annotated_img = cv2.addWeighted(img, 0.6, overlay, 0.4, 0)
|
| 72 |
return annotated_img, coverage_percent
|
| 73 |
|
| 74 |
+
def create_pdf_report(coverage_percent, extracted_texts, annotated_image_path, output_path):
|
| 75 |
+
pdf = FPDF()
|
| 76 |
+
pdf.add_page()
|
| 77 |
+
|
| 78 |
+
pdf.set_font("Arial", 'B', 16)
|
| 79 |
+
pdf.cell(200, 10, txt="UV Sterilization Report", ln=True, align='C')
|
| 80 |
+
pdf.ln(10)
|
| 81 |
+
|
| 82 |
+
pdf.set_font("Arial", size=12)
|
| 83 |
+
pdf.cell(0, 10, f"Sterilization Coverage: {coverage_percent:.2f}%", ln=True)
|
| 84 |
+
pdf.ln(5)
|
| 85 |
+
|
| 86 |
+
pdf.cell(0, 10, "Extracted Text from Image (OCR):", ln=True)
|
| 87 |
+
pdf.set_font("Arial", size=10)
|
| 88 |
+
if extracted_texts:
|
| 89 |
+
for text in extracted_texts:
|
| 90 |
+
# Filter out very short or empty OCR texts to improve clarity
|
| 91 |
+
if len(text.strip()) > 1:
|
| 92 |
+
pdf.multi_cell(0, 8, f"- {text}")
|
| 93 |
+
else:
|
| 94 |
+
pdf.cell(0, 8, "No text detected.", ln=True)
|
| 95 |
+
|
| 96 |
+
pdf.ln(10)
|
| 97 |
+
pdf.cell(0, 10, "Annotated Image:", ln=True)
|
| 98 |
+
pdf.image(annotated_image_path, x=10, y=pdf.get_y(), w=pdf.w - 20)
|
| 99 |
+
|
| 100 |
+
pdf.output(output_path)
|
| 101 |
+
|
| 102 |
def save_record_to_salesforce(annotated_image_url, coverage_percent, original_image_pil, compliance_threshold=80):
|
| 103 |
sf = Salesforce(
|
| 104 |
username=os.getenv('SF_USERNAME'),
|