Neurolingua commited on
Commit
907d1ed
1 Parent(s): 983b977

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -95,17 +95,26 @@ def extract_text_from_pdf(pdf_filepath):
95
 
96
  def query_rag(query_text: str, chat_history):
97
  try:
 
 
 
98
  embedding_function = HuggingFaceEmbeddings()
99
  db = Chroma(persist_directory=CHROMA_PATH, embedding_function=embedding_function)
100
 
 
101
  results = db.similarity_search_with_score(query_text, k=5)
102
-
103
  if not results:
 
104
  return "Sorry, I couldn't find any relevant information."
105
 
 
106
  context_text = "\n\n---\n\n".join([doc.page_content for doc, _score in results])
107
 
 
108
  prompt = f"Context:\n{context_text}\n\nQuestion:\n{query_text}"
 
 
109
  response = generate_response(prompt, chat_history)
110
 
111
  return response
@@ -114,6 +123,7 @@ def query_rag(query_text: str, chat_history):
114
  return "An error occurred while querying the RAG system."
115
 
116
 
 
117
  def save_pdf_and_update_database(pdf_filepath):
118
  try:
119
  text = extract_text_from_pdf(pdf_filepath)
 
95
 
96
  def query_rag(query_text: str, chat_history):
97
  try:
98
+ # Ensure the database is initialized
99
+ initialize_chroma()
100
+
101
  embedding_function = HuggingFaceEmbeddings()
102
  db = Chroma(persist_directory=CHROMA_PATH, embedding_function=embedding_function)
103
 
104
+ # Perform similarity search
105
  results = db.similarity_search_with_score(query_text, k=5)
106
+
107
  if not results:
108
+ print("No relevant information found.")
109
  return "Sorry, I couldn't find any relevant information."
110
 
111
+ # Combine document contents for context
112
  context_text = "\n\n---\n\n".join([doc.page_content for doc, _score in results])
113
 
114
+ # Prepare the prompt for the Falcon model
115
  prompt = f"Context:\n{context_text}\n\nQuestion:\n{query_text}"
116
+
117
+ # Generate a response using the Falcon model
118
  response = generate_response(prompt, chat_history)
119
 
120
  return response
 
123
  return "An error occurred while querying the RAG system."
124
 
125
 
126
+
127
  def save_pdf_and_update_database(pdf_filepath):
128
  try:
129
  text = extract_text_from_pdf(pdf_filepath)