Shiv22419 commited on
Commit
435dd17
Β·
verified Β·
1 Parent(s): 2ff0980

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -9
app.py CHANGED
@@ -1,6 +1,8 @@
1
  import time
2
  import os
3
  import streamlit as st
 
 
4
  from langchain_community.vectorstores import FAISS
5
  from langchain_community.embeddings import HuggingFaceEmbeddings
6
  from langchain.prompts import PromptTemplate
@@ -13,10 +15,23 @@ from footer import footer
13
  # Set the Streamlit page configuration and theme
14
  st.set_page_config(page_title="In-Legal-IPC", layout="centered")
15
 
16
- # Display the logo image
17
  col1, col2, col3 = st.columns([1, 30, 1])
18
  with col2:
19
- st.image("https://raw.githubusercontent.com/shiv4321/Images/refs/heads/main/Banner.png", use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  def hide_hamburger_menu():
22
  st.markdown("""
@@ -44,6 +59,7 @@ embeddings = load_embeddings()
44
  db = FAISS.load_local("ipc_embed_db", embeddings, allow_dangerous_deserialization=True)
45
  db_retriever = db.as_retriever(search_type="similarity", search_kwargs={"k": 3})
46
 
 
47
  prompt_template = """
48
  <s>[INST]
49
  As a legal chatbot specializing in the Indian Penal Code, you are tasked with providing highly accurate and contextually appropriate responses. Ensure your answers meet these criteria:
@@ -86,14 +102,56 @@ def reset_conversation():
86
  st.session_state.messages = []
87
  st.session_state.memory.clear()
88
 
89
- # Add the PDF button just above the chat input
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  st.markdown("""
91
- ### Useful PDFs
92
- - [πŸ“„ Commercial Court Rules and Forms](https://drive.google.com/file/d/1puzlPMT7fTt4utWJaGlFtOjW38CoFctc/view?usp=drive_link)
93
- - [πŸ“„ Bail-Bond](https://drive.google.com/file/d/1uRlT7Yo_2jemxs5aRyvHzoLgeS7S81Vn/view?usp=drive_link)
94
- - [πŸ“„ Inspection Form](https://drive.google.com/file/d/1Ib-RC4xPMqZVl7YgVES3Vb47Rb42W83s/view?usp=drive_link)
95
- - [πŸ“„ Additional PDF](https://drive.google.com/file/d/1Xkq64r4Id8qSyb5woVzdvArhzUxvKJk8/view?usp=drive_link)
96
- """, unsafe_allow_html=True)
 
 
 
 
97
 
98
  # Display previous messages
99
  for message in st.session_state.messages:
@@ -123,6 +181,13 @@ if input_prompt:
123
 
124
  st.session_state.messages.append({"role": "assistant", "content": answer})
125
 
 
 
 
 
 
 
 
126
  if st.button('πŸ—‘οΈ Reset All Chat', on_click=reset_conversation):
127
  st.experimental_rerun()
128
 
 
1
  import time
2
  import os
3
  import streamlit as st
4
+ from reportlab.lib.pagesizes import letter
5
+ from reportlab.pdfgen import canvas
6
  from langchain_community.vectorstores import FAISS
7
  from langchain_community.embeddings import HuggingFaceEmbeddings
8
  from langchain.prompts import PromptTemplate
 
15
  # Set the Streamlit page configuration and theme
16
  st.set_page_config(page_title="In-Legal-IPC", layout="centered")
17
 
18
+ # Display the logo image with blur shadow
19
  col1, col2, col3 = st.columns([1, 30, 1])
20
  with col2:
21
+ st.markdown(
22
+ """
23
+ <style>
24
+ .blur-shadow {
25
+ box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.5);
26
+ border-radius: 10px;
27
+ }
28
+ </style>
29
+ <div class="blur-shadow">
30
+ <img src="https://raw.githubusercontent.com/shiv4321/Images/refs/heads/main/Banner.png" alt="Banner" width="100%">
31
+ </div>
32
+ """,
33
+ unsafe_allow_html=True
34
+ )
35
 
36
  def hide_hamburger_menu():
37
  st.markdown("""
 
59
  db = FAISS.load_local("ipc_embed_db", embeddings, allow_dangerous_deserialization=True)
60
  db_retriever = db.as_retriever(search_type="similarity", search_kwargs={"k": 3})
61
 
62
+ # Define the prompt template
63
  prompt_template = """
64
  <s>[INST]
65
  As a legal chatbot specializing in the Indian Penal Code, you are tasked with providing highly accurate and contextually appropriate responses. Ensure your answers meet these criteria:
 
102
  st.session_state.messages = []
103
  st.session_state.memory.clear()
104
 
105
+ # Function to create a PDF
106
+ def create_pdf(content):
107
+ pdf_filename = "legal_letter.pdf"
108
+ c = canvas.Canvas(pdf_filename, pagesize=letter)
109
+ width, height = letter
110
+ c.drawString(100, height - 100, content)
111
+ c.save()
112
+ return pdf_filename
113
+
114
+
115
+ # Add links to multiple PDFs just above the chat input
116
+ #st.markdown("""
117
+ # ### Useful PDFs
118
+ # - [πŸ“„ Commercial Court Rules and Forms](https://drive.google.com/file/d/1puzlPMT7fTt4utWJaGlFtOjW38CoFctc/view?usp=drive_link)
119
+ # - [πŸ“„ Bail-Bond](https://drive.google.com/file/d/1uRlT7Yo_2jemxs5aRyvHzoLgeS7S81Vn/view?usp=drive_link)
120
+ # - [πŸ“„ Inspection Form](https://drive.google.com/file/d/1Ib-RC4xPMqZVl7YgVES3Vb47Rb42W83s/view?usp=drive_link)
121
+ # - [πŸ“„ Additional PDF](https://drive.google.com/file/d/1Xkq64r4Id8qSyb5woVzdvArhzUxvKJk8/view?usp=drive_link)
122
+ # """, unsafe_allow_html=True)
123
+
124
+
125
+
126
+ # Add the PDF buttons
127
+ st.markdown("<h3 class='underline'>Useful PDFs</h3>", unsafe_allow_html=True)
128
+
129
+ col1, col2 = st.columns(2) # Create two columns for better alignment
130
+ with col1:
131
+ if st.button("Commercial Court Rules and Forms πŸ“„", key="ccrf", help="Open PDF", use_container_width=True):
132
+ st.markdown("[Open PDF](https://drive.google.com/file/d/1puzlPMT7fTt4utWJaGlFtOjW38CoFctc/view?usp=drive_link)", unsafe_allow_html=True)
133
+ if st.button("Bail-Bond πŸ“„", key="bb", help="Open PDF", use_container_width=True):
134
+ st.markdown("[Open PDF](https://drive.google.com/file/d/1uRlT7Yo_2jemxs5aRyvHzoLgeS7S81Vn/view?usp=drive_link)", unsafe_allow_html=True)
135
+
136
+ with col2:
137
+ if st.button("Inspection Form πŸ“„", key="if", help="Open PDF", use_container_width=True):
138
+ st.markdown("[Open PDF](https://drive.google.com/file/d/1Ib-RC4xPMqZVl7YgVES3Vb47Rb42W83s/view?usp=drive_link)", unsafe_allow_html=True)
139
+ if st.button("Additional PDF πŸ“„", key="apdf", help="Open PDF", use_container_width=True):
140
+ st.markdown("[Open PDF](https://drive.google.com/file/d/1Xkq64r4Id8qSyb5woVzdvArhzUxvKJk8/view?usp=drive_link)", unsafe_allow_html=True)
141
+
142
+
143
+ # Add CSS for the button styling
144
  st.markdown("""
145
+ <style>
146
+ .stButton button {
147
+ background-color: #ADD8E6;
148
+ color: black;
149
+ font-size: 16px;
150
+ }
151
+ </style>
152
+ """, unsafe_allow_html=True)
153
+
154
+
155
 
156
  # Display previous messages
157
  for message in st.session_state.messages:
 
181
 
182
  st.session_state.messages.append({"role": "assistant", "content": answer})
183
 
184
+ # Generate PDF if the user indicates a personal legal problem
185
+ if "personal legal problem" in input_prompt.lower():
186
+ user_problem = input_prompt # Capture the user's legal problem
187
+ pdf_content = f"Dear Client,\n\nYour legal problem is as follows:\n{user_problem}\n\nBest Regards,\nYour Legal Advisor"
188
+ pdf_file = create_pdf(pdf_content)
189
+ st.download_button(label="Download your legal letter", data=pdf_file, file_name="legal_letter.pdf")
190
+
191
  if st.button('πŸ—‘οΈ Reset All Chat', on_click=reset_conversation):
192
  st.experimental_rerun()
193