Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,14 +6,17 @@ import os
|
|
| 6 |
|
| 7 |
# Load the model - for Hugging Face deployment
|
| 8 |
try:
|
| 9 |
-
#
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
print("Model loaded successfully")
|
| 12 |
|
| 13 |
-
# Print model info for debugging
|
| 14 |
-
print("Model type:", type(model))
|
| 15 |
-
if hasattr(model, '_classifier'):
|
| 16 |
-
print("Classifier type:", type(model._classifier))
|
| 17 |
except Exception as e:
|
| 18 |
print(f"Error loading model: {str(e)}")
|
| 19 |
print(f"Current working directory: {os.getcwd()}")
|
|
@@ -38,14 +41,9 @@ def predict_stroke_risk(age, gender, hypertension, heart_disease, ever_married,
|
|
| 38 |
'smoking_status': [smoking_status]
|
| 39 |
})
|
| 40 |
|
| 41 |
-
# Make prediction
|
| 42 |
-
prediction = model.predict(
|
| 43 |
-
|
| 44 |
-
# For probability, we need to access the underlying classifier
|
| 45 |
-
if hasattr(model, '_classifier'):
|
| 46 |
-
probability = model._classifier.predict_proba(data)[0][1]
|
| 47 |
-
else:
|
| 48 |
-
probability = 0.5 # Default if we can't get probability
|
| 49 |
|
| 50 |
# Create result message
|
| 51 |
if prediction[0] == 1:
|
|
|
|
| 6 |
|
| 7 |
# Load the model - for Hugging Face deployment
|
| 8 |
try:
|
| 9 |
+
# Get absolute path to current directory
|
| 10 |
+
current_dir = os.getcwd()
|
| 11 |
+
print(f"Loading model from: {current_dir}")
|
| 12 |
+
|
| 13 |
+
# List all files to verify
|
| 14 |
+
print("Available files:", os.listdir(current_dir))
|
| 15 |
+
|
| 16 |
+
# Load model from current directory
|
| 17 |
+
model = mlflow.sklearn.load_model(current_dir)
|
| 18 |
print("Model loaded successfully")
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
except Exception as e:
|
| 21 |
print(f"Error loading model: {str(e)}")
|
| 22 |
print(f"Current working directory: {os.getcwd()}")
|
|
|
|
| 41 |
'smoking_status': [smoking_status]
|
| 42 |
})
|
| 43 |
|
| 44 |
+
# Make prediction
|
| 45 |
+
prediction = model.predict(data)
|
| 46 |
+
probability = model.predict_proba(data)[0][1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
# Create result message
|
| 49 |
if prediction[0] == 1:
|