Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -153,43 +153,6 @@ class SentenceTransformerRetriever:
|
|
153 |
def get_cache_path(self, data_folder: str = None) -> str:
|
154 |
return os.path.join(self.cache_dir, self.cache_file)
|
155 |
|
156 |
-
@st.cache_resource
|
157 |
-
def initialize_model(self):
|
158 |
-
try:
|
159 |
-
if not os.path.exists(self.model_path):
|
160 |
-
direct_url = "https://huggingface.co/TheBloke/Mistral-7B-v0.1-GGUF/resolve/main/mistral-7b-v0.1.Q4_K_M.gguf"
|
161 |
-
download_file_with_progress(direct_url, self.model_path)
|
162 |
-
|
163 |
-
# Verify file exists and has content
|
164 |
-
if not os.path.exists(self.model_path):
|
165 |
-
raise FileNotFoundError(f"Model file {self.model_path} not found after download attempts")
|
166 |
-
|
167 |
-
if os.path.getsize(self.model_path) < 1000000: # Less than 1MB
|
168 |
-
os.remove(self.model_path)
|
169 |
-
raise ValueError("Downloaded model file is too small, likely corrupted")
|
170 |
-
|
171 |
-
llm_config = {
|
172 |
-
"n_ctx": 2048,
|
173 |
-
"n_threads": 4,
|
174 |
-
"n_batch": 512,
|
175 |
-
"n_gpu_layers": 0,
|
176 |
-
"verbose": False
|
177 |
-
}
|
178 |
-
|
179 |
-
return Llama(model_path=self.model_path, **llm_config)
|
180 |
-
|
181 |
-
except FileNotFoundError as e:
|
182 |
-
logging.error(f"Failed to find or download model file: {str(e)}")
|
183 |
-
raise
|
184 |
-
|
185 |
-
except ValueError as e:
|
186 |
-
logging.error(f"Model file validation failed: {str(e)}")
|
187 |
-
raise
|
188 |
-
|
189 |
-
except Exception as e:
|
190 |
-
logging.error(f"Unexpected error during model initialization: {str(e)}")
|
191 |
-
raise RuntimeError(f"Failed to initialize model: {str(e)}") from e
|
192 |
-
|
193 |
|
194 |
@log_function
|
195 |
def save_cache(self, data_folder: str, cache_data: dict):
|
@@ -249,9 +212,47 @@ class RAGPipeline:
|
|
249 |
self.retriever = SentenceTransformerRetriever()
|
250 |
self.documents = []
|
251 |
self.device = torch.device("cpu")
|
|
|
|
|
252 |
self.llm = initialize_model()
|
253 |
|
254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
|
256 |
@log_function
|
257 |
@st.cache_data
|
|
|
153 |
def get_cache_path(self, data_folder: str = None) -> str:
|
154 |
return os.path.join(self.cache_dir, self.cache_file)
|
155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
|
157 |
@log_function
|
158 |
def save_cache(self, data_folder: str, cache_data: dict):
|
|
|
212 |
self.retriever = SentenceTransformerRetriever()
|
213 |
self.documents = []
|
214 |
self.device = torch.device("cpu")
|
215 |
+
|
216 |
+
self.model_path = "mistral-7b-v0.1.Q4_K_M.gguf"
|
217 |
self.llm = initialize_model()
|
218 |
|
219 |
+
@st.cache_resource
|
220 |
+
def initialize_model(self):
|
221 |
+
try:
|
222 |
+
if not os.path.exists(self.model_path):
|
223 |
+
direct_url = "https://huggingface.co/TheBloke/Mistral-7B-v0.1-GGUF/resolve/main/mistral-7b-v0.1.Q4_K_M.gguf"
|
224 |
+
download_file_with_progress(direct_url, self.model_path)
|
225 |
+
|
226 |
+
# Verify file exists and has content
|
227 |
+
if not os.path.exists(self.model_path):
|
228 |
+
raise FileNotFoundError(f"Model file {self.model_path} not found after download attempts")
|
229 |
+
|
230 |
+
if os.path.getsize(self.model_path) < 1000000: # Less than 1MB
|
231 |
+
os.remove(self.model_path)
|
232 |
+
raise ValueError("Downloaded model file is too small, likely corrupted")
|
233 |
+
|
234 |
+
llm_config = {
|
235 |
+
"n_ctx": 2048,
|
236 |
+
"n_threads": 4,
|
237 |
+
"n_batch": 512,
|
238 |
+
"n_gpu_layers": 0,
|
239 |
+
"verbose": False
|
240 |
+
}
|
241 |
+
|
242 |
+
return Llama(model_path=self.model_path, **llm_config)
|
243 |
+
|
244 |
+
except FileNotFoundError as e:
|
245 |
+
logging.error(f"Failed to find or download model file: {str(e)}")
|
246 |
+
raise
|
247 |
+
|
248 |
+
except ValueError as e:
|
249 |
+
logging.error(f"Model file validation failed: {str(e)}")
|
250 |
+
raise
|
251 |
+
|
252 |
+
except Exception as e:
|
253 |
+
logging.error(f"Unexpected error during model initialization: {str(e)}")
|
254 |
+
raise RuntimeError(f"Failed to initialize model: {str(e)}") from e
|
255 |
+
|
256 |
|
257 |
@log_function
|
258 |
@st.cache_data
|