SiraH commited on
Commit
f41cbd5
1 Parent(s): 3f1433f

comment source

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -196,6 +196,11 @@ def set_custom_prompt():
196
  'chat_history'])
197
  return prompt
198
 
 
 
 
 
 
199
  @st.cache_resource
200
  def load_embeddings():
201
  embeddings = HuggingFaceEmbeddings(model_name = "thenlper/gte-base",
@@ -241,7 +246,7 @@ def main():
241
  text = ""
242
  for page in pdf_reader.pages:
243
  text += page.extract_text()
244
- db = FAISS.from_texts(text, embeddings)
245
  qa_chain = ConversationalRetrievalChain(
246
  retriever =db.as_retriever(search_type="similarity_score_threshold", search_kwargs={'k':2, "score_threshold": 0.7}),
247
  question_generator=question_generator,
@@ -268,7 +273,7 @@ def main():
268
 
269
  response = qa_chain({'question': query})
270
 
271
- url_list = set([i.metadata['source'] for i in response['source_documents']])
272
  #print(f"condensed quesion : {question_generator.run({'chat_history': response['chat_history'], 'question' : query})}")
273
 
274
  with st.chat_message("assistant"):
@@ -280,10 +285,10 @@ def main():
280
  # Add assistant response to chat history
281
  st.session_state.messages.append({"role": "assistant", "content": response['answer']})
282
 
283
- with st.expander("See the related documents"):
284
- for count, url in enumerate(url_list):
285
- #url_reg = regex_source(url)
286
- st.write(str(count+1)+":", url)
287
 
288
  clear_button = st.button("Start new convo")
289
  if clear_button :
 
196
  'chat_history'])
197
  return prompt
198
 
199
+ @st.cache_resource
200
+ def create_db(text,embeddings):
201
+ return FAISS.from_texts(text, embeddings)
202
+
203
+
204
  @st.cache_resource
205
  def load_embeddings():
206
  embeddings = HuggingFaceEmbeddings(model_name = "thenlper/gte-base",
 
246
  text = ""
247
  for page in pdf_reader.pages:
248
  text += page.extract_text()
249
+ db = create_db(text,embeddings)
250
  qa_chain = ConversationalRetrievalChain(
251
  retriever =db.as_retriever(search_type="similarity_score_threshold", search_kwargs={'k':2, "score_threshold": 0.7}),
252
  question_generator=question_generator,
 
273
 
274
  response = qa_chain({'question': query})
275
 
276
+ # url_list = set([i.metadata['source'] for i in response['source_documents']])
277
  #print(f"condensed quesion : {question_generator.run({'chat_history': response['chat_history'], 'question' : query})}")
278
 
279
  with st.chat_message("assistant"):
 
285
  # Add assistant response to chat history
286
  st.session_state.messages.append({"role": "assistant", "content": response['answer']})
287
 
288
+ # with st.expander("See the related documents"):
289
+ # for count, url in enumerate(url_list):
290
+ # #url_reg = regex_source(url)
291
+ # st.write(str(count+1)+":", url)
292
 
293
  clear_button = st.button("Start new convo")
294
  if clear_button :