Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,10 @@ import gradio as gr
|
|
9 |
import os
|
10 |
import pytesseract
|
11 |
from PIL import Image
|
12 |
-
import pickle
|
|
|
|
|
|
|
13 |
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
14 |
index = faiss.read_index('IPC_index.faiss')
|
15 |
index2 = faiss.read_index('CrpC_index.faiss')
|
@@ -26,6 +29,13 @@ with open('CrPC_F.pkl', 'rb') as f:
|
|
26 |
with open('CrPC_C.pkl', 'rb') as f:
|
27 |
chunk_indices2 = pickle.load(f)
|
28 |
# Step 3: Retrieval with Citations using PDF filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
def retrieve_info_with_citation(query, top_k=5):
|
30 |
query_embedding = model.encode([query])
|
31 |
D, I = index.search(query_embedding, k=top_k)
|
@@ -319,9 +329,13 @@ doj_tool=Tool(
|
|
319 |
func=doj_info,
|
320 |
description="Provides Summarized Information about Department of Justice."
|
321 |
)
|
322 |
-
|
323 |
-
|
324 |
-
|
|
|
|
|
|
|
|
|
325 |
max_tokens=None,
|
326 |
timeout=None,
|
327 |
max_retries=2,
|
@@ -345,7 +359,7 @@ llm = ChatGoogleGenerativeAI(
|
|
345 |
"""
|
346 |
)
|
347 |
|
348 |
-
agent_tools = [ipc_tool,crpc_tool,doj_tool]
|
349 |
|
350 |
agent = initialize_agent(
|
351 |
tools=agent_tools,
|
|
|
9 |
import os
|
10 |
import pytesseract
|
11 |
from PIL import Image
|
12 |
+
import pickle
|
13 |
+
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
|
14 |
+
# Load the CSV data as a DataFrame
|
15 |
+
df = pd.read_csv("hf://datasets/kshitij230/Indian-Law/Indian-Law.csv")
|
16 |
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
17 |
index = faiss.read_index('IPC_index.faiss')
|
18 |
index2 = faiss.read_index('CrpC_index.faiss')
|
|
|
29 |
with open('CrPC_C.pkl', 'rb') as f:
|
30 |
chunk_indices2 = pickle.load(f)
|
31 |
# Step 3: Retrieval with Citations using PDF filename
|
32 |
+
def retrieve_faq(query):
|
33 |
+
relevant_rows = df[df['Instruction'].str.contains(query, case=False)]
|
34 |
+
if not relevant_rows.empty:
|
35 |
+
response = relevant_rows.iloc[0]['Response']
|
36 |
+
return response
|
37 |
+
else:
|
38 |
+
return "Sorry, I couldn't find relevant FAQs for your query."
|
39 |
def retrieve_info_with_citation(query, top_k=5):
|
40 |
query_embedding = model.encode([query])
|
41 |
D, I = index.search(query_embedding, k=top_k)
|
|
|
329 |
func=doj_info,
|
330 |
description="Provides Summarized Information about Department of Justice."
|
331 |
)
|
332 |
+
faq_tool=Tool(
|
333 |
+
name="Commonly Asked Questions",
|
334 |
+
func=retrieve_faq,
|
335 |
+
description="Provides Answers to commonly asked questions related to query keyword(s)"
|
336 |
+
)
|
337 |
+
llm = HuggingFaceEndpoint(
|
338 |
+
model="meta-llama/Meta-Llama-3-8B",
|
339 |
max_tokens=None,
|
340 |
timeout=None,
|
341 |
max_retries=2,
|
|
|
359 |
"""
|
360 |
)
|
361 |
|
362 |
+
agent_tools = [ipc_tool,crpc_tool,doj_tool,faq_tool]
|
363 |
|
364 |
agent = initialize_agent(
|
365 |
tools=agent_tools,
|