Shreyas094 commited on
Commit
022b6d8
·
verified ·
1 Parent(s): b88f544

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -88,8 +88,8 @@ def update_vectors(files, parser):
88
  logging.info(f"Loaded {len(data)} chunks from {file.name}")
89
  all_data.extend(data)
90
  total_chunks += len(data)
91
- if not any(doc["name"] == file.name for doc in uploaded_documents):
92
- uploaded_documents.append({"name": file.name, "selected": True})
93
  logging.info(f"Added new document to uploaded_documents: {file.name}")
94
  else:
95
  logging.info(f"Document already exists in uploaded_documents: {file.name}")
@@ -322,8 +322,8 @@ def respond(message, history, model, temperature, num_calls, use_web_search, sel
322
  return
323
 
324
  # Filter relevant documents based on user selection
325
- filtered_docs = [doc for doc in relevant_docs if doc.metadata["source"] in selected_docs]
326
- logging.info(f"Filtered to {len(filtered_docs)} documents based on user selection")
327
 
328
  if not filtered_docs:
329
  logging.warning("No relevant information found in the selected documents")
@@ -353,6 +353,7 @@ def respond(message, history, model, temperature, num_calls, use_web_search, sel
353
  yield f"An unexpected error occurred: {str(e)}"
354
 
355
  logging.info("Finished respond function")
 
356
 
357
  def get_response_from_cloudflare(prompt, context, query, num_calls=3, temperature=0.2, search_type="pdf"):
358
  headers = {
@@ -511,6 +512,9 @@ Write a detailed and complete response that answers the following user question:
511
  logging.error(f"Error in API call {i+1}: {str(e)}")
512
 
513
  logging.info("Finished generating response")
 
 
 
514
 
515
  def vote(data: gr.LikeData):
516
  if data.liked:
@@ -534,8 +538,8 @@ uploaded_documents = []
534
 
535
  def display_documents():
536
  return gr.CheckboxGroup(
537
- choices=[doc["name"] for doc in uploaded_documents],
538
- value=[doc["name"] for doc in uploaded_documents if doc["selected"]],
539
  label="Select documents to query"
540
  )
541
 
 
88
  logging.info(f"Loaded {len(data)} chunks from {file.name}")
89
  all_data.extend(data)
90
  total_chunks += len(data)
91
+ if not any(doc["name"] == os.path.basename(file.name) for doc in uploaded_documents):
92
+ uploaded_documents.append({"name": os.path.basename(file.name), "selected": True})
93
  logging.info(f"Added new document to uploaded_documents: {file.name}")
94
  else:
95
  logging.info(f"Document already exists in uploaded_documents: {file.name}")
 
322
  return
323
 
324
  # Filter relevant documents based on user selection
325
+ filtered_docs = [doc for doc in relevant_docs if os.path.basename(doc.metadata["source"]) in [os.path.basename(doc) for doc in selected_docs]]
326
+ logging.info(f"Number of filtered documents: {len(filtered_docs)}")
327
 
328
  if not filtered_docs:
329
  logging.warning("No relevant information found in the selected documents")
 
353
  yield f"An unexpected error occurred: {str(e)}"
354
 
355
  logging.info("Finished respond function")
356
+ logging.info(f"Selected docs: {selected_docs}")
357
 
358
  def get_response_from_cloudflare(prompt, context, query, num_calls=3, temperature=0.2, search_type="pdf"):
359
  headers = {
 
512
  logging.error(f"Error in API call {i+1}: {str(e)}")
513
 
514
  logging.info("Finished generating response")
515
+ logging.info(f"Relevant docs: {[doc.metadata['source'] for doc in relevant_docs]}")
516
+ logging.info(f"Selected docs: {selected_docs}")
517
+ logging.info(f"Filtered docs: {[doc.metadata['source'] for doc in filtered_docs]}")
518
 
519
  def vote(data: gr.LikeData):
520
  if data.liked:
 
538
 
539
  def display_documents():
540
  return gr.CheckboxGroup(
541
+ choices=[os.path.basename(doc["name"]) for doc in uploaded_documents],
542
+ value=[os.path.basename(doc["name"]) for doc in uploaded_documents if doc["selected"]],
543
  label="Select documents to query"
544
  )
545