vedsadani commited on
Commit
7b1dcbe
·
verified ·
1 Parent(s): 03d3a20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -21,11 +21,11 @@ embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-
21
  vector_store= FAISS.load_local("vector_db/", embeddings)
22
 
23
  repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1"
24
- llm = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature": 0.01, "max_new_tokens": 2048})
25
 
26
  retriever = vector_store.as_retriever(
27
  search_type="similarity",
28
- search_kwargs={"k":3, "include_metadata": True}
29
  )
30
 
31
  df=pd.read_csv('data/Gretel_Data.csv')
@@ -131,14 +131,12 @@ network_features = {
131
  ]
132
  }
133
 
134
-
135
-
136
  def echo(message, history):
137
  try:
138
  qa=RetrievalQA.from_chain_type(llm=llm, retriever=retriever, return_source_documents=True)
139
- message= "You are a senior telecom network engineer having access to troubleshooting tickets data and other technical and product documentation. Stick to the knowledge provided. Ask clarification questions if needed. Return only the helpful answer" + message
140
  result= qa({"query":message})
141
- answer= result['result'].split('Helpful Answer: ')[1]
142
  for word in target_words:
143
  if re.search(r'\b' + re.escape(word) + r'\b', answer, flags=re.IGNORECASE):
144
  columns.extend(network_features.get(word, []))
@@ -164,11 +162,13 @@ def echo(message, history):
164
 
165
  gr.Dataframe(styled_df)
166
  return (
167
- answer + '\n'
168
- + '\n' + "Sources: \n"
169
- + '\n' + '1. ' + result['source_documents'][0].metadata['source'] + ' Row: ' +str(result['source_documents'][0].metadata['row']) + '\n' + result['source_documents'][0].page_content + "\n"
170
- + '\n' + '2. ' + result['source_documents'][1].metadata['source'] + ' Row: ' +str(result['source_documents'][1].metadata['row']) + '\n' + result['source_documents'][1].page_content + "\n"
171
- + '\n' + "3. " + result['source_documents'][2].metadata['source'] + ' Row: ' +str(result['source_documents'][2].metadata['row']) + '\n' + result['source_documents'][2].page_content,
 
 
172
  styled_df
173
  )
174
  except Exception as e:
@@ -218,9 +218,12 @@ with demo_agent:
218
 
219
  gr.Examples([
220
  "Wi-Fi connected but no internet showing",
221
- "internet stopped working after primary link down",
222
- "internet stopped working link not shifted to secondary after primary link down",
223
- "What are the network problems faced by people living in the state of California?"
 
 
 
224
  ],
225
  inputs=[message]
226
  )
 
21
  vector_store= FAISS.load_local("vector_db/", embeddings)
22
 
23
  repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1"
24
+ llm = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature": 0.01, "max_new_tokens": 4096})
25
 
26
  retriever = vector_store.as_retriever(
27
  search_type="similarity",
28
+ search_kwargs={"k":10}
29
  )
30
 
31
  df=pd.read_csv('data/Gretel_Data.csv')
 
131
  ]
132
  }
133
 
 
 
134
  def echo(message, history):
135
  try:
136
  qa=RetrievalQA.from_chain_type(llm=llm, retriever=retriever, return_source_documents=True)
137
+ message= " <s> [INST] You are a senior telecom network engineer having access to troubleshooting tickets data and other technical and product documentation. Stick to the knowledge provided. Search through the product documentation pdfs first before scanning the tickets to generate the answer. Return only the helpful answer. Question:" + message + '[/INST]'
138
  result= qa({"query":message})
139
+ answer= result['result'].split('Helpful Answer:')[-1]
140
  for word in target_words:
141
  if re.search(r'\b' + re.escape(word) + r'\b', answer, flags=re.IGNORECASE):
142
  columns.extend(network_features.get(word, []))
 
162
 
163
  gr.Dataframe(styled_df)
164
  return (
165
+ answer.split('Helpful Answer:')[-1].strip() + '\n'
166
+ + '\n' + "Sources: \n"
167
+ + '\n' + '1. ' + result['source_documents'][0].metadata['source'] + '\n' + result['source_documents'][0].page_content + "\n"
168
+ + '\n' + '2. ' + result['source_documents'][1].metadata['source'] + '\n' + result['source_documents'][1].page_content + "\n"
169
+ + '\n' + "3. " + result['source_documents'][2].metadata['source'] + '\n' + result['source_documents'][2].page_content + "\n"
170
+ + '\n' + "4. " + result['source_documents'][3].metadata['source'] + '\n' + result['source_documents'][3].page_content + "\n"
171
+ + '\n' + "5. " + result['source_documents'][4].metadata['source'] + '\n' + result['source_documents'][4].page_content + "\n",
172
  styled_df
173
  )
174
  except Exception as e:
 
218
 
219
  gr.Examples([
220
  "Wi-Fi connected but no internet showing",
221
+ 'What are the possible cause of router overheating ?',
222
+ "What are the possible causes of RAN getting disconnected frequently?",
223
+ "For the past week, are there any specific cell towers in Texas experiencing unusually high call failure rates or data latency?",
224
+ "What are the network problems faced by people living in the state of California?",
225
+ "I have an FWA connection and all devices except my iPhone have internet access via this FWA device. Can you suggest steps for resolution?",
226
+ "We're receiving reports of congested cell towers in Cleveland. Can you identify the specific cell towers experiencing overload and suggest any temporary network adjustments to alleviate the congestion?"
227
  ],
228
  inputs=[message]
229
  )