Update legal_document_analysis.py
Browse files- legal_document_analysis.py +12 -8
legal_document_analysis.py
CHANGED
|
@@ -394,12 +394,18 @@ def generate_pdf_analysis(document_text, summary, detected_clauses, hidden_oblig
|
|
| 394 |
|
| 395 |
pdf.ln(10)
|
| 396 |
|
| 397 |
-
#
|
| 398 |
-
pdf
|
| 399 |
-
pdf.
|
| 400 |
-
pdf.cell(0, 10, f'Page {pdf.page_no()}', 0, 0, 'C')
|
| 401 |
|
| 402 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
|
| 404 |
# Function to handle chatbot interaction
|
| 405 |
def chatbot_query(user_input):
|
|
@@ -604,9 +610,7 @@ def display_legal_analysis_page():
|
|
| 604 |
|
| 605 |
# Download PDF Analysis Button
|
| 606 |
st.subheader("Download Analysis as PDF")
|
| 607 |
-
pdf_buffer =
|
| 608 |
-
pdf = generate_pdf_analysis(document_text, summary, detected_clauses, hidden_obligations, detected_risks, risk_assessment_matrix, risk_level_distribution, risks_by_type, stacked_bar_chart, risk_heatmap)
|
| 609 |
-
pdf.output(pdf_buffer, 'F')
|
| 610 |
pdf_buffer.seek(0)
|
| 611 |
|
| 612 |
# Add download button for PDF
|
|
|
|
| 394 |
|
| 395 |
pdf.ln(10)
|
| 396 |
|
| 397 |
+
# Save PDF to a temporary file
|
| 398 |
+
temp_pdf_path = "legal_document_analysis.pdf"
|
| 399 |
+
pdf.output(temp_pdf_path, 'F')
|
|
|
|
| 400 |
|
| 401 |
+
# Load the PDF into a BytesIO object
|
| 402 |
+
with open(temp_pdf_path, "rb") as f:
|
| 403 |
+
pdf_buffer = io.BytesIO(f.read())
|
| 404 |
+
|
| 405 |
+
# Optionally, delete the temporary file
|
| 406 |
+
os.remove(temp_pdf_path)
|
| 407 |
+
|
| 408 |
+
return pdf_buffer
|
| 409 |
|
| 410 |
# Function to handle chatbot interaction
|
| 411 |
def chatbot_query(user_input):
|
|
|
|
| 610 |
|
| 611 |
# Download PDF Analysis Button
|
| 612 |
st.subheader("Download Analysis as PDF")
|
| 613 |
+
pdf_buffer = generate_pdf_analysis(document_text, summary, detected_clauses, hidden_obligations, detected_risks, risk_assessment_matrix, risk_level_distribution, risks_by_type, stacked_bar_chart, risk_heatmap)
|
|
|
|
|
|
|
| 614 |
pdf_buffer.seek(0)
|
| 615 |
|
| 616 |
# Add download button for PDF
|