ankanghosh commited on
Commit
87dead9
·
verified ·
1 Parent(s): 24f8abc

Update rag_engine.py

Browse files
Files changed (1) hide show
  1. rag_engine.py +11 -13
rag_engine.py CHANGED
@@ -118,16 +118,15 @@ def load_data_files():
118
  st.error("Failed to initialize required services")
119
  return None, None, None
120
 
121
- # Download necessary files with a spinner to show progress
122
- with st.spinner("Downloading necessary files..."):
123
- success = True
124
- success &= download_file_from_gcs(bucket, faiss_index_file_gcs, local_faiss_index_file)
125
- success &= download_file_from_gcs(bucket, text_chunks_file_gcs, local_text_chunks_file)
126
- success &= download_file_from_gcs(bucket, metadata_file_gcs, local_metadata_file)
127
-
128
- if not success:
129
- st.error("Failed to download required files")
130
- return None, None, None
131
 
132
  # Load FAISS index
133
  try:
@@ -299,7 +298,6 @@ def answer_with_llm(query, context=None, word_limit=100):
299
  user_message = f"""
300
  Context:
301
  {formatted_context}
302
-
303
  Question:
304
  {query}
305
  """
@@ -331,8 +329,8 @@ def answer_with_llm(query, context=None, word_limit=100):
331
  return "I apologize, but I'm unable to answer at the moment."
332
 
333
  def format_citations(sources):
334
- """Format citations to display each one on a new line."""
335
- return "\n".join([f"📚 {title} by {author}, Published by {publisher}" for title, author, publisher in sources])
336
 
337
  def process_query(query, top_k=5, word_limit=100):
338
  """Process a query through the RAG pipeline with proper formatting."""
 
118
  st.error("Failed to initialize required services")
119
  return None, None, None
120
 
121
+ # Download necessary files - remove the spinner from here
122
+ success = True
123
+ success &= download_file_from_gcs(bucket, faiss_index_file_gcs, local_faiss_index_file)
124
+ success &= download_file_from_gcs(bucket, text_chunks_file_gcs, local_text_chunks_file)
125
+ success &= download_file_from_gcs(bucket, metadata_file_gcs, local_metadata_file)
126
+
127
+ if not success:
128
+ st.error("Failed to download required files")
129
+ return None, None, None
 
130
 
131
  # Load FAISS index
132
  try:
 
298
  user_message = f"""
299
  Context:
300
  {formatted_context}
 
301
  Question:
302
  {query}
303
  """
 
329
  return "I apologize, but I'm unable to answer at the moment."
330
 
331
  def format_citations(sources):
332
+ """Format citations to display each one on a new line with a full stop."""
333
+ return "\n".join([f"📚 {title} by {author}, Published by {publisher}." for title, author, publisher in sources])
334
 
335
  def process_query(query, top_k=5, word_limit=100):
336
  """Process a query through the RAG pipeline with proper formatting."""