Update legal_document_analysis.py
Browse files- legal_document_analysis.py +51 -21
legal_document_analysis.py
CHANGED
@@ -15,7 +15,6 @@ from fpdf import FPDF
|
|
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,8 +374,56 @@ def generate_pdf_analysis(document_text, summary, detected_clauses, hidden_oblig
|
|
375 |
|
376 |
return pdf_file_path # Return the path to the saved PDF
|
377 |
|
378 |
-
#
|
379 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
380 |
sender_email = os.getenv("SENDER_EMAIL")
|
381 |
password = os.getenv("EMAIL_PASS")
|
382 |
|
@@ -418,21 +465,6 @@ def get_update_suggestion(update):
|
|
418 |
suggestion = generate_summary(prompt)
|
419 |
return suggestion if suggestion else "No suggestion available."
|
420 |
|
421 |
-
# Function to generate suggestions for improvement
|
422 |
-
def generate_suggestions(text):
|
423 |
-
suggestions = []
|
424 |
-
|
425 |
-
if "shall" in text.lower():
|
426 |
-
suggestions.append("Consider replacing 'shall' with 'must' for clarity.")
|
427 |
-
if "may" in text.lower():
|
428 |
-
suggestions.append("Clarify the conditions under which actions 'may' be taken.")
|
429 |
-
if "if" in text.lower() and "then" not in text.lower():
|
430 |
-
suggestions.append("Ensure conditional statements are clear and complete.")
|
431 |
-
if "not" in text.lower():
|
432 |
-
suggestions.append("Review negative clauses to ensure they are not overly restrictive.")
|
433 |
-
|
434 |
-
return suggestions
|
435 |
-
|
436 |
# Function to display feedback form
|
437 |
def display_feedback_form():
|
438 |
st.subheader("Feedback Form")
|
@@ -566,9 +598,7 @@ def display_legal_analysis_page():
|
|
566 |
# Button to send PDF via email
|
567 |
if st.button("Send PDF Analysis"):
|
568 |
if recipient_email:
|
569 |
-
|
570 |
-
success = asyncio.run(send_pdf_via_email(pdf_buffer, recipient_email))
|
571 |
-
if success:
|
572 |
st.success("PDF has been sent successfully!")
|
573 |
else:
|
574 |
st.error("Failed to send PDF. Please try again.")
|
|
|
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 |
|
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):
|
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 |
|
|
|
465 |
suggestion = generate_summary(prompt)
|
466 |
return suggestion if suggestion else "No suggestion available."
|
467 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
468 |
# Function to display feedback form
|
469 |
def display_feedback_form():
|
470 |
st.subheader("Feedback Form")
|
|
|
598 |
# Button to send PDF via email
|
599 |
if st.button("Send PDF Analysis"):
|
600 |
if recipient_email:
|
601 |
+
if send_pdf_via_email(pdf_buffer, recipient_email):
|
|
|
|
|
602 |
st.success("PDF has been sent successfully!")
|
603 |
else:
|
604 |
st.error("Failed to send PDF. Please try again.")
|