Update legal_document_analysis.py
Browse files- legal_document_analysis.py +19 -9
legal_document_analysis.py
CHANGED
@@ -372,16 +372,26 @@ def generate_pdf_analysis(document_text, summary, detected_clauses, hidden_oblig
|
|
372 |
pdf.cell(0, 10, f"{risk['phrase']}: {risk['summary']} (Risk Level: {risk['risk_level']})", ln=True)
|
373 |
pdf.ln(10)
|
374 |
|
375 |
-
#
|
376 |
-
|
377 |
-
|
378 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
379 |
|
380 |
-
|
381 |
-
|
382 |
-
|
|
|
|
|
383 |
|
384 |
-
pdf.image(base64_to_image(risk_heatmap), x=10, y=pdf.get_y(), w=190) # Fit image to width
|
385 |
pdf.ln(10)
|
386 |
|
387 |
# Footer
|
@@ -456,7 +466,7 @@ def send_pdf_via_email(pdf_buffer, recipient_email):
|
|
456 |
pdf_buffer.seek(0)
|
457 |
pdf_attachment.write(pdf_buffer.read())
|
458 |
pdf_attachment.seek(0)
|
459 |
-
|
460 |
part = MIMEApplication(pdf_attachment.read(), Name='legal_document_analysis.pdf')
|
461 |
part['Content-Disposition'] = 'attachment; filename="legal_document_analysis.pdf"'
|
462 |
msg.attach(part)
|
|
|
372 |
pdf.cell(0, 10, f"{risk['phrase']}: {risk['summary']} (Risk Level: {risk['risk_level']})", ln=True)
|
373 |
pdf.ln(10)
|
374 |
|
375 |
+
# Save images temporarily and add them to the PDF
|
376 |
+
def save_base64_image(image_str, filename):
|
377 |
+
with open(filename, "wb") as img_file:
|
378 |
+
img_file.write(base64.b64decode(image_str))
|
379 |
+
|
380 |
+
# Save images
|
381 |
+
image_filenames = [
|
382 |
+
"risk_assessment_matrix.png",
|
383 |
+
"risk_level_distribution.png",
|
384 |
+
"risks_by_type.png",
|
385 |
+
"stacked_bar_chart.png",
|
386 |
+
"risk_heatmap.png"
|
387 |
+
]
|
388 |
|
389 |
+
images = [risk_assessment_matrix, risk_level_distribution, risks_by_type, stacked_bar_chart, risk_heatmap]
|
390 |
+
|
391 |
+
for img_str, filename in zip(images, image_filenames):
|
392 |
+
save_base64_image(img_str, filename)
|
393 |
+
pdf.image(filename, x=10, y=pdf.get_y(), w=90) # Use the saved image file
|
394 |
|
|
|
395 |
pdf.ln(10)
|
396 |
|
397 |
# Footer
|
|
|
466 |
pdf_buffer.seek(0)
|
467 |
pdf_attachment.write(pdf_buffer.read())
|
468 |
pdf_attachment.seek(0)
|
469 |
+
|
470 |
part = MIMEApplication(pdf_attachment.read(), Name='legal_document_analysis.pdf')
|
471 |
part['Content-Disposition'] = 'attachment; filename="legal_document_analysis.pdf"'
|
472 |
msg.attach(part)
|