Update legal_document_analysis.py
Browse files- legal_document_analysis.py +11 -4
legal_document_analysis.py
CHANGED
@@ -6,7 +6,6 @@ from langchain_groq import ChatGroq
|
|
6 |
from docx import Document
|
7 |
import matplotlib.pyplot as plt
|
8 |
import io
|
9 |
-
import base64
|
10 |
import tempfile
|
11 |
from email.mime.multipart import MIMEMultipart
|
12 |
from email.mime.text import MIMEText
|
@@ -369,7 +368,11 @@ def generate_pdf_analysis(document_text, summary, detected_clauses, hidden_oblig
|
|
369 |
pdf.set_font("Arial", 'I', 8)
|
370 |
pdf.cell(0, 10, f'Page {pdf.page_no()}', 0, 0, 'C')
|
371 |
|
372 |
-
|
|
|
|
|
|
|
|
|
373 |
|
374 |
# Function to handle chatbot interaction
|
375 |
def chatbot_query(user_input):
|
@@ -572,9 +575,13 @@ def display_legal_analysis_page():
|
|
572 |
|
573 |
# Download PDF Analysis Button
|
574 |
st.subheader("Download Analysis as PDF")
|
|
|
|
|
|
|
575 |
pdf_buffer = io.BytesIO()
|
576 |
-
|
577 |
-
|
|
|
578 |
pdf_buffer.seek(0)
|
579 |
|
580 |
# Add download button for PDF
|
|
|
6 |
from docx import Document
|
7 |
import matplotlib.pyplot as plt
|
8 |
import io
|
|
|
9 |
import tempfile
|
10 |
from email.mime.multipart import MIMEMultipart
|
11 |
from email.mime.text import MIMEText
|
|
|
368 |
pdf.set_font("Arial", 'I', 8)
|
369 |
pdf.cell(0, 10, f'Page {pdf.page_no()}', 0, 0, 'C')
|
370 |
|
371 |
+
# Save the PDF to a temporary file
|
372 |
+
pdf_file_path = tempfile.mktemp(suffix=".pdf")
|
373 |
+
pdf.output(pdf_file_path, 'F')
|
374 |
+
|
375 |
+
return pdf_file_path # Return the path to the saved PDF
|
376 |
|
377 |
# Function to handle chatbot interaction
|
378 |
def chatbot_query(user_input):
|
|
|
575 |
|
576 |
# Download PDF Analysis Button
|
577 |
st.subheader("Download Analysis as PDF")
|
578 |
+
pdf_file_path = generate_pdf_analysis(document_text, summary, detected_clauses, hidden_obligations, detected_risks, risk_assessment_matrix_path, risk_level_distribution_path, risks_by_type_path, stacked_bar_chart_path, risk_heatmap_path)
|
579 |
+
|
580 |
+
# Read PDF into BytesIO for download
|
581 |
pdf_buffer = io.BytesIO()
|
582 |
+
with open(pdf_file_path, 'rb') as f:
|
583 |
+
pdf_buffer.write(f.read())
|
584 |
+
|
585 |
pdf_buffer.seek(0)
|
586 |
|
587 |
# Add download button for PDF
|