TusharsinghBaghel commited on
Commit
befa928
1 Parent(s): 503e330

Upload 6 files

Browse files
.env ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ '''
2
+ LANGCHAIN_API_KEY="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"
3
+ GROQ_API_KEY="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"
4
+ LANGCHAIN_PROJECT="try"
5
+ '''
Faiss_index/index.faiss ADDED
Binary file (903 kB). View file
 
Faiss_index/index.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bd5de032dd6d0e0f86fddbe8b2feae0c725f9b4d73c788e94a10789adea59205
3
+ size 813439
__pycache__/main.cpython-39.pyc ADDED
Binary file (2.97 kB). View file
 
main.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
4
+
5
+ import warnings
6
+ from langchain_groq import ChatGroq
7
+ from langchain_community.embeddings import OllamaEmbeddings
8
+ from langchain_community.embeddings import HuggingFaceEmbeddings
9
+
10
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
11
+
12
+ from langchain.chains.combine_documents import create_stuff_documents_chain
13
+ from langchain_core.prompts import ChatPromptTemplate
14
+ from langchain.chains import create_retrieval_chain
15
+ from langchain_community.vectorstores import FAISS
16
+ from langchain_community.document_loaders import PyPDFDirectoryLoader
17
+ from typing import Any
18
+ from langchain.agents import AgentExecutor
19
+ from langchain_core.tools import tool
20
+
21
+ from dotenv import load_dotenv
22
+ from fastapi.middleware.cors import CORSMiddleware
23
+
24
+ load_dotenv()
25
+ groq_api_key=os.getenv('GROQ_API_KEY')
26
+
27
+
28
+ warnings.filterwarnings('ignore')
29
+
30
+ llm=ChatGroq(groq_api_key=groq_api_key,
31
+ model_name="mixtral-8x7b-32768")
32
+
33
+ prompt=ChatPromptTemplate.from_template(
34
+ """
35
+ You are a Mineral Exploration assistant.You are given a context and an input query. Use the context to answer the query.
36
+ <context>
37
+ {context}
38
+ <context>
39
+ Questions:{input}
40
+
41
+ """
42
+ )
43
+
44
+ def vector_embedding():
45
+
46
+ if "vectors" not in st.session_state:
47
+
48
+
49
+ print("Embeddings defined")
50
+ loader=PyPDFDirectoryLoader("./rules_regulations") ## Data Ingestion
51
+ docs=loader.load() ## Document Loading
52
+ print("PDF loaded")
53
+ text_splitter=RecursiveCharacterTextSplitter(chunk_size=4000,chunk_overlap=500) ## Chunk Creation
54
+ print("Chunks created")
55
+ final_documents=text_splitter.split_documents(docs) #splitting
56
+ print("Splitting done")
57
+ vectors=FAISS.from_documents(final_documents,embeddings) #vector embeddings
58
+ vectors.save_local("Faiss_index")
59
+ print("Embeddings created")
60
+ else:
61
+ print("Faiss index already exist")
62
+
63
+
64
+
65
+
66
+
67
+ embeddings=HuggingFaceEmbeddings()
68
+ vectors = FAISS.load_local("Faiss_index", embeddings, allow_dangerous_deserialization=True)
69
+
70
+ def Get_Rag_Response(query):
71
+ if query:
72
+ print("Got query:")
73
+ print(query)
74
+ document_chain=create_stuff_documents_chain(llm,prompt)
75
+ retriever=vectors.as_retriever()
76
+ print("Retrieved docs")
77
+ retrieval_chain=create_retrieval_chain(retriever,document_chain)
78
+ response=retrieval_chain.invoke({'input':query})
79
+ return response
80
+
81
+ else:
82
+ print("Error: No query passed")
83
+
84
+ iface= gr.Interface(fn = Get_Rag_Response,
85
+ inputs = ["text"],
86
+ outputs = ['text'],
87
+ title = "Rag_Response",
88
+ description="Get RAG chatbot response")
89
+
90
+ iface.launch(inline=False)
requirements.txt ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ langchain_core
2
+ python-dotenv
3
+ streamlit
4
+ langchain_community
5
+ sse_starlette
6
+ bs4
7
+ pypdf
8
+ faiss-cpu
9
+ groq
10
+ cassio
11
+ beautifulsoup4
12
+ langchain-groq
13
+ langchainhub
14
+ langchain
15
+ sentence_transformers
16
+ sentence-transformers
17
+ InstructorEmbedding
18
+ torch
19
+ urllib3<2
20
+ requests
21
+ gradio