Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -136,13 +136,22 @@ def check_environment():
|
|
136 |
return False
|
137 |
|
138 |
@st.cache_resource
|
139 |
-
def initialize_model():
|
140 |
-
"""Initialize the model with proper error handling and verification
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
try:
|
142 |
if not os.path.exists(self.model_path):
|
143 |
direct_url = "https://huggingface.co/TheBloke/Mistral-7B-v0.1-GGUF/resolve/main/mistral-7b-v0.1.Q4_K_M.gguf"
|
144 |
download_file_with_progress(direct_url, self.model_path)
|
145 |
-
|
146 |
# Verify file exists and has content
|
147 |
if not os.path.exists(self.model_path):
|
148 |
raise FileNotFoundError(f"Model file {self.model_path} not found after download attempts")
|
@@ -150,17 +159,28 @@ def initialize_model():
|
|
150 |
if os.path.getsize(self.model_path) < 1000000: # Less than 1MB
|
151 |
os.remove(self.model_path)
|
152 |
raise ValueError("Downloaded model file is too small, likely corrupted")
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
|
166 |
class SentenceTransformerRetriever:
|
|
|
136 |
return False
|
137 |
|
138 |
@st.cache_resource
|
139 |
+
def initialize_model(self):
|
140 |
+
"""Initialize the model with proper error handling and verification
|
141 |
+
|
142 |
+
Returns:
|
143 |
+
Llama: Initialized model instance
|
144 |
+
|
145 |
+
Raises:
|
146 |
+
FileNotFoundError: If model file cannot be found or downloaded
|
147 |
+
ValueError: If model file is corrupted or too small
|
148 |
+
RuntimeError: If model initialization fails
|
149 |
+
"""
|
150 |
try:
|
151 |
if not os.path.exists(self.model_path):
|
152 |
direct_url = "https://huggingface.co/TheBloke/Mistral-7B-v0.1-GGUF/resolve/main/mistral-7b-v0.1.Q4_K_M.gguf"
|
153 |
download_file_with_progress(direct_url, self.model_path)
|
154 |
+
|
155 |
# Verify file exists and has content
|
156 |
if not os.path.exists(self.model_path):
|
157 |
raise FileNotFoundError(f"Model file {self.model_path} not found after download attempts")
|
|
|
159 |
if os.path.getsize(self.model_path) < 1000000: # Less than 1MB
|
160 |
os.remove(self.model_path)
|
161 |
raise ValueError("Downloaded model file is too small, likely corrupted")
|
162 |
+
|
163 |
+
llm_config = {
|
164 |
+
"n_ctx": 2048,
|
165 |
+
"n_threads": 4,
|
166 |
+
"n_batch": 512,
|
167 |
+
"n_gpu_layers": 0,
|
168 |
+
"verbose": False
|
169 |
+
}
|
170 |
+
|
171 |
+
return Llama(model_path=self.model_path, **llm_config)
|
172 |
+
|
173 |
+
except FileNotFoundError as e:
|
174 |
+
logging.error(f"Failed to find or download model file: {str(e)}")
|
175 |
+
raise
|
176 |
+
|
177 |
+
except ValueError as e:
|
178 |
+
logging.error(f"Model file validation failed: {str(e)}")
|
179 |
+
raise
|
180 |
+
|
181 |
+
except Exception as e:
|
182 |
+
logging.error(f"Unexpected error during model initialization: {str(e)}")
|
183 |
+
raise RuntimeError(f"Failed to initialize model: {str(e)}") from e
|
184 |
|
185 |
|
186 |
class SentenceTransformerRetriever:
|