Shashank1406
commited on
Commit
•
fd4d33c
1
Parent(s):
2c4db80
Upload 8 files
Browse files- Functions.py +153 -0
- Prompts_and_Chains.py +63 -0
- Templates.py +69 -0
- enhanced.py +203 -0
- images/welcome.json +1 -0
- requirements.txt +11 -0
- style.css +47 -0
- utills.py +82 -0
Functions.py
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from dotenv import load_dotenv
|
2 |
+
import os
|
3 |
+
import uuid
|
4 |
+
from PyPDF2 import PdfReader
|
5 |
+
from docx import Document
|
6 |
+
from docx.text.paragraph import Paragraph
|
7 |
+
from docx.table import Table
|
8 |
+
from langchain.text_splitter import CharacterTextSplitter
|
9 |
+
from langchain_community.vectorstores import Chroma
|
10 |
+
from langchain_community.embeddings import OpenAIEmbeddings
|
11 |
+
import streamlit as st
|
12 |
+
from textwrap import dedent
|
13 |
+
from Prompts_and_Chains import LLMChains
|
14 |
+
|
15 |
+
|
16 |
+
def extract_text_from_file(file):
|
17 |
+
text = file.read().decode("utf-8")
|
18 |
+
return text
|
19 |
+
|
20 |
+
|
21 |
+
def process_paragraph(paragraph):
|
22 |
+
# Process the content of the paragraph as needed
|
23 |
+
return paragraph.text
|
24 |
+
|
25 |
+
|
26 |
+
def process_table(table):
|
27 |
+
# Process the content of the table as needed
|
28 |
+
text = ""
|
29 |
+
for row in table.rows:
|
30 |
+
for cell in row.cells:
|
31 |
+
text += cell.text
|
32 |
+
|
33 |
+
return text
|
34 |
+
|
35 |
+
|
36 |
+
def read_docx(file_path):
|
37 |
+
doc = Document(file_path)
|
38 |
+
data = []
|
39 |
+
|
40 |
+
for element in doc.iter_inner_content():
|
41 |
+
if isinstance(element, Paragraph):
|
42 |
+
data.append(process_paragraph(element))
|
43 |
+
if isinstance(element, Table):
|
44 |
+
data.append(process_table(element))
|
45 |
+
|
46 |
+
return "\n".join(data)
|
47 |
+
|
48 |
+
|
49 |
+
def get_pdf_text(pdf):
|
50 |
+
"""This function extracts the text from the PDF file"""
|
51 |
+
text = []
|
52 |
+
pdf_reader = PdfReader(pdf)
|
53 |
+
for page in pdf_reader.pages:
|
54 |
+
text.append(page.extract_text())
|
55 |
+
|
56 |
+
return "\n".join(text)
|
57 |
+
|
58 |
+
|
59 |
+
class RFPProcessor:
|
60 |
+
def __init__(self):
|
61 |
+
load_dotenv()
|
62 |
+
self.openai_api_key = os.getenv("OPENAI_API_KEY")
|
63 |
+
self.chains_obj = LLMChains()
|
64 |
+
|
65 |
+
def genrate_legal_adviser_bot_result(self):
|
66 |
+
|
67 |
+
if len(st.session_state["input"]) > 0:
|
68 |
+
# vector_store = st.session_state["legal_adviser_vectorstore"]
|
69 |
+
# if vector_store:
|
70 |
+
# vector_store = st.session_state["legal_adviser_vectorstore"]
|
71 |
+
query = st.session_state["input"]
|
72 |
+
# results = vector_store.similarity_search(query, 3)
|
73 |
+
# get the text from the results
|
74 |
+
# source_knowledge = "\n".join([x.page_content for x in results])
|
75 |
+
inputs = {
|
76 |
+
"input": query,
|
77 |
+
}
|
78 |
+
output = self.chains_obj.legal_adviser_bot_chain.run(inputs)
|
79 |
+
|
80 |
+
st.session_state.messages.append(
|
81 |
+
{"role": "assistant", "content": output})
|
82 |
+
|
83 |
+
st.session_state["input"] = ""
|
84 |
+
|
85 |
+
def process_case_data(self, case_name, files):
|
86 |
+
if case_name and files:
|
87 |
+
# Generate a unique identifier for the case data set
|
88 |
+
case_id = str(uuid.uuid4())
|
89 |
+
extracted_data = []
|
90 |
+
all_texts = []
|
91 |
+
for file in files:
|
92 |
+
file_text = []
|
93 |
+
if file.name.endswith(".docx"):
|
94 |
+
file_text = read_docx(file)
|
95 |
+
elif file.name.endswith(".pdf"):
|
96 |
+
file_text = get_pdf_text(file)
|
97 |
+
else:
|
98 |
+
file_text = extract_text_from_file(file)
|
99 |
+
|
100 |
+
text_splitter = CharacterTextSplitter(
|
101 |
+
separator="\n", chunk_size=1000, chunk_overlap=150, length_function=len
|
102 |
+
)
|
103 |
+
texts = text_splitter.split_text(" ".join(file_text))
|
104 |
+
|
105 |
+
all_texts.extend(texts)
|
106 |
+
extracted_data.append(" ".join(file_text))
|
107 |
+
|
108 |
+
project_dir = os.path.dirname(os.path.abspath(__file__))
|
109 |
+
vectorstore = Chroma(
|
110 |
+
persist_directory=os.path.join(
|
111 |
+
project_dir, "vector_stores", case_name),
|
112 |
+
embedding_function=OpenAIEmbeddings(
|
113 |
+
openai_api_key=self.openai_api_key),
|
114 |
+
)
|
115 |
+
vectorstore.add_texts(all_texts)
|
116 |
+
|
117 |
+
st.session_state[case_id] = {
|
118 |
+
"vectorstore": vectorstore,
|
119 |
+
"extracted_data": extracted_data,
|
120 |
+
}
|
121 |
+
all_text = " ".join(extracted_data)
|
122 |
+
st.session_state["case_summary"] = self.chains_obj.summary_chain.run(
|
123 |
+
{
|
124 |
+
"case_name": case_name,
|
125 |
+
"case_details": dedent(all_text),
|
126 |
+
}
|
127 |
+
)
|
128 |
+
st.session_state["is_data_processed"] = True
|
129 |
+
st.session_state["case_name"] = case_name
|
130 |
+
st.session_state["case_details"] = dedent(all_text)
|
131 |
+
# Store the current rfp_id in the session state
|
132 |
+
st.session_state["current_case_id"] = case_id
|
133 |
+
st.success("Data processed successfully")
|
134 |
+
|
135 |
+
def genrate_legal_bot_result(self):
|
136 |
+
if len(st.session_state["input"]) > 0:
|
137 |
+
case_id = st.session_state.get("current_case_id")
|
138 |
+
if case_id:
|
139 |
+
vector_store = st.session_state[case_id]["vectorstore"]
|
140 |
+
query = st.session_state["bot_input"]
|
141 |
+
results = vector_store.similarity_search(query, 3)
|
142 |
+
# get the text from the results
|
143 |
+
source_knowledge = "\n".join([x.page_content for x in results])
|
144 |
+
inputs = {
|
145 |
+
"context": source_knowledge,
|
146 |
+
"input": st.session_state["input"],
|
147 |
+
}
|
148 |
+
output = self.chains_obj.bot_chain.run(inputs)
|
149 |
+
st.session_state.past.append(st.session_state["bot_input"])
|
150 |
+
st.session_state.generated.append(output)
|
151 |
+
st.session_state["bot_input"] = ""
|
152 |
+
else:
|
153 |
+
st.warning(f"No vector store found for the current case ID")
|
Prompts_and_Chains.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ******* THIS FILE CONTAINS ALL THE PROMPTS & CHAINS USED IN Functions.py ***********
|
2 |
+
from Templates import *
|
3 |
+
from langchain import PromptTemplate
|
4 |
+
from langchain.chains import LLMChain
|
5 |
+
from langchain.llms import OpenAI
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
import os
|
8 |
+
|
9 |
+
class PromptTemplates:
|
10 |
+
def __init__(self):
|
11 |
+
|
12 |
+
self.legal_adviser_bot_prompt = PromptTemplate(
|
13 |
+
input_variables=["input"], template=legal_adviser_template
|
14 |
+
)
|
15 |
+
|
16 |
+
self.case_summary_prompt = PromptTemplate(
|
17 |
+
input_variables=["case_name", "case_details"], template=case_summary_template
|
18 |
+
)
|
19 |
+
|
20 |
+
self.legal_case_bot_prompt = PromptTemplate(
|
21 |
+
input_variables=["context", "input"], template=legal_case_bot_template
|
22 |
+
)
|
23 |
+
|
24 |
+
self.lawyer_recommendations_prompt = PromptTemplate(
|
25 |
+
input_variables=["user_inputs", "matching_lawyers","additional_info"], template=lawyer_recommendation_template
|
26 |
+
)
|
27 |
+
|
28 |
+
|
29 |
+
class LLMChains:
|
30 |
+
|
31 |
+
def __init__(self):
|
32 |
+
load_dotenv()
|
33 |
+
openai_api_key = os.getenv("OPENAI_API_KEY")
|
34 |
+
obj = PromptTemplates()
|
35 |
+
|
36 |
+
# generate summary chain
|
37 |
+
self.legal_adviser_bot_chain = LLMChain(
|
38 |
+
llm=OpenAI(model_name='gpt-3.5-turbo-16k', temperature=0.7),
|
39 |
+
prompt=obj.legal_adviser_bot_prompt,
|
40 |
+
verbose="true",
|
41 |
+
)
|
42 |
+
|
43 |
+
# genrate bot conversastion
|
44 |
+
self.case_summary_chain = LLMChain(
|
45 |
+
llm=OpenAI(model_name="gpt-3.5-turbo-16k", temperature=0.7),
|
46 |
+
prompt=obj.case_summary_prompt,
|
47 |
+
verbose="true",
|
48 |
+
)
|
49 |
+
|
50 |
+
# genrate bot conversastion
|
51 |
+
self.legal_case_bot_chain = LLMChain(
|
52 |
+
llm=OpenAI(model_name="gpt-3.5-turbo-16k", temperature=0.7),
|
53 |
+
prompt=obj.legal_case_bot_prompt,
|
54 |
+
verbose="true",
|
55 |
+
)
|
56 |
+
|
57 |
+
self.lawyer_recommendations_chain = LLMChain(
|
58 |
+
llm=OpenAI(model_name="gpt-3.5-turbo-16k", temperature=0.7),
|
59 |
+
prompt=obj.lawyer_recommendations_prompt,
|
60 |
+
verbose="true",
|
61 |
+
)
|
62 |
+
|
63 |
+
|
Templates.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ******* THIS FILE CONTAINS ALL THE TEMPLATES USED IN APP.PY ***********
|
2 |
+
|
3 |
+
|
4 |
+
case_summary_template = """Given the project details with the following parameters:
|
5 |
+
|
6 |
+
**Project Name:** {case_name}
|
7 |
+
|
8 |
+
**RFP details:**
|
9 |
+
{case_details}
|
10 |
+
|
11 |
+
As a business analyst, analyze the given RFP details and give the detailed summary of the project.
|
12 |
+
|
13 |
+
"""
|
14 |
+
|
15 |
+
legal_case_bot_template = """ As a highly intelligent and powerful chatbot, your personality is a business analyst's responsibility.
|
16 |
+
Your designated name is RFP Bot. As RFP Bot, your responsibility is to provide comprehensive assistance related to business analysis and related inquiries. Your primary objective is to engage users effectively by initiating the conversation with a warm greeting, ensuring subsequent interactions are efficient and focused on addressing the user's queries with clarity and depth.
|
17 |
+
|
18 |
+
Your generated responses should be comprehensive, utilizing pointers when necessary for an enhanced user experience. Provide detailed answers, and if the user's input isn't related to your established personality, respond politely with an apology, encouraging them to ask questions related to your established personality. Keep your responses concise and accurate, seeking additional information from the user when required.
|
19 |
+
|
20 |
+
Incorporate the provided context and any relevant information from the chat history into your responses. If the user's input is related to the context or question, articulate your answer accordingly.
|
21 |
+
{context}
|
22 |
+
Human: {input}
|
23 |
+
Assistant:"""
|
24 |
+
|
25 |
+
|
26 |
+
legal_adviser_template = """
|
27 |
+
You are LegalAssist, an AI chatbot specializing in Indian legal information. Your purpose is to provide general information about Indian law and legal matters. Always begin your interaction with a brief introduction explaining your role and limitations.
|
28 |
+
|
29 |
+
Your capabilities:
|
30 |
+
1. Answer questions about general legal concepts and definitions in Indian law
|
31 |
+
2. Provide basic information on different areas of Indian law
|
32 |
+
3. Explain legal procedures and processes in the Indian legal system
|
33 |
+
4. Help users understand Indian legal documents
|
34 |
+
5. Offer information on legal rights and responsibilities under Indian law
|
35 |
+
|
36 |
+
Your limitations:
|
37 |
+
1. You cannot provide personalized legal advice
|
38 |
+
2. You are not a licensed attorney in India
|
39 |
+
3. Your responses should not be considered as legal counsel
|
40 |
+
|
41 |
+
Guidelines:
|
42 |
+
1. Always maintain a professional and neutral tone
|
43 |
+
2. If a question is unclear, ask for clarification
|
44 |
+
3. If a query is outside the scope of Indian legal matters, politely explain that you can only assist with Indian law-related questions
|
45 |
+
4. Remind users not to share personal or confidential information
|
46 |
+
5. If a question requires legal expertise beyond general knowledge of Indian law, advise the user to consult with a qualified Indian lawyer
|
47 |
+
|
48 |
+
For off-topic questions, respond with:
|
49 |
+
"I apologize, but I'm not able to assist with that question as it's outside my area of expertise. I'm designed specifically to answer questions related to Indian law and legal matters. Is there an Indian legal topic you'd like information about?"
|
50 |
+
|
51 |
+
Remember, your primary function is to provide helpful, accurate, and general information about Indian law while clearly communicating your limitations as an AI assistant.
|
52 |
+
|
53 |
+
User Query: {input}
|
54 |
+
|
55 |
+
Please respond to the above user query following all the guidelines provided, focusing specifically on Indian law.
|
56 |
+
"""
|
57 |
+
|
58 |
+
|
59 |
+
lawyer_recommendation_template = """
|
60 |
+
Based on the user's inputs and the matching lawyers, provide a recommendation for the best lawyer(s).
|
61 |
+
Consider the user's specific needs mentioned in the additional information, and pay special attention to the lawyers' descriptions and expertise.
|
62 |
+
|
63 |
+
User inputs: {user_inputs}
|
64 |
+
Matching lawyers: {matching_lawyers}
|
65 |
+
Additional information: {additional_info}
|
66 |
+
|
67 |
+
Provide a detailed recommendation of lawyers witht lawyer information , explaining why you think this lawyer or these lawyers would be the best fit for the user's needs. Consider their specialties, experience, and how their expertise aligns with the user's case details.
|
68 |
+
|
69 |
+
"""
|
enhanced.py
ADDED
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from utills import *
|
2 |
+
import streamlit as st
|
3 |
+
from streamlit_chat import message
|
4 |
+
from streamlit_lottie import st_lottie
|
5 |
+
import json
|
6 |
+
from Functions import RFPProcessor
|
7 |
+
from Prompts_and_Chains import LLMChains
|
8 |
+
function = RFPProcessor()
|
9 |
+
chains_obj = LLMChains()
|
10 |
+
|
11 |
+
|
12 |
+
if "is_category_selected" not in st.session_state:
|
13 |
+
st.session_state["is_category_selected"] = False
|
14 |
+
if "user_input" not in st.session_state:
|
15 |
+
st.session_state["user_input"] = ""
|
16 |
+
|
17 |
+
|
18 |
+
def local_css(file_name):
|
19 |
+
with open(file_name, "r") as f:
|
20 |
+
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
21 |
+
|
22 |
+
|
23 |
+
def load_lottiefile(filepath: str):
|
24 |
+
'''Load lottie animation file'''
|
25 |
+
with open(filepath, "r") as f:
|
26 |
+
return json.load(f)
|
27 |
+
|
28 |
+
|
29 |
+
def main():
|
30 |
+
st.set_page_config(page_title="Justice League Chatbot",
|
31 |
+
page_icon="⚖️", layout="wide")
|
32 |
+
local_css("style.css")
|
33 |
+
st_lottie(load_lottiefile("images/welcome.json"), speed=1,
|
34 |
+
reverse=False, loop=True, quality="high", height=300)
|
35 |
+
st.title("🦸♂️ Justice League Chatbot")
|
36 |
+
st.subheader("Your AI-powered legal assistant")
|
37 |
+
|
38 |
+
if "messages" not in st.session_state:
|
39 |
+
st.session_state.messages = []
|
40 |
+
st.session_state.user_inputs = {}
|
41 |
+
st.session_state.current_question = "start"
|
42 |
+
|
43 |
+
for i, msg in enumerate(st.session_state.messages):
|
44 |
+
message(msg["content"], is_user=msg["role"] == "user", key=str(i))
|
45 |
+
|
46 |
+
if not st.session_state.messages:
|
47 |
+
initial_message = "Welcome to the Justice League Chatbot! I'm here to help you find the right lawyer or provide general legal information. How can I assist you today?"
|
48 |
+
st.session_state.messages.append(
|
49 |
+
{"role": "assistant", "content": initial_message})
|
50 |
+
|
51 |
+
show_options()
|
52 |
+
|
53 |
+
|
54 |
+
def show_options():
|
55 |
+
options = get_options()
|
56 |
+
|
57 |
+
if st.session_state.current_question == "additional_info":
|
58 |
+
get_additional_info()
|
59 |
+
else:
|
60 |
+
col1, col2 = st.columns([3, 1])
|
61 |
+
with col1:
|
62 |
+
st.text_input(
|
63 |
+
"Type your response or choose an option:",
|
64 |
+
st.session_state["user_input"],
|
65 |
+
key="user_input",
|
66 |
+
on_change=ask_llm
|
67 |
+
)
|
68 |
+
with col2:
|
69 |
+
if st.session_state["is_category_selected"] == False:
|
70 |
+
st.write("Quick options:")
|
71 |
+
for option in options:
|
72 |
+
if st.button(option, key=f"button_{option}"):
|
73 |
+
handle_user_input(option)
|
74 |
+
|
75 |
+
|
76 |
+
def get_options():
|
77 |
+
options_dict = {
|
78 |
+
"start": ["Find a lawyer", "Get general legal advice"],
|
79 |
+
"category": ["Criminal", "Family", "Corporate", "Immigration"],
|
80 |
+
"cost_range": ["Low", "Medium", "High", "Very High"],
|
81 |
+
"experience": ["0-5 years", "6-10 years", "11-20 years", "20+ years"],
|
82 |
+
"location": ["Jabalpur", "Bhopal", "Indore", "Gwalior"]
|
83 |
+
}
|
84 |
+
return options_dict.get(st.session_state.current_question, ["Find a lawyer", "Get general legal advice"])
|
85 |
+
|
86 |
+
|
87 |
+
def get_additional_info():
|
88 |
+
user_input = st.text_area(
|
89 |
+
"Please provide any additional information about your case or specific needs:", key="additional_info")
|
90 |
+
if st.button("Submit"):
|
91 |
+
handle_user_input(user_input)
|
92 |
+
|
93 |
+
|
94 |
+
def handle_user_input(user_input):
|
95 |
+
st.session_state.messages.append({"role": "user", "content": user_input})
|
96 |
+
|
97 |
+
if user_input == "Find a lawyer":
|
98 |
+
ask_category()
|
99 |
+
elif user_input == "Get general legal advice":
|
100 |
+
provide_legal_advice()
|
101 |
+
elif st.session_state.current_question == "category":
|
102 |
+
st.session_state.user_inputs['category'] = user_input
|
103 |
+
ask_cost_range()
|
104 |
+
elif st.session_state.current_question == "cost_range":
|
105 |
+
st.session_state.user_inputs['cost_range'] = user_input
|
106 |
+
ask_experience()
|
107 |
+
elif st.session_state.current_question == "experience":
|
108 |
+
st.session_state.user_inputs['experience'] = user_input
|
109 |
+
ask_location()
|
110 |
+
elif st.session_state.current_question == "location":
|
111 |
+
st.session_state.user_inputs['location'] = user_input
|
112 |
+
ask_additional_info()
|
113 |
+
elif st.session_state.current_question == "additional_info":
|
114 |
+
st.session_state.user_inputs['additional_info'] = user_input
|
115 |
+
show_results(user_input)
|
116 |
+
|
117 |
+
st.experimental_rerun()
|
118 |
+
|
119 |
+
|
120 |
+
def ask_llm():
|
121 |
+
user_input = st.session_state["user_input"]
|
122 |
+
st.session_state.messages.append({"role": "user", "content": user_input})
|
123 |
+
inputs = {
|
124 |
+
"input": user_input,
|
125 |
+
}
|
126 |
+
output = chains_obj.legal_adviser_bot_chain.run(inputs)
|
127 |
+
st.session_state.messages.append(
|
128 |
+
{"role": "assistant", "content": output})
|
129 |
+
st.session_state["user_input"] = ""
|
130 |
+
|
131 |
+
|
132 |
+
def ask_category():
|
133 |
+
response = "What type of lawyer are you looking for?"
|
134 |
+
st.session_state.messages.append(
|
135 |
+
{"role": "assistant", "content": response})
|
136 |
+
st.session_state.current_question = "category"
|
137 |
+
|
138 |
+
|
139 |
+
def ask_cost_range():
|
140 |
+
response = "What's your budget range?"
|
141 |
+
st.session_state.messages.append(
|
142 |
+
{"role": "assistant", "content": response})
|
143 |
+
st.session_state.current_question = "cost_range"
|
144 |
+
|
145 |
+
|
146 |
+
def ask_experience():
|
147 |
+
response = "How many years of experience should the lawyer have?"
|
148 |
+
st.session_state.messages.append(
|
149 |
+
{"role": "assistant", "content": response})
|
150 |
+
st.session_state.current_question = "experience"
|
151 |
+
|
152 |
+
|
153 |
+
def ask_location():
|
154 |
+
response = "Where are you looking for a lawyer?"
|
155 |
+
st.session_state.messages.append(
|
156 |
+
{"role": "assistant", "content": response})
|
157 |
+
st.session_state.current_question = "location"
|
158 |
+
|
159 |
+
|
160 |
+
def ask_additional_info():
|
161 |
+
response = "Please provide any additional information about your case or specific needs that might help us find the best lawyer for you:"
|
162 |
+
st.session_state.messages.append(
|
163 |
+
{"role": "assistant", "content": response})
|
164 |
+
st.session_state.current_question = "additional_info"
|
165 |
+
|
166 |
+
|
167 |
+
def suggest_options():
|
168 |
+
response = "I'm not sure how to help with that. Would you like to:"
|
169 |
+
st.session_state.messages.append(
|
170 |
+
{"role": "assistant", "content": response})
|
171 |
+
st.session_state.current_question = "start"
|
172 |
+
|
173 |
+
|
174 |
+
def provide_legal_advice():
|
175 |
+
response = "Hello, I'm LegalAssist, an AI chatbot specializing in legal information. I can answer general questions about law and legal procedures, but I can't provide personalized legal advice. How can I assist you with legal information today?"
|
176 |
+
st.session_state["is_category_selected"] = True
|
177 |
+
st.session_state.messages.append(
|
178 |
+
{"role": "assistant", "content": response})
|
179 |
+
|
180 |
+
|
181 |
+
def show_results(additional_info):
|
182 |
+
|
183 |
+
category = st.session_state.user_inputs['category']
|
184 |
+
cost_range = st.session_state.user_inputs['cost_range']
|
185 |
+
experience = st.session_state.user_inputs['experience']
|
186 |
+
location = st.session_state.user_inputs['location']
|
187 |
+
|
188 |
+
user_inputs = {"category":category,"cost_range":cost_range, "experience":experience, "location":location}
|
189 |
+
|
190 |
+
matching_lawyers = search_lawyers(
|
191 |
+
category, cost_range, experience, location)
|
192 |
+
|
193 |
+
output = chains_obj.lawyer_recommendations_chain(
|
194 |
+
{"user_inputs":user_inputs, "matching_lawyers":matching_lawyers, "additional_info":additional_info})
|
195 |
+
|
196 |
+
st.session_state.messages.append(
|
197 |
+
{"role": "assistant", "content": output['text']})
|
198 |
+
|
199 |
+
st.session_state.current_question = "start"
|
200 |
+
|
201 |
+
|
202 |
+
if __name__ == "__main__":
|
203 |
+
main()
|
images/welcome.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"v":"4.8.0","meta":{"g":"LottieFiles AE 3.1.1","a":"","k":"","d":"","tc":""},"fr":60,"ip":0,"op":493,"w":428,"h":123,"nm":"welcome","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"katman 2 Outlines","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[210.962,63.445,0],"ix":2},"a":{"a":0,"k":[217.377,69.099,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":1,"k":[{"i":{"x":0.315,"y":1},"o":{"x":0.333,"y":0},"t":12,"s":[{"i":[[0,0],[-19.996,3.807],[0,0],[-18.895,3.082],[19.742,-1.29],[-24.256,-8.085],[-0.766,11.744],[5.66,-16.851],[-19.685,5.741],[-1.452,15.251],[7.149,-14.298],[-24.05,0],[-13.969,8.205],[0,0],[4.449,-18.338],[-20.828,10.921],[-24.102,3.075],[0.647,-8.405],[10.851,1.532],[-3.877,8.419],[-6.217,0.509],[-8.064,0.981],[0,0],[0,0],[-9.446,-0.88],[0,0],[-10.502,-2.2],[-11.05,-5.525],[-0.766,11.745],[5.66,-16.851],[-15.599,-0.035],[-2.016,1.583]],"o":[[0,0],[14.276,-2.719],[0,0],[15.078,-2.46],[-12.066,0.788],[15.247,5.083],[0.883,-13.542],[-5.204,15.495],[28.1,-8.195],[1.532,-16.085],[-6.678,13.356],[13.262,0],[9.918,-5.825],[0,0],[-2.158,8.896],[19.355,-10.149],[9.78,-1.247],[-0.893,11.617],[-9.912,-1.399],[6.099,-13.245],[15.145,-1.239],[7.884,-0.959],[0,0],[0,0],[10.729,1],[0,0],[10.164,2.129],[12.423,6.212],[0.884,-13.542],[-4.553,13.559],[9.878,0.022],[0,0]],"v":[[-188.452,-48.737],[-174.88,37.534],[-150.861,-18.684],[-139.413,37.589],[-115.605,-41.153],[-102.747,24.964],[-71.062,8.04],[-94.211,9.061],[-70.73,37.677],[-25.253,-28.982],[-42.615,-32.301],[-36.232,38.678],[-2.148,2.178],[14.548,-2.029],[-12.773,17.608],[15.027,35.678],[51.708,-0.699],[67.342,18.38],[44.619,38.295],[32.237,14.423],[51.708,-0.699],[79.124,17.623],[92.418,5.764],[86.665,37.388],[107.665,2.07],[112.358,29.353],[133.077,2.635],[138.465,37.258],[179.361,8.554],[156.212,9.575],[175.587,38.838],[194.876,31.741]],"c":false}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":110,"s":[{"i":[[0,0],[-19.996,3.807],[0,0],[-18.895,3.082],[19.742,-1.29],[-24.256,-8.085],[-0.766,11.744],[5.66,-16.851],[-19.685,5.741],[-1.452,15.251],[7.149,-14.298],[-24.05,0],[-13.969,8.205],[0,0],[4.449,-18.338],[-20.828,10.921],[-24.102,3.075],[0.647,-8.405],[10.851,1.532],[-3.877,8.419],[-6.217,0.509],[-8.064,0.981],[0,0],[0,0],[-9.446,-0.88],[0,0],[-10.502,-2.2],[-11.05,-5.525],[-0.766,11.745],[5.66,-16.851],[-15.599,-0.035],[-2.016,1.583]],"o":[[0,0],[14.276,-2.719],[0,0],[15.078,-2.46],[-12.066,0.788],[15.247,5.083],[0.883,-13.542],[-5.204,15.495],[28.1,-8.195],[1.532,-16.085],[-6.678,13.356],[13.262,0],[9.918,-5.825],[0,0],[-2.158,8.896],[19.355,-10.149],[9.78,-1.247],[-0.893,11.617],[-9.912,-1.399],[6.099,-13.245],[15.145,-1.239],[7.884,-0.959],[0,0],[0,0],[10.729,1],[0,0],[10.164,2.129],[12.423,6.212],[0.884,-13.542],[-4.553,13.559],[9.878,0.022],[0,0]],"v":[[-187.452,-42.737],[-174.88,37.534],[-150.861,-18.684],[-139.413,37.589],[-115.605,-41.153],[-102.747,24.964],[-71.062,8.04],[-94.211,9.061],[-70.73,37.677],[-25.253,-28.982],[-42.615,-32.301],[-36.232,38.678],[-2.148,2.178],[14.548,-2.029],[-12.773,17.608],[15.027,35.678],[51.708,-0.699],[67.342,18.38],[44.619,38.295],[32.237,14.423],[51.708,-0.699],[79.124,17.623],[92.418,5.764],[86.665,37.388],[107.665,2.07],[111.858,34.353],[133.077,2.635],[138.465,37.258],[179.361,8.554],[156.212,9.575],[175.587,38.838],[194.876,31.741]],"c":false}]},{"i":{"x":0.833,"y":1},"o":{"x":0.167,"y":0},"t":196,"s":[{"i":[[0,0],[-19.996,3.807],[0,0],[-18.895,3.082],[19.742,-1.29],[-24.256,-8.085],[-0.766,11.744],[5.66,-16.851],[-19.685,5.741],[-1.452,15.251],[7.149,-14.298],[-24.05,0],[-13.969,8.205],[0,0],[4.449,-18.338],[-20.828,10.921],[-24.102,3.075],[0.647,-8.405],[10.851,1.532],[-3.877,8.419],[-6.217,0.509],[-8.064,0.981],[0,0],[0,0],[-9.446,-0.88],[0,0],[-10.605,-1.634],[-11.05,-5.525],[-0.766,11.745],[5.66,-16.851],[-15.599,-0.035],[-2.016,1.583]],"o":[[0,0],[14.276,-2.719],[0,0],[15.078,-2.46],[-12.066,0.788],[15.247,5.083],[0.883,-13.542],[-5.204,15.495],[28.1,-8.195],[1.532,-16.085],[-6.678,13.356],[13.262,0],[9.918,-5.825],[0,0],[-2.158,8.896],[19.355,-10.149],[9.78,-1.247],[-0.893,11.617],[-9.912,-1.399],[6.099,-13.245],[15.145,-1.239],[7.884,-0.959],[0,0],[0,0],[10.729,1],[0,0],[12.461,1.921],[12.423,6.212],[0.884,-13.542],[-4.553,13.559],[9.878,0.022],[0,0]],"v":[[-187.452,-42.737],[-174.88,37.534],[-150.861,-18.684],[-139.413,37.589],[-115.605,-41.153],[-102.747,24.964],[-71.062,8.04],[-94.21,9.061],[-70.73,37.677],[-25.253,-28.982],[-42.615,-32.301],[-36.232,38.678],[-2.148,2.178],[14.547,-2.029],[-12.773,17.608],[15.027,35.678],[51.708,-0.699],[67.342,18.38],[44.619,38.295],[32.236,14.423],[51.708,-0.699],[79.124,17.623],[92.418,5.764],[86.665,37.388],[107.665,2.07],[111.858,35.853],[133.077,2.635],[138.465,37.258],[179.361,8.554],[156.212,9.575],[175.587,38.838],[197.876,29.741]],"c":false}]},{"t":292,"s":[{"i":[[0,0],[-19.996,3.807],[0,0],[-18.895,3.082],[19.742,-1.29],[-24.256,-8.085],[-0.766,11.744],[5.66,-16.851],[-19.685,5.741],[-1.452,15.251],[7.149,-14.298],[-24.05,0],[-13.969,8.205],[0,0],[4.449,-18.338],[-20.828,10.921],[-24.102,3.075],[0.647,-8.405],[10.851,1.532],[-3.877,8.419],[-6.217,0.509],[-8.064,0.981],[0,0],[0,0],[-9.446,-0.88],[0,0],[-10.705,-0.732],[-11.05,-5.525],[-0.766,11.745],[5.66,-16.851],[-15.599,-0.035],[-2.016,1.583]],"o":[[0,0],[14.276,-2.719],[0,0],[15.078,-2.46],[-12.066,0.788],[15.247,5.083],[0.883,-13.542],[-5.204,15.495],[28.1,-8.195],[1.532,-16.085],[-6.678,13.356],[13.262,0],[9.918,-5.825],[0,0],[-2.158,8.896],[19.355,-10.149],[9.78,-1.247],[-0.893,11.617],[-9.912,-1.399],[6.099,-13.245],[15.145,-1.239],[7.884,-0.959],[0,0],[0,0],[10.729,1],[0,0],[13.461,0.921],[12.423,6.212],[0.884,-13.542],[-4.553,13.559],[9.878,0.022],[0,0]],"v":[[-187.452,-42.737],[-174.88,37.534],[-150.861,-18.684],[-139.413,37.589],[-115.605,-41.153],[-102.747,24.964],[-71.062,8.04],[-94.211,9.061],[-70.73,37.677],[-25.253,-28.982],[-42.615,-32.301],[-36.232,38.678],[-2.148,2.178],[14.548,-2.029],[-12.773,17.608],[15.027,35.678],[51.708,-0.699],[67.342,18.38],[44.619,38.295],[32.237,14.423],[51.708,-0.699],[79.124,17.623],[92.418,5.764],[86.665,37.388],[107.665,2.07],[111.858,35.353],[133.077,2.635],[138.465,37.258],[179.361,8.554],[156.212,9.575],[175.587,38.838],[194.876,31.741]],"c":false}]}],"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"tm","s":{"a":1,"k":[{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.414],"y":[0]},"t":292,"s":[0]},{"t":470,"s":[100]}],"ix":1},"e":{"a":1,"k":[{"i":{"x":[0.588],"y":[1]},"o":{"x":[0.409],"y":[0.273]},"t":12,"s":[0]},{"t":196,"s":[100]}],"ix":2},"o":{"a":0,"k":0,"ix":3},"m":1,"ix":2,"nm":"Trim Paths 1","mn":"ADBE Vector Filter - Trim","hd":false},{"ty":"gs","o":{"a":0,"k":100,"ix":9},"w":{"a":0,"k":9,"ix":10},"g":{"p":11,"k":{"a":0,"k":[0,0.008,0.569,0.592,0.093,0.333,0.725,0.478,0.187,0.659,0.882,0.365,0.293,0.829,0.843,0.225,0.399,1,0.804,0.086,0.504,1,0.596,0.112,0.609,1,0.388,0.137,0.712,1,0.29,0.471,0.814,1,0.192,0.804,0.907,0.614,0.467,0.884,1,0.227,0.741,0.965],"ix":8}},"s":{"a":1,"k":[{"i":{"x":0.283,"y":1},"o":{"x":0.333,"y":0},"t":34,"s":[-253.742,-70.793],"to":[8.667,8.833],"ti":[-8.667,-8.833]},{"t":282,"s":[-201.742,-17.793]}],"ix":4},"e":{"a":1,"k":[{"i":{"x":0.283,"y":1},"o":{"x":0.333,"y":0},"t":34,"s":[118.488,29.074],"to":[10.667,-3.5],"ti":[-10.667,3.5]},{"t":282,"s":[182.488,8.074]}],"ix":5},"t":1,"lc":2,"lj":2,"bm":0,"nm":"Gradient Stroke 1","mn":"ADBE Vector Graphic - G-Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[217.377,69.099],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Group 1","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":608,"st":0,"bm":0}],"markers":[]}
|
requirements.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit==1.31.1
|
2 |
+
streamlit-option-menu==0.3.6
|
3 |
+
langchain==0.1.11
|
4 |
+
langchain-community==0.0.27
|
5 |
+
langchain-core==0.1.30
|
6 |
+
langchain-text-splitters==0.0.1
|
7 |
+
chromadb==0.4.24
|
8 |
+
openai==0.28.0
|
9 |
+
python-dotenv==1.0.1
|
10 |
+
python-docx==1.1.0
|
11 |
+
PyPDF2==3.0.1
|
style.css
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* style.css */
|
2 |
+
body {
|
3 |
+
background-color: #f0f2f6;
|
4 |
+
font-family: 'Arial', sans-serif;
|
5 |
+
}
|
6 |
+
|
7 |
+
.stButton>button {
|
8 |
+
width: 100%;
|
9 |
+
border-radius: 20px;
|
10 |
+
border: 1px solid #4CAF50;
|
11 |
+
background-color: #4CAF50;
|
12 |
+
color: white;
|
13 |
+
font-weight: bold;
|
14 |
+
padding: 10px 15px;
|
15 |
+
transition: all 0.3s ease;
|
16 |
+
}
|
17 |
+
|
18 |
+
.stButton>button:hover {
|
19 |
+
background-color: white;
|
20 |
+
color: #4CAF50;
|
21 |
+
}
|
22 |
+
|
23 |
+
.stTextInput>div>div>input {
|
24 |
+
border-radius: 20px;
|
25 |
+
}
|
26 |
+
|
27 |
+
.stTextArea>div>div>textarea {
|
28 |
+
border-radius: 10px;
|
29 |
+
}
|
30 |
+
|
31 |
+
.css-1d391kg {
|
32 |
+
padding-top: 3rem;
|
33 |
+
}
|
34 |
+
|
35 |
+
.stTitle {
|
36 |
+
font-size: 3rem;
|
37 |
+
color: #1E88E5;
|
38 |
+
text-align: center;
|
39 |
+
margin-bottom: 2rem;
|
40 |
+
}
|
41 |
+
|
42 |
+
.stSubheader {
|
43 |
+
font-size: 1.5rem;
|
44 |
+
color: #424242;
|
45 |
+
text-align: center;
|
46 |
+
margin-bottom: 2rem;
|
47 |
+
}
|
utills.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
lawyer_db = [
|
2 |
+
{"id": 1, "name": "Rajesh Kumar", "specialty": "Criminal", "experience": "11-20 years", "cost_range": "High", "location": "Jabalpur", "rating": 4.8, "description": "Specializes in IPC cases, has successfully defended in multiple murder trials."},
|
3 |
+
{"id": 2, "name": "Priya Sharma", "specialty": "Family", "experience": "6-10 years", "cost_range": "Medium", "location": "Bhopal", "rating": 4.5, "description": "Expert in divorce cases and child custody battles under Hindu Marriage Act."},
|
4 |
+
{"id": 3, "name": "Amit Patel", "specialty": "Corporate", "experience": "20+ years", "cost_range": "Very High", "location": "Indore", "rating": 4.9, "description": "Handled major mergers and acquisitions, expert in Company Law and SEBI regulations."},
|
5 |
+
{"id": 4, "name": "Neha Gupta", "specialty": "Immigration", "experience": "0-5 years", "cost_range": "Low", "location": "Gwalior", "rating": 4.2, "description": "Specializes in student visas and work permits for IT professionals."},
|
6 |
+
{"id": 5, "name": "Vikram Singh", "specialty": "Criminal", "experience": "11-20 years", "cost_range": "Medium", "location": "Bhopal", "rating": 4.7, "description": "Former public prosecutor, expert in cybercrime cases under IT Act."},
|
7 |
+
{"id": 6, "name": "Anita Desai", "specialty": "Family", "experience": "20+ years", "cost_range": "High", "location": "Indore", "rating": 4.6, "description": "Specializes in inter-faith marriages and Special Marriage Act cases."},
|
8 |
+
{"id": 7, "name": "Sanjay Mehta", "specialty": "Corporate", "experience": "11-20 years", "cost_range": "High", "location": "Jabalpur", "rating": 4.5, "description": "Expert in Intellectual Property Rights and patent law."},
|
9 |
+
{"id": 8, "name": "Kavita Reddy", "specialty": "Immigration", "experience": "6-10 years", "cost_range": "Medium", "location": "Bhopal", "rating": 4.3, "description": "Specializes in NRI property disputes and OCI card issues."},
|
10 |
+
{"id": 9, "name": "Arjun Malhotra", "specialty": "Criminal", "experience": "20+ years", "cost_range": "Very High", "location": "Indore", "rating": 4.9, "description": "Renowned for handling high-profile corruption cases under Prevention of Corruption Act."},
|
11 |
+
{"id": 10, "name": "Deepa Joshi", "specialty": "Family", "experience": "0-5 years", "cost_range": "Low", "location": "Gwalior", "rating": 4.1, "description": "Focuses on domestic violence cases under Protection of Women from Domestic Violence Act."},
|
12 |
+
{"id": 11, "name": "Rahul Verma", "specialty": "Corporate", "experience": "6-10 years", "cost_range": "Medium", "location": "Jabalpur", "rating": 4.4, "description": "Specializes in startup law and venture capital regulations."},
|
13 |
+
{"id": 12, "name": "Sunita Agarwal", "specialty": "Immigration", "experience": "11-20 years", "cost_range": "High", "location": "Bhopal", "rating": 4.7, "description": "Expert in handling complex deportation cases and appeals."},
|
14 |
+
{"id": 13, "name": "Kiran Bedi", "specialty": "Criminal", "experience": "20+ years", "cost_range": "Very High", "location": "Indore", "rating": 4.8, "description": "Former IPS officer, specializes in police brutality and human rights violation cases."},
|
15 |
+
{"id": 14, "name": "Vivek Chauhan", "specialty": "Family", "experience": "11-20 years", "cost_range": "High", "location": "Gwalior", "rating": 4.6, "description": "Expert in adoption cases and surrogacy law in India."},
|
16 |
+
{"id": 15, "name": "Meera Saxena", "specialty": "Corporate", "experience": "20+ years", "cost_range": "Very High", "location": "Jabalpur", "rating": 4.9, "description": "Specializes in banking law and financial regulations, handled major NPAs cases."},
|
17 |
+
{"id": 16, "name": "Alok Nath", "specialty": "Immigration", "experience": "6-10 years", "cost_range": "Medium", "location": "Bhopal", "rating": 4.3, "description": "Expert in handling asylum cases and refugee status applications."},
|
18 |
+
{"id": 17, "name": "Pooja Bhatt", "specialty": "Criminal", "experience": "0-5 years", "cost_range": "Low", "location": "Indore", "rating": 4.2, "description": "Specializes in juvenile justice cases under Juvenile Justice Act."},
|
19 |
+
{"id": 18, "name": "Rohit Sharma", "specialty": "Family", "experience": "11-20 years", "cost_range": "High", "location": "Gwalior", "rating": 4.7, "description": "Expert in handling LGBTQ+ rights cases and same-sex partnership issues."},
|
20 |
+
{"id": 19, "name": "Nandini Roy", "specialty": "Corporate", "experience": "6-10 years", "cost_range": "Medium", "location": "Jabalpur", "rating": 4.5, "description": "Specializes in environmental law and corporate social responsibility cases."},
|
21 |
+
{"id": 20, "name": "Ajay Devgan", "specialty": "Immigration", "experience": "20+ years", "cost_range": "Very High", "location": "Bhopal", "rating": 4.8, "description": "Expert in handling complex citizenship cases and constitutional challenges."},
|
22 |
+
{"id": 21, "name": "Ravi Shankar", "specialty": "Criminal", "experience": "6-10 years", "cost_range": "Medium", "location": "Jabalpur", "rating": 4.4, "description": "Specializes in white-collar crimes and economic offenses."},
|
23 |
+
{"id": 22, "name": "Anjali Kapoor", "specialty": "Family", "experience": "20+ years", "cost_range": "Very High", "location": "Bhopal", "rating": 4.8, "description": "Expert in high-net-worth divorce cases and property disputes."},
|
24 |
+
{"id": 23, "name": "Suresh Patel", "specialty": "Corporate", "experience": "0-5 years", "cost_range": "Low", "location": "Indore", "rating": 4.0, "description": "Focuses on startup incorporation and compliance issues."},
|
25 |
+
{"id": 24, "name": "Preeti Singhania", "specialty": "Immigration", "experience": "11-20 years", "cost_range": "High", "location": "Gwalior", "rating": 4.6, "description": "Specializes in business immigration and investor visas."},
|
26 |
+
{"id": 25, "name": "Arun Jaitley", "specialty": "Criminal", "experience": "20+ years", "cost_range": "Very High", "location": "Jabalpur", "rating": 4.9, "description": "Renowned for handling high-profile criminal cases and constitutional matters."},
|
27 |
+
{"id": 26, "name": "Shalini Mishra", "specialty": "Family", "experience": "6-10 years", "cost_range": "Medium", "location": "Indore", "rating": 4.3, "description": "Specializes in child rights and juvenile law."},
|
28 |
+
{"id": 27, "name": "Vijay Mallya", "specialty": "Corporate", "experience": "11-20 years", "cost_range": "High", "location": "Bhopal", "rating": 4.7, "description": "Expert in corporate restructuring and insolvency cases."},
|
29 |
+
{"id": 28, "name": "Aarti Chabria", "specialty": "Immigration", "experience": "0-5 years", "cost_range": "Low", "location": "Jabalpur", "rating": 4.1, "description": "Focuses on family-based immigration and naturalization cases."},
|
30 |
+
{"id": 29, "name": "Ranveer Kapoor", "specialty": "Criminal", "experience": "6-10 years", "cost_range": "Medium", "location": "Gwalior", "rating": 4.4, "description": "Specializes in drug-related offenses and NDPS Act cases."},
|
31 |
+
{"id": 30, "name": "Sneha Agarwal", "specialty": "Family", "experience": "11-20 years", "cost_range": "High", "location": "Bhopal", "rating": 4.6, "description": "Expert in handling complex custody battles and international family law cases."},
|
32 |
+
{"id": 31, "name": "Raj Malhotra", "specialty": "Corporate", "experience": "20+ years", "cost_range": "Very High", "location": "Indore", "rating": 4.9, "description": "Specializes in cross-border transactions and international trade law."},
|
33 |
+
{"id": 32, "name": "Zoya Khan", "specialty": "Immigration", "experience": "6-10 years", "cost_range": "Medium", "location": "Jabalpur", "rating": 4.3, "description": "Expert in handling visa appeals and deportation defense cases."},
|
34 |
+
{"id": 33, "name": "Aryan Khanna", "specialty": "Criminal", "experience": "0-5 years", "cost_range": "Low", "location": "Bhopal", "rating": 4.0, "description": "Focuses on petty crimes and first-time offender cases."},
|
35 |
+
{"id": 34, "name": "Ishaan Sharma", "specialty": "Family", "experience": "20+ years", "cost_range": "Very High", "location": "Gwalior", "rating": 4.8, "description": "Renowned for handling high-profile divorce cases involving public figures."},
|
36 |
+
{"id": 35, "name": "Aditi Rao", "specialty": "Corporate", "experience": "11-20 years", "cost_range": "High", "location": "Indore", "rating": 4.7, "description": "Specializes in corporate governance and compliance issues."},
|
37 |
+
{"id": 36, "name": "Kabir Singh", "specialty": "Immigration", "experience": "20+ years", "cost_range": "Very High", "location": "Jabalpur", "rating": 4.9, "description": "Expert in complex immigration litigation and federal court appeals."},
|
38 |
+
{"id": 37, "name": "Neha Dhupia", "specialty": "Criminal", "experience": "11-20 years", "cost_range": "High", "location": "Bhopal", "rating": 4.6, "description": "Specializes in cyber law and online fraud cases."},
|
39 |
+
{"id": 38, "name": "Rajat Kapoor", "specialty": "Family", "experience": "0-5 years", "cost_range": "Low", "location": "Indore", "rating": 4.1, "description": "Focuses on family mediation and collaborative divorce processes."},
|
40 |
+
{"id": 39, "name": "Dia Mirza", "specialty": "Corporate", "experience": "6-10 years", "cost_range": "Medium", "location": "Gwalior", "rating": 4.4, "description": "Specializes in entertainment law and intellectual property rights in media."},
|
41 |
+
{"id": 40, "name": "Farhan Akhtar", "specialty": "Immigration", "experience": "11-20 years", "cost_range": "High", "location": "Bhopal", "rating": 4.7, "description": "Expert in handling employment-based immigration and labor certification cases."}
|
42 |
+
]
|
43 |
+
|
44 |
+
|
45 |
+
def search_lawyers(category, cost_range, experience, location):
|
46 |
+
print(f"Searching for - Category: {category}, Cost Range: {cost_range}, Experience: {experience}, Location: {location}")
|
47 |
+
|
48 |
+
def find_matches(specialty_match, cost_match, experience_match, location_match):
|
49 |
+
return [
|
50 |
+
lawyer for lawyer in lawyer_db
|
51 |
+
if (specialty_match == "any" or lawyer["specialty"] == category)
|
52 |
+
and (cost_match == "any" or lawyer["cost_range"] == cost_range)
|
53 |
+
and (experience_match == "any" or lawyer["experience"] == experience)
|
54 |
+
and (location_match == "any" or lawyer["location"] == location)
|
55 |
+
]
|
56 |
+
|
57 |
+
# Try exact match
|
58 |
+
matching_lawyers = find_matches(category, cost_range, experience, location)
|
59 |
+
|
60 |
+
# Relax location
|
61 |
+
if not matching_lawyers:
|
62 |
+
matching_lawyers = find_matches(category, cost_range, experience, "any")
|
63 |
+
print("Relaxed location criteria")
|
64 |
+
|
65 |
+
# Relax cost range
|
66 |
+
if not matching_lawyers:
|
67 |
+
matching_lawyers = find_matches(category, "any", experience, "any")
|
68 |
+
print("Relaxed cost range criteria")
|
69 |
+
|
70 |
+
# Relax experience
|
71 |
+
if not matching_lawyers:
|
72 |
+
matching_lawyers = find_matches(category, "any", "any", "any")
|
73 |
+
print("Relaxed experience criteria")
|
74 |
+
|
75 |
+
# Relax specialty (return all lawyers if no matches found)
|
76 |
+
if not matching_lawyers:
|
77 |
+
matching_lawyers = find_matches("any", "any", "any", "any")
|
78 |
+
print("Relaxed all criteria")
|
79 |
+
|
80 |
+
print(f"Total matches found: {len(matching_lawyers)}")
|
81 |
+
|
82 |
+
return matching_lawyers
|