Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -135,42 +135,6 @@ def check_environment():
|
|
135 |
st.stop()
|
136 |
return False
|
137 |
|
138 |
-
@st.cache_resource
|
139 |
-
def initialize_model(self):
|
140 |
-
try:
|
141 |
-
if not os.path.exists(self.model_path):
|
142 |
-
direct_url = "https://huggingface.co/TheBloke/Mistral-7B-v0.1-GGUF/resolve/main/mistral-7b-v0.1.Q4_K_M.gguf"
|
143 |
-
download_file_with_progress(direct_url, self.model_path)
|
144 |
-
|
145 |
-
# Verify file exists and has content
|
146 |
-
if not os.path.exists(self.model_path):
|
147 |
-
raise FileNotFoundError(f"Model file {self.model_path} not found after download attempts")
|
148 |
-
|
149 |
-
if os.path.getsize(self.model_path) < 1000000: # Less than 1MB
|
150 |
-
os.remove(self.model_path)
|
151 |
-
raise ValueError("Downloaded model file is too small, likely corrupted")
|
152 |
-
|
153 |
-
llm_config = {
|
154 |
-
"n_ctx": 2048,
|
155 |
-
"n_threads": 4,
|
156 |
-
"n_batch": 512,
|
157 |
-
"n_gpu_layers": 0,
|
158 |
-
"verbose": False
|
159 |
-
}
|
160 |
-
|
161 |
-
return Llama(model_path=self.model_path, **llm_config)
|
162 |
-
|
163 |
-
except FileNotFoundError as e:
|
164 |
-
logging.error(f"Failed to find or download model file: {str(e)}")
|
165 |
-
raise
|
166 |
-
|
167 |
-
except ValueError as e:
|
168 |
-
logging.error(f"Model file validation failed: {str(e)}")
|
169 |
-
raise
|
170 |
-
|
171 |
-
except Exception as e:
|
172 |
-
logging.error(f"Unexpected error during model initialization: {str(e)}")
|
173 |
-
raise RuntimeError(f"Failed to initialize model: {str(e)}") from e
|
174 |
|
175 |
|
176 |
class SentenceTransformerRetriever:
|
@@ -188,6 +152,44 @@ class SentenceTransformerRetriever:
|
|
188 |
|
189 |
def get_cache_path(self, data_folder: str = None) -> str:
|
190 |
return os.path.join(self.cache_dir, self.cache_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
|
192 |
@log_function
|
193 |
def save_cache(self, data_folder: str, cache_data: dict):
|
@@ -248,6 +250,8 @@ class RAGPipeline:
|
|
248 |
self.documents = []
|
249 |
self.device = torch.device("cpu")
|
250 |
self.llm = initialize_model()
|
|
|
|
|
251 |
|
252 |
@log_function
|
253 |
@st.cache_data
|
|
|
135 |
st.stop()
|
136 |
return False
|
137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
|
140 |
class SentenceTransformerRetriever:
|
|
|
152 |
|
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):
|
|
|
250 |
self.documents = []
|
251 |
self.device = torch.device("cpu")
|
252 |
self.llm = initialize_model()
|
253 |
+
|
254 |
+
self.model_path = "mistral-7b-v0.1.Q4_K_M.gguf"
|
255 |
|
256 |
@log_function
|
257 |
@st.cache_data
|