Update legal_document_analysis.py
Browse files- legal_document_analysis.py +6 -51
legal_document_analysis.py
CHANGED
@@ -15,6 +15,7 @@ from fpdf import FPDF
|
|
15 |
import getpass
|
16 |
import pandas as pd
|
17 |
import seaborn as sns
|
|
|
18 |
|
19 |
# Load environment variables from .env file
|
20 |
load_dotenv()
|
@@ -374,56 +375,8 @@ def generate_pdf_analysis(document_text, summary, detected_clauses, hidden_oblig
|
|
374 |
|
375 |
return pdf_file_path # Return the path to the saved PDF
|
376 |
|
377 |
-
#
|
378 |
-
def
|
379 |
-
try:
|
380 |
-
response = model({"text": user_input})
|
381 |
-
if isinstance(response, dict) and 'text' in response:
|
382 |
-
return response['text']
|
383 |
-
else:
|
384 |
-
return "Error: Unexpected response format."
|
385 |
-
except Exception as e:
|
386 |
-
return f"Error: {str(e)}"
|
387 |
-
|
388 |
-
# Function to generate suggestions for improvement
|
389 |
-
def generate_suggestions(text):
|
390 |
-
suggestions = []
|
391 |
-
|
392 |
-
if "shall" in text.lower():
|
393 |
-
suggestions.append("Consider replacing 'shall' with 'must' for clarity.")
|
394 |
-
if "may" in text.lower():
|
395 |
-
suggestions.append("Clarify the conditions under which actions 'may' be taken.")
|
396 |
-
if "if" in text.lower() and "then" not in text.lower():
|
397 |
-
suggestions.append("Ensure conditional statements are clear and complete.")
|
398 |
-
if "not" in text.lower():
|
399 |
-
suggestions.append("Review negative clauses to ensure they are not overly restrictive.")
|
400 |
-
|
401 |
-
return suggestions
|
402 |
-
|
403 |
-
# Function to send feedback via email
|
404 |
-
def send_feedback(feedback_content):
|
405 |
-
sender_email = os.getenv("SENDER_EMAIL")
|
406 |
-
receiver_email = os.getenv("FEEDBACK_EMAIL")
|
407 |
-
password = os.getenv("EMAIL_PASS")
|
408 |
-
|
409 |
-
msg = MIMEMultipart()
|
410 |
-
msg['From'] = sender_email
|
411 |
-
msg['To'] = receiver_email
|
412 |
-
msg['Subject'] = "User Feedback on Legal Document Analysis"
|
413 |
-
|
414 |
-
msg.attach(MIMEText(feedback_content, 'plain'))
|
415 |
-
|
416 |
-
try:
|
417 |
-
with smtplib.SMTP('smtp.gmail.com', 587) as server:
|
418 |
-
server.starttls()
|
419 |
-
server.login(sender_email, password)
|
420 |
-
server.send_message(msg)
|
421 |
-
return True
|
422 |
-
except Exception as e:
|
423 |
-
return False
|
424 |
-
|
425 |
-
# Function to send PDF via email
|
426 |
-
def send_pdf_via_email(pdf_buffer, recipient_email):
|
427 |
sender_email = os.getenv("SENDER_EMAIL")
|
428 |
password = os.getenv("EMAIL_PASS")
|
429 |
|
@@ -598,7 +551,9 @@ def display_legal_analysis_page():
|
|
598 |
# Button to send PDF via email
|
599 |
if st.button("Send PDF Analysis"):
|
600 |
if recipient_email:
|
601 |
-
|
|
|
|
|
602 |
st.success("PDF has been sent successfully!")
|
603 |
else:
|
604 |
st.error("Failed to send PDF. Please try again.")
|
|
|
15 |
import getpass
|
16 |
import pandas as pd
|
17 |
import seaborn as sns
|
18 |
+
import asyncio
|
19 |
|
20 |
# Load environment variables from .env file
|
21 |
load_dotenv()
|
|
|
375 |
|
376 |
return pdf_file_path # Return the path to the saved PDF
|
377 |
|
378 |
+
# Asynchronous function to send PDF via email
|
379 |
+
async def send_pdf_via_email(pdf_buffer, recipient_email):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
380 |
sender_email = os.getenv("SENDER_EMAIL")
|
381 |
password = os.getenv("EMAIL_PASS")
|
382 |
|
|
|
551 |
# Button to send PDF via email
|
552 |
if st.button("Send PDF Analysis"):
|
553 |
if recipient_email:
|
554 |
+
# Send PDF asynchronously
|
555 |
+
success = asyncio.run(send_pdf_via_email(pdf_buffer, recipient_email))
|
556 |
+
if success:
|
557 |
st.success("PDF has been sent successfully!")
|
558 |
else:
|
559 |
st.error("Failed to send PDF. Please try again.")
|