nishantgaurav23 commited on
Commit
060ddae
·
verified ·
1 Parent(s): ec50cfd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -216,41 +216,46 @@ class RAGPipeline:
216
  self.retriever = SentenceTransformerRetriever()
217
  self.documents = []
218
  self.device = torch.device("cpu")
219
- self.model_path = os.path.join("models", "mistral-7b-v0.1.Q4_K_M.gguf")
 
 
 
 
 
220
  self.llm = None
 
221
  self._initialize_model()
222
 
223
- @st.cache_resource(show_spinner=False)
224
  def _initialize_model(_self):
225
  try:
226
- os.makedirs(os.path.dirname(_self.model_path), exist_ok=True)
227
-
228
  if not os.path.exists(_self.model_path):
229
  direct_url = "https://huggingface.co/TheBloke/Mistral-7B-v0.1-GGUF/resolve/main/mistral-7b-v0.1.Q4_K_M.gguf"
230
  download_file_with_progress(direct_url, _self.model_path)
231
 
 
232
  if not os.path.exists(_self.model_path):
233
  raise FileNotFoundError(f"Model file {_self.model_path} not found after download attempts")
234
-
235
- if os.path.getsize(_self.model_path) < 1000000:
236
- os.remove(_self.model_path)
237
- raise ValueError("Downloaded model file is too small, likely corrupted")
238
-
239
  llm_config = {
240
  "n_ctx": 2048,
241
  "n_threads": 4,
242
  "n_batch": 512,
243
  "n_gpu_layers": 0,
244
- "verbose": False
245
  }
246
-
247
  _self.llm = Llama(model_path=_self.model_path, **llm_config)
248
  st.success("Model loaded successfully!")
 
249
  except Exception as e:
 
250
  logging.error(f"Error initializing model: {str(e)}")
251
  st.error(f"Error initializing model: {str(e)}")
252
  raise
253
-
 
254
  def check_model_health(self):
255
  try:
256
  if self.llm is None:
 
216
  self.retriever = SentenceTransformerRetriever()
217
  self.documents = []
218
  self.device = torch.device("cpu")
219
+
220
+ # Change 1: Process documents first
221
+ self.load_and_process_csvs()
222
+
223
+ # Change 2: Simplified model path
224
+ self.model_path = "mistral-7b-v0.1.Q4_K_M.gguf"
225
  self.llm = None
226
+ # Change 3: Initialize model after documents are processed
227
  self._initialize_model()
228
 
229
+ @st.cache_resource # Added caching decorator
230
  def _initialize_model(_self):
231
  try:
 
 
232
  if not os.path.exists(_self.model_path):
233
  direct_url = "https://huggingface.co/TheBloke/Mistral-7B-v0.1-GGUF/resolve/main/mistral-7b-v0.1.Q4_K_M.gguf"
234
  download_file_with_progress(direct_url, _self.model_path)
235
 
236
+ # Added better error handling
237
  if not os.path.exists(_self.model_path):
238
  raise FileNotFoundError(f"Model file {_self.model_path} not found after download attempts")
239
+
240
+ # Added verbose mode for better debugging
 
 
 
241
  llm_config = {
242
  "n_ctx": 2048,
243
  "n_threads": 4,
244
  "n_batch": 512,
245
  "n_gpu_layers": 0,
246
+ "verbose": True # Added this
247
  }
248
+
249
  _self.llm = Llama(model_path=_self.model_path, **llm_config)
250
  st.success("Model loaded successfully!")
251
+
252
  except Exception as e:
253
+ # Added better error logging
254
  logging.error(f"Error initializing model: {str(e)}")
255
  st.error(f"Error initializing model: {str(e)}")
256
  raise
257
+
258
+
259
  def check_model_health(self):
260
  try:
261
  if self.llm is None: