satvikjain commited on
Commit
0d592f9
·
1 Parent(s): 64530fe

added website dynamic data

Browse files
Files changed (2) hide show
  1. app.py +36 -10
  2. data.txt +9 -0
app.py CHANGED
@@ -1,6 +1,6 @@
1
-
2
  from langchain.text_splitter import CharacterTextSplitter
3
  from langchain_community.document_loaders import TextLoader
 
4
  from langchain_huggingface import HuggingFaceEmbeddings
5
  from langchain_groq import ChatGroq
6
  import langchain_community.vectorstores
@@ -15,10 +15,23 @@ import gradio as gr
15
  class ChatBot():
16
  load_dotenv()
17
  # loader = DirectoryLoader('data', glob="*.md")
18
- loader = TextLoader('data.txt', encoding = 'UTF-8')
19
- documents = loader.load()
 
 
 
 
 
 
 
 
 
 
20
  text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=600)
21
- docs = text_splitter.split_documents(documents)
 
 
 
22
 
23
  embeddings = HuggingFaceEmbeddings()
24
 
@@ -29,7 +42,7 @@ class ChatBot():
29
  )
30
 
31
  # Define Index Name
32
- index_name = "noqs-chatbot"
33
 
34
  # Checking Index
35
  if index_name not in pc.list_indexes().names():
@@ -44,26 +57,39 @@ class ChatBot():
44
 
45
  docsearch = langchain_community.vectorstores.Pinecone.from_documents(docs, embeddings, index_name=index_name)
46
  else:
47
- # Link to the existing index
48
- docsearch = langchain_community.vectorstores.Pinecone.from_existing_index(index_name, embeddings)
 
 
 
 
 
 
 
 
 
49
 
50
  # Define the repo ID and connect to a model on Groq API
51
  model_id = "llama3-8b-8192"
52
  llm = ChatGroq(
53
  model=model_id,
54
  temperature=0.5,
55
- max_tokens=600
56
  )
57
 
58
  # Creating prompt response template
59
  template = """
60
- You are a knowledgeable assistant for NoQs Digital. The Manager of our company is Mr. Adit Agarwal. Users will ask you questions about our company, and you must use the given context to answer their questions accurately. Follow these guidelines:
 
 
 
61
  Always base your answers on the provided context. Do not make up information.
62
  If the context does not contain the answer, simply say, "I don't know based on the provided information."
63
  Offer detailed and thorough responses, but stay relevant to the user's question.
64
  Maintain a professional tone in your responses.
65
  You have to answer like a Customer Care Specialist.
66
  If someone answer about program A just answer politelly that due to high demand we are currently not offering program A.
 
67
 
68
  Context: {context}
69
 
@@ -113,4 +139,4 @@ iface = gr.ChatInterface(
113
  ["Tell me the difference between your programs"]
114
  ]
115
  )
116
- iface.launch(share = True)
 
 
1
  from langchain.text_splitter import CharacterTextSplitter
2
  from langchain_community.document_loaders import TextLoader
3
+ from langchain_community.document_loaders import UnstructuredURLLoader
4
  from langchain_huggingface import HuggingFaceEmbeddings
5
  from langchain_groq import ChatGroq
6
  import langchain_community.vectorstores
 
15
  class ChatBot():
16
  load_dotenv()
17
  # loader = DirectoryLoader('data', glob="*.md")
18
+ urls = [
19
+ 'https://noqs.in/faqs/',
20
+ 'https://noqs.in/',
21
+ 'https://noqs.in/internships/'
22
+ ]
23
+
24
+ url_loader = UnstructuredURLLoader(urls=urls)
25
+ url_data = url_loader.load()
26
+
27
+ text_loader = TextLoader('data.txt', encoding = 'UTF-8')
28
+ text_data = text_loader.load()
29
+
30
  text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=600)
31
+
32
+ url_docs = text_splitter.split_documents(url_data)
33
+ text_docs = text_splitter.split_documents(text_data)
34
+ docs = url_docs + text_docs
35
 
36
  embeddings = HuggingFaceEmbeddings()
37
 
 
42
  )
43
 
44
  # Define Index Name
45
+ index_name = "noqs-chatbot-with-web-content-dynamic"
46
 
47
  # Checking Index
48
  if index_name not in pc.list_indexes().names():
 
57
 
58
  docsearch = langchain_community.vectorstores.Pinecone.from_documents(docs, embeddings, index_name=index_name)
59
  else:
60
+ # Embed the documents
61
+ pc.delete_index(index_name)
62
+ pc.create_index(name=index_name,
63
+ metric="cosine",
64
+ dimension=768,
65
+ spec=ServerlessSpec(
66
+ cloud="aws",
67
+ region="us-east-1"
68
+ ))
69
+
70
+ docsearch = langchain_community.vectorstores.Pinecone.from_documents(docs, embeddings, index_name=index_name)
71
 
72
  # Define the repo ID and connect to a model on Groq API
73
  model_id = "llama3-8b-8192"
74
  llm = ChatGroq(
75
  model=model_id,
76
  temperature=0.5,
77
+ max_tokens=1200
78
  )
79
 
80
  # Creating prompt response template
81
  template = """
82
+ You are a knowledgeable assistant for NoQs Digital.
83
+ The Manager of our company is Mr. Adit Agarwal.
84
+ Users will ask you questions about our company, and you must use the given context to answer their questions accurately.
85
+ Follow these guidelines:
86
  Always base your answers on the provided context. Do not make up information.
87
  If the context does not contain the answer, simply say, "I don't know based on the provided information."
88
  Offer detailed and thorough responses, but stay relevant to the user's question.
89
  Maintain a professional tone in your responses.
90
  You have to answer like a Customer Care Specialist.
91
  If someone answer about program A just answer politelly that due to high demand we are currently not offering program A.
92
+ Don't tell user that you are fetching the information from the context
93
 
94
  Context: {context}
95
 
 
139
  ["Tell me the difference between your programs"]
140
  ]
141
  )
142
+ iface.launch()
data.txt CHANGED
@@ -73,6 +73,10 @@ Yes, all the prices mentioned are inclusive of taxes only.
73
  Can I pay for more than 1 year at once?
74
  Yes, you can pay for more than 1 year at once. We also offer discounts for a multiple year package.
75
 
 
 
 
 
76
 
77
  How do I manage and update my app?
78
  As part of your package, you get your own admin panel (personal subdomain) which you can use to modify, update and manage the app.
@@ -204,6 +208,11 @@ Want to Apply Now?
204
  If you want to join Program A, click here[https://noqs.in/iaf/] (Applications currently closed for May, June and July due to high volume)
205
  If you want to join Program A, click here[https://noqs.in/liaf] (Filling fast for May, June and July. BOOK YOUR SEAT NOW)
206
 
 
 
 
 
 
207
  Both programs are designed to help you gain valuable experience and develop new skills, but Program B offers some extra benefits that we think you’ll love.
208
 
209
  Here are some of the differences:
 
73
  Can I pay for more than 1 year at once?
74
  Yes, you can pay for more than 1 year at once. We also offer discounts for a multiple year package.
75
 
76
+ Who created the NoQs Digital ChatBot?
77
+ Who made the NoQs Digital Chatbot?
78
+ Wh made you?
79
+ Satvik Jain created me.
80
 
81
  How do I manage and update my app?
82
  As part of your package, you get your own admin panel (personal subdomain) which you can use to modify, update and manage the app.
 
208
  If you want to join Program A, click here[https://noqs.in/iaf/] (Applications currently closed for May, June and July due to high volume)
209
  If you want to join Program A, click here[https://noqs.in/liaf] (Filling fast for May, June and July. BOOK YOUR SEAT NOW)
210
 
211
+ Link for registeration is https://noqs.in/iaf/
212
+ Link for Enrollement is https://noqs.in/iaf/
213
+ Link to join NoQs as an intern is https://noqs.in/iaf/
214
+
215
+
216
  Both programs are designed to help you gain valuable experience and develop new skills, but Program B offers some extra benefits that we think you’ll love.
217
 
218
  Here are some of the differences: