Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,24 @@ 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 once when starting the app
|
| 17 |
try:
|
| 18 |
-
model = decode_file('model.pkl')
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
except Exception as e:
|
| 21 |
print(f"Error loading model: {e}")
|
| 22 |
model = None
|
|
@@ -107,7 +117,7 @@ def predict(gender, age, hypertension, ever_married, work_type, heart_disease,
|
|
| 107 |
prediction = model.predict_proba(processed_input)[0][1]
|
| 108 |
return f"The probability of stroke is {prediction:.2%}"
|
| 109 |
except Exception as e:
|
| 110 |
-
return f"Error making prediction: {str(e)}"
|
| 111 |
|
| 112 |
# Create the Gradio interface
|
| 113 |
iface = gr.Interface(
|
|
|
|
| 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') # Updated here
|
| 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
|
|
|
|
| 117 |
prediction = model.predict_proba(processed_input)[0][1]
|
| 118 |
return f"The probability of stroke is {prediction:.2%}"
|
| 119 |
except Exception as e:
|
| 120 |
+
return f"Error making prediction: {str(e)}, model is not valid" # updated here
|
| 121 |
|
| 122 |
# Create the Gradio interface
|
| 123 |
iface = gr.Interface(
|