jarif commited on
Commit
275a13f
·
verified ·
1 Parent(s): 0bf85d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -0
app.py CHANGED
@@ -1,11 +1,15 @@
1
  import os
2
  import faiss
 
3
  import streamlit as st
4
  from langchain.embeddings import HuggingFaceEmbeddings
5
  from langchain.vectorstores import FAISS
6
  from langchain.chains import RetrievalQA
7
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
8
 
 
 
 
9
  def load_faiss_index(index_path):
10
  """
11
  Load a FAISS index from a specified path.
@@ -17,14 +21,18 @@ def load_faiss_index(index_path):
17
  - faiss.Index: Loaded FAISS index object.
18
  """
19
  if not os.path.exists(index_path):
 
20
  st.error(f"FAISS index not found at {index_path}. Please create the index first.")
21
  raise FileNotFoundError(f"FAISS index not found at {index_path}.")
22
 
23
  try:
 
24
  index = faiss.read_index(index_path)
 
25
  st.success("FAISS index loaded successfully.")
26
  return index
27
  except Exception as e:
 
28
  st.error(f"Failed to load FAISS index: {e}")
29
  raise
30
 
@@ -72,6 +80,7 @@ def process_answer(question):
72
  answer = result['result']
73
  return answer, result
74
  except Exception as e:
 
75
  st.error(f"An error occurred while processing the answer: {e}")
76
  return "An error occurred while processing your request.", {}
77
 
 
1
  import os
2
  import faiss
3
+ import logging
4
  import streamlit as st
5
  from langchain.embeddings import HuggingFaceEmbeddings
6
  from langchain.vectorstores import FAISS
7
  from langchain.chains import RetrievalQA
8
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
9
 
10
+ # Configure logging
11
+ logging.basicConfig(level=logging.DEBUG)
12
+
13
  def load_faiss_index(index_path):
14
  """
15
  Load a FAISS index from a specified path.
 
21
  - faiss.Index: Loaded FAISS index object.
22
  """
23
  if not os.path.exists(index_path):
24
+ logging.error(f"FAISS index not found at {index_path}. Please create the index first.")
25
  st.error(f"FAISS index not found at {index_path}. Please create the index first.")
26
  raise FileNotFoundError(f"FAISS index not found at {index_path}.")
27
 
28
  try:
29
+ logging.info(f"Attempting to load FAISS index from {index_path}.")
30
  index = faiss.read_index(index_path)
31
+ logging.info("FAISS index loaded successfully.")
32
  st.success("FAISS index loaded successfully.")
33
  return index
34
  except Exception as e:
35
+ logging.error(f"Failed to load FAISS index: {e}")
36
  st.error(f"Failed to load FAISS index: {e}")
37
  raise
38
 
 
80
  answer = result['result']
81
  return answer, result
82
  except Exception as e:
83
+ logging.error(f"An error occurred while processing the answer: {e}")
84
  st.error(f"An error occurred while processing the answer: {e}")
85
  return "An error occurred while processing your request.", {}
86