Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,12 +9,27 @@ import os
|
|
| 9 |
print(f"Prediction environment scikit-learn version: {sklearn.__version__}")
|
| 10 |
|
| 11 |
def decode_file(file_path):
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
# Load the model
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
def preprocess_input(data_dict):
|
| 20 |
"""Preprocess input data to match the training format"""
|
|
|
|
| 9 |
print(f"Prediction environment scikit-learn version: {sklearn.__version__}")
|
| 10 |
|
| 11 |
def decode_file(file_path):
|
| 12 |
+
try:
|
| 13 |
+
with open(file_path, 'rb') as file:
|
| 14 |
+
obj = pickle.load(file)
|
| 15 |
+
return obj
|
| 16 |
+
except FileNotFoundError:
|
| 17 |
+
print(f"Error: File not found at {file_path}")
|
| 18 |
+
return None
|
| 19 |
+
except Exception as e:
|
| 20 |
+
print(f"Error loading pickle file: {e}")
|
| 21 |
+
return None
|
| 22 |
|
| 23 |
+
# Load the model once when starting the app
|
| 24 |
+
try:
|
| 25 |
+
model = decode_file('./model.pkl')
|
| 26 |
+
if model is not None:
|
| 27 |
+
print("Model loaded successfully")
|
| 28 |
+
else:
|
| 29 |
+
print("Model loading failed, None value")
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(f"Error loading model: {e}")
|
| 32 |
+
model = None
|
| 33 |
|
| 34 |
def preprocess_input(data_dict):
|
| 35 |
"""Preprocess input data to match the training format"""
|