Update app.py
Browse files
app.py
CHANGED
@@ -97,22 +97,26 @@ llm = ChatGoogleGenerativeAI(
|
|
97 |
max_tokens=None,
|
98 |
timeout=None,
|
99 |
max_retries=2,
|
100 |
-
|
|
|
101 |
You are a highly specialized legal assistant with deep knowledge of the Indian Penal Code (IPC).
|
102 |
Your primary task is to retrieve and summarize legal information accurately from the IPC.pdf document provided to you.
|
|
|
103 |
Your responses should be highly specific, fact-based, and free from any speculation or hallucinations.
|
104 |
Always cite the exact section from the IPC when providing an answer.
|
105 |
If the information is not available in the document, clearly state that and do not make any assumptions.
|
|
|
|
|
106 |
|
107 |
Example task: "What is the punishment for theft according to the IPC?"
|
108 |
Example response: "According to Section 379 of the IPC, the punishment for theft is imprisonment of either description for a term which may extend to three years, or with fine, or with both."
|
|
|
|
|
109 |
|
110 |
-
Task: {{
|
111 |
|
112 |
Response:
|
113 |
-
"""
|
114 |
-
)
|
115 |
-
|
116 |
agent_tools = [ipc_tool,crpc_tool]
|
117 |
|
118 |
agent = initialize_agent(
|
@@ -125,7 +129,8 @@ agent = initialize_agent(
|
|
125 |
)
|
126 |
def encode_image_to_base64(image_path):
|
127 |
return pytesseract.image_to_string(Image.open(image_path))
|
128 |
-
def chatbot_response(query):
|
|
|
129 |
if query.get('files'):
|
130 |
# Encode image to base64
|
131 |
image_data=""
|
@@ -144,7 +149,7 @@ def chatbot_response(query):
|
|
144 |
message = HumanMessage(content=[{"type": "text", "text": query}])
|
145 |
|
146 |
# Invoke the model with the multimodal message
|
147 |
-
result = agent.invoke(
|
148 |
response = result['output']
|
149 |
intermediate_steps = result.get('intermediate_steps', [])
|
150 |
|
@@ -158,7 +163,7 @@ def chatbot_response(query):
|
|
158 |
# Step 5: Gradio Interface
|
159 |
from gradio import ChatMessage
|
160 |
def chatbot_interface(messages,prompt):
|
161 |
-
response, thought_process = chatbot_response(prompt)
|
162 |
#messages.append(ChatMessage(role="user", content=prompt))
|
163 |
|
164 |
for x in prompt["files"]:
|
|
|
97 |
max_tokens=None,
|
98 |
timeout=None,
|
99 |
max_retries=2,
|
100 |
+
)
|
101 |
+
prompt="""
|
102 |
You are a highly specialized legal assistant with deep knowledge of the Indian Penal Code (IPC).
|
103 |
Your primary task is to retrieve and summarize legal information accurately from the IPC.pdf document provided to you.
|
104 |
+
Keep the conversation Topic related to Department of Justice
|
105 |
Your responses should be highly specific, fact-based, and free from any speculation or hallucinations.
|
106 |
Always cite the exact section from the IPC when providing an answer.
|
107 |
If the information is not available in the document, clearly state that and do not make any assumptions.
|
108 |
+
|
109 |
+
|
110 |
|
111 |
Example task: "What is the punishment for theft according to the IPC?"
|
112 |
Example response: "According to Section 379 of the IPC, the punishment for theft is imprisonment of either description for a term which may extend to three years, or with fine, or with both."
|
113 |
+
|
114 |
+
History:{{}}
|
115 |
|
116 |
+
Task: {{}}
|
117 |
|
118 |
Response:
|
119 |
+
"""
|
|
|
|
|
120 |
agent_tools = [ipc_tool,crpc_tool]
|
121 |
|
122 |
agent = initialize_agent(
|
|
|
129 |
)
|
130 |
def encode_image_to_base64(image_path):
|
131 |
return pytesseract.image_to_string(Image.open(image_path))
|
132 |
+
def chatbot_response(m,query):
|
133 |
+
|
134 |
if query.get('files'):
|
135 |
# Encode image to base64
|
136 |
image_data=""
|
|
|
149 |
message = HumanMessage(content=[{"type": "text", "text": query}])
|
150 |
|
151 |
# Invoke the model with the multimodal message
|
152 |
+
result = agent.invoke(prompt.format(m,message))
|
153 |
response = result['output']
|
154 |
intermediate_steps = result.get('intermediate_steps', [])
|
155 |
|
|
|
163 |
# Step 5: Gradio Interface
|
164 |
from gradio import ChatMessage
|
165 |
def chatbot_interface(messages,prompt):
|
166 |
+
response, thought_process = chatbot_response(messages,prompt)
|
167 |
#messages.append(ChatMessage(role="user", content=prompt))
|
168 |
|
169 |
for x in prompt["files"]:
|