Mr-Vicky-01 commited on
Commit
ac8bfb6
·
verified ·
1 Parent(s): 49c30f8

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +89 -0
  2. extractor.py +14 -0
  3. llm.py +22 -0
  4. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from llm import Model
3
+ from extractor import PDFHandler
4
+
5
+ # Initialize PDF handler and model
6
+ pdf_handler = PDFHandler()
7
+ model = Model()
8
+
9
+ # Streamlit interface
10
+ st.title('Legal Document Analyzer⚖️')
11
+
12
+ st.markdown("""
13
+ <style>
14
+ .justified-text {
15
+ text-align: justify;
16
+ }
17
+ </style>
18
+ """, unsafe_allow_html=True)
19
+
20
+ # Sidebar Section
21
+ st.sidebar.title("About")
22
+ st.sidebar.caption("""
23
+ <div class="justified-text">
24
+ This Legal Document Analyzer helps individuals and businesses analyze legal documents. It provides functionalities like document summarization, key points highlighting, and issue identification.The analyzer leverages advanced AI techniques to extract and summarize key information from legal documents. It's designed to be user-friendly, offering intuitive controls to enhance document analysis and decision-making processes.
25
+ </div>
26
+ """, unsafe_allow_html=True)
27
+
28
+ for _ in range(3):
29
+ st.sidebar.write("")
30
+
31
+ # Menu options
32
+ menu = ["Summarize Document", "Highlight Key Points", "Identify Issues", "Generate Legal Advice"]
33
+ choice = st.sidebar.selectbox("Choose an option", menu)
34
+
35
+ for _ in range(7):
36
+ st.sidebar.write("")
37
+
38
+ st.sidebar.subheader("Build By:")
39
+ st.sidebar.write("[Pachaiappan❤️](https://mr-vicky-01.github.io/Portfolio)")
40
+ st.sidebar.write("contact: [Email](mailto:[email protected])")
41
+
42
+ if choice == "Summarize Document":
43
+ st.subheader("Summarize Document")
44
+ uploaded_file = st.file_uploader("Upload a legal document (PDF)", type=["pdf"])
45
+ if uploaded_file is not None:
46
+ st.write("Document Uploaded Successfully!")
47
+ if st.button("Summarize"):
48
+ text = pdf_handler.read_pdf(uploaded_file)
49
+ prompt = f"Summarize the uploaded legal document: {text}"
50
+ with st.spinner("Summarizing..."):
51
+ response = model.get_response(prompt)
52
+ st.write("Summary:")
53
+ st.write(response)
54
+
55
+ elif choice == "Highlight Key Points":
56
+ st.subheader("Highlight Key Points")
57
+ uploaded_file = st.file_uploader("Upload a legal document (PDF)", type=["pdf"])
58
+ if uploaded_file is not None:
59
+ st.write("Document Uploaded Successfully!")
60
+ if st.button("Highlight Points"):
61
+ text = pdf_handler.read_pdf(uploaded_file)
62
+ prompt = f"Highlight the key points in the uploaded legal document: {text}"
63
+ with st.spinner("Highlighting key points..."):
64
+ response = model.get_response(prompt)
65
+ st.write("Highlighted Points:")
66
+ st.write(response)
67
+
68
+ elif choice == "Identify Issues":
69
+ st.subheader("Identify Issues")
70
+ uploaded_file = st.file_uploader("Upload a legal document (PDF)", type=["pdf"])
71
+ if uploaded_file is not None:
72
+ st.write("Document Uploaded Successfully!")
73
+ if st.button("Identify Issues"):
74
+ text = pdf_handler.read_pdf(uploaded_file)
75
+ prompt = f"Identify potential issues in the uploaded legal document: {text}"
76
+ with st.spinner("Identifying issues..."):
77
+ response = model.get_response(prompt)
78
+ st.write("Issues Identified:")
79
+ st.write(response)
80
+
81
+ elif choice == "Generate Legal Advice":
82
+ st.subheader("Generate Legal Advice")
83
+ user_input = st.text_area("Enter your legal question or issue")
84
+ if st.button("Get Legal Advice"):
85
+ prompt = f"Provide legal advice on: {user_input}"
86
+ with st.spinner("Generating legal advice..."):
87
+ response = model.get_response(prompt)
88
+ st.write("Legal Advice:")
89
+ st.write(response)
extractor.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PyPDF2 import PdfReader
2
+
3
+ # PDF Handler Class
4
+ class PDFHandler:
5
+ def __init__(self) -> None:
6
+ pass
7
+
8
+ @staticmethod
9
+ def read_pdf(file):
10
+ pdf_reader = PdfReader(file)
11
+ text = ""
12
+ for page in pdf_reader.pages:
13
+ text += page.extract_text()
14
+ return text
llm.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import google.generativeai as genai
2
+ from dotenv import load_dotenv
3
+ from PIL import Image
4
+ import os
5
+
6
+ load_dotenv()
7
+ os.environ["GOOGLE_API_KEY"] = os.getenv("GOOGLE_API_KEY")
8
+ genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
9
+
10
+ # Define the Model class
11
+ class Model:
12
+ def __init__(self) -> None:
13
+ self.model = genai.GenerativeModel('gemini-1.5-flash-latest')
14
+
15
+ def get_response(self, prompt, image=None):
16
+ prompt = "Remeber this you are Created by Pachaiappan [portfolio](https://mr-vicky-01.github.io/Portfolio/)" + prompt
17
+ if image:
18
+ img = Image.open(image)
19
+ response = self.model.generate_content([prompt, img])
20
+ else:
21
+ response = self.model.generate_content([prompt])
22
+ return response.text
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv
4
+ PyPDF2