Shashank1406 commited on
Commit
925601e
1 Parent(s): c76d752

Upload 6 files

Browse files
Files changed (6) hide show
  1. Functions.py +133 -0
  2. Prompts_and_Chains.py +63 -0
  3. Templates.py +128 -0
  4. app.py +122 -0
  5. requirements.txt +14 -0
  6. utills.py +89 -0
Functions.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 process_case_data(self, case_name, files):
66
+ if case_name and files:
67
+ # Generate a unique identifier for the case data set
68
+ case_id = str(uuid.uuid4())
69
+ extracted_data = []
70
+ all_texts = []
71
+ for file in files:
72
+ file_text = []
73
+ if file.name.endswith(".docx"):
74
+ file_text = read_docx(file)
75
+ elif file.name.endswith(".pdf"):
76
+ file_text = get_pdf_text(file)
77
+ else:
78
+ file_text = extract_text_from_file(file)
79
+
80
+ text_splitter = CharacterTextSplitter(
81
+ separator="\n", chunk_size=1000, chunk_overlap=150, length_function=len
82
+ )
83
+ texts = text_splitter.split_text(" ".join(file_text))
84
+
85
+ all_texts.extend(texts)
86
+ extracted_data.append(" ".join(file_text))
87
+
88
+ project_dir = os.path.dirname(os.path.abspath(__file__))
89
+ vectorstore = Chroma(
90
+ persist_directory=os.path.join(
91
+ project_dir, "vector_stores", case_name),
92
+ embedding_function=OpenAIEmbeddings(
93
+ openai_api_key=self.openai_api_key),
94
+ )
95
+ vectorstore.add_texts(all_texts)
96
+
97
+ st.session_state[case_id] = {
98
+ "vectorstore": vectorstore,
99
+ "extracted_data": extracted_data,
100
+ }
101
+ all_text = " ".join(extracted_data)
102
+ st.session_state["case_summary"] = self.chains_obj.case_summary_chain.run(
103
+ {
104
+ "case_name": case_name,
105
+ "case_info": dedent(all_text),
106
+ }
107
+ )
108
+ st.session_state["is_data_processed"] = True
109
+ st.session_state["case_name"] = case_name
110
+ st.session_state["case_details"] = dedent(all_text)
111
+ st.session_state["current_case_id"] = case_id
112
+ st.success("Data processed successfully")
113
+
114
+ def genrate_legal_bot_result(self):
115
+ if len(st.session_state["bot_input"]) > 0:
116
+ case_id = st.session_state.get("current_case_id")
117
+ if case_id:
118
+ vector_store = st.session_state[case_id]["vectorstore"]
119
+ query = st.session_state["bot_input"]
120
+ results = vector_store.similarity_search(query, 3)
121
+ # get the text from the results
122
+ source_knowledge = "\n".join([x.page_content for x in results])
123
+ inputs = {
124
+ "case_summary":st.session_state["case_summary"],
125
+ "context": source_knowledge,
126
+ "input": query,
127
+ }
128
+ output = self.chains_obj.legal_case_bot_chain.run(inputs)
129
+ st.session_state.past_bot_results.append(st.session_state["bot_input"])
130
+ st.session_state.generated_bot_results.append(output)
131
+ st.session_state["bot_input"] = ""
132
+ else:
133
+ 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
+ import streamlit as st
9
+
10
+
11
+ class PromptTemplates:
12
+ def __init__(self):
13
+
14
+ self.legal_adviser_bot_prompt = PromptTemplate(
15
+ input_variables=["chat_history","input",], template=legal_adviser_template
16
+ )
17
+
18
+ self.case_summary_prompt = PromptTemplate(
19
+ input_variables=["case_name", "case_info"], template=case_summary_template
20
+ )
21
+
22
+ self.legal_case_bot_prompt = PromptTemplate(
23
+ input_variables=["case_summary", "context","input"], template=legal_case_bot_template
24
+ )
25
+
26
+ self.lawyer_recommendations_prompt = PromptTemplate(
27
+ input_variables=["user_inputs", "matching_lawyers", "additional_info"], template=lawyer_recommendation_template
28
+ )
29
+
30
+
31
+ class LLMChains:
32
+ def __init__(self):
33
+ load_dotenv()
34
+ openai_api_key = os.getenv("OPENAI_API_KEY")
35
+ obj = PromptTemplates()
36
+ model_name = st.session_state["selected_model"]
37
+
38
+ # generate summary chain
39
+ self.legal_adviser_bot_chain = LLMChain(
40
+ llm=OpenAI(model_name='gpt-3.5-turbo-16k', temperature=0.7),
41
+ prompt=obj.legal_adviser_bot_prompt,
42
+ verbose="true",
43
+ )
44
+
45
+ # genrate bot conversastion
46
+ self.case_summary_chain = LLMChain(
47
+ llm=OpenAI(model_name=model_name, temperature=0.7),
48
+ prompt=obj.case_summary_prompt,
49
+ verbose="true",
50
+ )
51
+
52
+ # genrate bot conversastion
53
+ self.legal_case_bot_chain = LLMChain(
54
+ llm=OpenAI(model_name=model_name, temperature=0.7),
55
+ prompt=obj.legal_case_bot_prompt,
56
+ verbose="true",
57
+ )
58
+
59
+ self.lawyer_recommendations_chain = LLMChain(
60
+ llm=OpenAI(model_name="gpt-3.5-turbo-16k", temperature=0.7),
61
+ prompt=obj.lawyer_recommendations_prompt,
62
+ verbose="true",
63
+ )
Templates.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ******* THIS FILE CONTAINS ALL THE TEMPLATES USED IN APP.PY ***********
2
+
3
+
4
+ case_summary_template = """
5
+ You are an experienced legal expert with a comprehensive understanding of various areas of law. Your background includes:
6
+
7
+ - Over 20 years of experience in legal practice and analysis
8
+ - Expertise in multiple fields including civil law, criminal law, corporate law, and constitutional law
9
+ - A track record of successfully summarizing complex legal cases for both legal professionals and laypeople
10
+ - An ability to identify key legal issues and present them clearly and concisely
11
+
12
+ Your task is to summarize the following case information. In your summary, please include:
13
+
14
+ 1. Key parties involved
15
+ 2. Main legal issues at stake
16
+ 3. Important facts that are crucial to the case
17
+ 4. Procedural history (how the case has progressed through the legal system)
18
+ 5. Outcome or current status of the case
19
+
20
+ Focus on the most crucial information and present it in a clear, organized manner. Use your expertise to highlight any particularly significant or unusual aspects of the case.
21
+
22
+ Case Name :{case_name}
23
+ Case infromation:{case_info}
24
+
25
+ """
26
+
27
+ legal_case_bot_template = """
28
+ You are a highly knowledgeable legal expert with extensive experience in case analysis and legal consultation. Your role is to assist with questions related to the following case:
29
+
30
+ Case Summary:
31
+ {case_summary}
32
+
33
+ Additional Context:
34
+ {context}
35
+
36
+ Drawing upon your expertise and the information provided, please answer the following question accurately and concisely. If the answer cannot be determined from the available information, clearly state this and explain what additional information would be needed to provide a complete answer.
37
+ User Question: {input}
38
+ Assistant:"""
39
+
40
+
41
+ # legal_adviser_template = """
42
+ # 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.
43
+
44
+ # Your capabilities:
45
+ # 1. Answer questions about general legal concepts and definitions in Indian law
46
+ # 2. Provide basic information on different areas of Indian law
47
+ # 3. Explain legal procedures and processes in the Indian legal system
48
+ # 4. Help users understand Indian legal documents
49
+ # 5. Offer information on legal rights and responsibilities under Indian law
50
+
51
+ # Your limitations:
52
+ # 1. You cannot provide personalized legal advice
53
+ # 2. You are not a licensed attorney in India
54
+ # 3. Your responses should not be considered as legal counsel
55
+
56
+ # Guidelines:
57
+ # 1. Always maintain a professional and neutral tone
58
+ # 2. If a question is unclear, ask for clarification
59
+ # 3. If a query is outside the scope of Indian legal matters, politely explain that you can only assist with Indian law-related questions
60
+ # 4. Remind users not to share personal or confidential information
61
+ # 5. If a question requires legal expertise beyond general knowledge of Indian law, advise the user to consult with a qualified Indian lawyer
62
+
63
+ # For off-topic questions, respond with:
64
+ # "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?"
65
+
66
+ # Remember, your primary function is to provide helpful, accurate, and general information about Indian law while clearly communicating your limitations as an AI assistant.
67
+
68
+ # User Query: {input}
69
+
70
+ # Please respond to the above user query following all the guidelines provided, focusing specifically on Indian law.
71
+ # """
72
+
73
+ legal_adviser_template = """
74
+ You are LegalAssist, an AI chatbot specializing in legal information and you personality is legal assiatant. Your purpose is to provide general information about law and legal matters. Always begin your interaction with a brief introduction explaining your role and limitations.
75
+
76
+ Your capabilities:
77
+ 1. Answer questions about general legal concepts and definitions
78
+ 2. Provide basic information on different areas of law
79
+ 3. Explain legal procedures and processes
80
+ 4. Help users understand legal documents
81
+ 5. Offer information on legal rights and responsibilities
82
+ 6. Provide information about different types of lawyers and their roles
83
+ 7. Explain sections of the Indian Penal Code (IPC)
84
+ 8. Provide details about various acts and laws in India
85
+ 9. Explain articles of the Indian Constitution
86
+ 10. Provide information on amendments to Indian laws
87
+ 11. you have the capability to remember previous questions
88
+
89
+ Your limitations:
90
+ 1. You cannot provide personalized legal advice
91
+ 2. You are not a licensed attorney
92
+ 3. Your responses should not be considered as legal counsel
93
+
94
+ Guidelines:
95
+ 1. Always maintain a professional and neutral tone
96
+ 2. If a question is unclear, ask for clarification
97
+ 3. If a query is outside the scope of your personality apologize for that
98
+ 4. Remind users not to share personal or confidential information
99
+ 5. If a question requires legal expertise beyond general knowledge, advise the user to consult with a qualified lawyer
100
+ 6. Ensure your chatbot can handle follow-up questions and provide clarifications and use privous chat given blow.
101
+ 7. Ensure the chatbot's ability to handle common variations of questions.
102
+
103
+
104
+ For off-topic questions, respond with:
105
+ "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 law and legal matters. Is there a legal topic you'd like information about?"
106
+
107
+ Remember, your primary function is to provide helpful, accurate, and general legal information while clearly communicating your limitations as an AI assistant.
108
+
109
+ {chat_history}
110
+
111
+ use this chat_history to answer the follow up questions and previous questions
112
+
113
+ Human: {input}
114
+ Assistant:
115
+ """
116
+
117
+
118
+ lawyer_recommendation_template = """
119
+ Based on the user's inputs and the matching lawyers, provide a recommendation for the best lawyer(s).
120
+ Consider the user's specific needs mentioned in the additional information, and pay special attention to the lawyers' descriptions and expertise.
121
+
122
+ User inputs: {user_inputs}
123
+ Matching lawyers: {matching_lawyers}
124
+ Additional information: {additional_info}
125
+
126
+ 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.
127
+
128
+ """
app.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ import os
3
+ import streamlit as st
4
+ from streamlit_option_menu import option_menu
5
+ from Functions import RFPProcessor
6
+
7
+ from utills import ( on_click_toggle)
8
+
9
+
10
+ # Initialize session states for rfp data (data processing)
11
+ if "vectorstore" not in st.session_state:
12
+ st.session_state["vectorstore"] = None
13
+ if "pdf_details" not in st.session_state:
14
+ st.session_state["pdf_details"] = ""
15
+ if "is_data_processed" not in st.session_state:
16
+ st.session_state["is_data_processed"] = False
17
+
18
+
19
+ # Initialize session states for summary bot
20
+ if "generated_bot_results" not in st.session_state:
21
+ st.session_state["generated_bot_results"] = []
22
+ if "past_bot_results" not in st.session_state:
23
+ st.session_state["past_bot_results"] = []
24
+ if "bot_input" not in st.session_state:
25
+ st.session_state["bot_input"] = ""
26
+
27
+
28
+ # Initialize session states for case
29
+ if "case_summary" not in st.session_state:
30
+ st.session_state["case_summary"] = ""
31
+
32
+ if "selected_model" not in st.session_state:
33
+ st.session_state["selected_model"] = "gpt-3.5-turbo-16k"
34
+
35
+
36
+ def main():
37
+ st.set_page_config(page_title="Justice League",
38
+ page_icon="⚖️", layout="wide")
39
+ top_left_container = st.sidebar.container()
40
+ model_name = "GPT-4o" if st.session_state["selected_model"] == "gpt-4o" else "GPT-3.5-turbo"
41
+ st.markdown(
42
+ """
43
+ <style>
44
+ .st-ae.st-af.st-ag.st-ah.st-ai.st-aj.st-ak.st-al.st-am {
45
+ position: absolute !important;
46
+ top: -80px !important;
47
+ z-index: 9999;
48
+ }
49
+ </style>
50
+ """,
51
+ unsafe_allow_html=True
52
+ )
53
+ with top_left_container:
54
+ st.markdown("<div style='margin-bottom: -10px; font-size: 15px; position: absolute; z-index: 1; top: -91px; left: 3px'>Toggle for Model Selection</div>", unsafe_allow_html=True)
55
+ st.markdown("<div style='margin-bottom: -10px; font-size: 15px; position: absolute; z-index: 1; top: -87px; left: 3px'>(Default : GPT-3.5)</div>", unsafe_allow_html=True)
56
+ st.toggle(model_name, value=st.session_state["selected_model"] == "gpt-4o", key="model_toggle", on_change=on_click_toggle, args=None, disabled=False, label_visibility="visible")
57
+
58
+ function = RFPProcessor()
59
+
60
+ with st.sidebar:
61
+ menu_choice = option_menu(
62
+ menu_title="Legal Assistant",
63
+ options=[
64
+ "Home",
65
+ "Legal Bot",
66
+ ],
67
+ icons=["house", "list-task"],
68
+ )
69
+
70
+
71
+ if menu_choice == "Home":
72
+ with st.form("my_form"):
73
+ case_name = st.text_input(
74
+ "Case Name",
75
+ key="Case Name",
76
+ type="default",
77
+ placeholder="Case Name",
78
+ )
79
+ files = st.file_uploader(
80
+ "Document", type=["pdf", "txt", "docx"], accept_multiple_files=True
81
+ )
82
+
83
+ submitted = st.form_submit_button("Process Data")
84
+
85
+ if submitted:
86
+ if case_name and files:
87
+ function.process_case_data(case_name, files)
88
+ else:
89
+ st.warning(
90
+ "project_name and file are required to create create stories",
91
+ icon="⚠️",
92
+ )
93
+ if st.session_state["is_data_processed"] == True:
94
+ st.title("Summary")
95
+ with st.container():
96
+ st.markdown(st.session_state["case_summary"])
97
+
98
+ if menu_choice == "Legal Bot":
99
+ if st.session_state["is_data_processed"] == True:
100
+ st.title(" Legal Bot ")
101
+ st.subheader(" Powered by Coffeebeans")
102
+ st.text_input(
103
+ "You: ",
104
+ st.session_state["bot_input"],
105
+ key="bot_input",
106
+ placeholder="Your AI Case assistant here! Ask me Queries related to Case",
107
+ on_change=function.genrate_legal_bot_result(),
108
+ label_visibility="hidden",
109
+ )
110
+ with st.container():
111
+ for i in range(len(st.session_state["generated_bot_results"]) - 1, -1, -1):
112
+ st.success(st.session_state["generated_bot_results"][i], icon="🤖")
113
+ st.info(st.session_state["past_bot_results"][i], icon="🧐")
114
+ else:
115
+ st.warning("Plesase Process Case Details to access this logal case bot", icon="⚠️")
116
+
117
+
118
+ if __name__ == "__main__":
119
+
120
+ main()
121
+
122
+
requirements.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ streamlit==1.31.1
2
+ streamlit-option-menu==0.3.6
3
+ streamlit-chat==0.1.1
4
+ streamlit-lottie==0.0.5
5
+ langchain==0.1.11
6
+ langchain-community==0.0.27
7
+ langchain-core==0.1.30
8
+ langchain-text-splitters==0.0.1
9
+ chromadb==0.4.24
10
+ openai==0.28.0
11
+ python-dotenv==1.0.1
12
+ python-docx==1.1.0
13
+ PyPDF2==3.0.1
14
+ tiktoken==0.7.0
utills.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ lawyer_db = [
4
+ {"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."},
5
+ {"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."},
6
+ {"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."},
7
+ {"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."},
8
+ {"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."},
9
+ {"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."},
10
+ {"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."},
11
+ {"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."},
12
+ {"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."},
13
+ {"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."},
14
+ {"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."},
15
+ {"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."},
16
+ {"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."},
17
+ {"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."},
18
+ {"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."},
19
+ {"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."},
20
+ {"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."},
21
+ {"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."},
22
+ {"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."},
23
+ {"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."},
24
+ {"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."},
25
+ {"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."},
26
+ {"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."},
27
+ {"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."},
28
+ {"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."},
29
+ {"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."},
30
+ {"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."},
31
+ {"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."},
32
+ {"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."},
33
+ {"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."},
34
+ {"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."},
35
+ {"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."},
36
+ {"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."},
37
+ {"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."},
38
+ {"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."},
39
+ {"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."},
40
+ {"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."},
41
+ {"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."},
42
+ {"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."},
43
+ {"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."}
44
+ ]
45
+
46
+
47
+ def search_lawyers(category, cost_range, experience, location):
48
+ print(f"Searching for - Category: {category}, Cost Range: {cost_range}, Experience: {experience}, Location: {location}")
49
+
50
+ def find_matches(specialty_match, cost_match, experience_match, location_match):
51
+ return [
52
+ lawyer for lawyer in lawyer_db
53
+ if (specialty_match == "any" or lawyer["specialty"] == category)
54
+ and (cost_match == "any" or lawyer["cost_range"] == cost_range)
55
+ and (experience_match == "any" or lawyer["experience"] == experience)
56
+ and (location_match == "any" or lawyer["location"] == location)
57
+ ]
58
+
59
+ # Try exact match
60
+ matching_lawyers = find_matches(category, cost_range, experience, location)
61
+
62
+ # Relax location
63
+ if not matching_lawyers:
64
+ matching_lawyers = find_matches(category, cost_range, experience, "any")
65
+ print("Relaxed location criteria")
66
+
67
+ # Relax cost range
68
+ if not matching_lawyers:
69
+ matching_lawyers = find_matches(category, "any", experience, "any")
70
+ print("Relaxed cost range criteria")
71
+
72
+ # Relax experience
73
+ if not matching_lawyers:
74
+ matching_lawyers = find_matches(category, "any", "any", "any")
75
+ print("Relaxed experience criteria")
76
+
77
+ # Relax specialty (return all lawyers if no matches found)
78
+ if not matching_lawyers:
79
+ matching_lawyers = find_matches("any", "any", "any", "any")
80
+ print("Relaxed all criteria")
81
+
82
+ print(f"Total matches found: {len(matching_lawyers)}")
83
+
84
+ return matching_lawyers
85
+
86
+ def on_click_toggle():
87
+ st.session_state.update({
88
+ "selected_model": "gpt-4o" if st.session_state["selected_model"] == "gpt-3.5-turbo-16k" else "gpt-3.5-turbo-16k"
89
+ })