Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,7 +84,7 @@ def predict():
|
|
| 84 |
'age': float(input_data.get('age', 0)),
|
| 85 |
'gender': input_data.get('gender', 'Unknown'),
|
| 86 |
'ever_married': input_data.get('ever_married', 'No'),
|
| 87 |
-
'residence_type': input_data.get('residence_type', 'Unknown'),
|
| 88 |
'work_type': input_data.get('work_type', 'Unknown'),
|
| 89 |
'hypertension': int(input_data.get('hypertension', 0)),
|
| 90 |
'heart_disease': int(input_data.get('heart_disease', 0)),
|
|
@@ -118,13 +118,13 @@ def predict():
|
|
| 118 |
|
| 119 |
# Make prediction
|
| 120 |
probability = model.predict_proba(df)[0][1] * 100
|
| 121 |
-
|
| 122 |
|
| 123 |
# Determine contributing factors
|
| 124 |
contributing_factors = {
|
| 125 |
'glucose': features['avg_glucose_level'] > 140,
|
| 126 |
'hypertension': features['hypertension'] == 1,
|
| 127 |
-
'heartDisease': features['heart_disease'] == 1,
|
| 128 |
'smoking': features['smoking_status'] in ['smokes', 'formerly smoked']
|
| 129 |
}
|
| 130 |
|
|
@@ -150,16 +150,16 @@ def predict():
|
|
| 150 |
features['bmi'],
|
| 151 |
features['smoking_status'],
|
| 152 |
round(probability),
|
| 153 |
-
|
| 154 |
))
|
| 155 |
conn.commit()
|
| 156 |
conn.close()
|
| 157 |
|
| 158 |
-
print(f"Prediction success: probability={probability}%,
|
| 159 |
return jsonify({
|
| 160 |
'success': True,
|
|
|
|
| 161 |
'probability': round(probability),
|
| 162 |
-
'riskLevel': risk_level,
|
| 163 |
'contributingFactors': contributing_factors
|
| 164 |
})
|
| 165 |
except Exception as e:
|
|
|
|
| 84 |
'age': float(input_data.get('age', 0)),
|
| 85 |
'gender': input_data.get('gender', 'Unknown'),
|
| 86 |
'ever_married': input_data.get('ever_married', 'No'),
|
| 87 |
+
'residence_type': input_data.get('residence_type', 'Unknown'),
|
| 88 |
'work_type': input_data.get('work_type', 'Unknown'),
|
| 89 |
'hypertension': int(input_data.get('hypertension', 0)),
|
| 90 |
'heart_disease': int(input_data.get('heart_disease', 0)),
|
|
|
|
| 118 |
|
| 119 |
# Make prediction
|
| 120 |
probability = model.predict_proba(df)[0][1] * 100
|
| 121 |
+
risk_prediction = "Stroke Risk" if probability > 50 else "No Stroke Risk"
|
| 122 |
|
| 123 |
# Determine contributing factors
|
| 124 |
contributing_factors = {
|
| 125 |
'glucose': features['avg_glucose_level'] > 140,
|
| 126 |
'hypertension': features['hypertension'] == 1,
|
| 127 |
+
'heartDisease': features['heart_disease'] == 1,
|
| 128 |
'smoking': features['smoking_status'] in ['smokes', 'formerly smoked']
|
| 129 |
}
|
| 130 |
|
|
|
|
| 150 |
features['bmi'],
|
| 151 |
features['smoking_status'],
|
| 152 |
round(probability),
|
| 153 |
+
risk_prediction
|
| 154 |
))
|
| 155 |
conn.commit()
|
| 156 |
conn.close()
|
| 157 |
|
| 158 |
+
print(f"Prediction success: probability={probability}%, prediction={risk_prediction}")
|
| 159 |
return jsonify({
|
| 160 |
'success': True,
|
| 161 |
+
'prediction': risk_prediction, # Simplified output
|
| 162 |
'probability': round(probability),
|
|
|
|
| 163 |
'contributingFactors': contributing_factors
|
| 164 |
})
|
| 165 |
except Exception as e:
|