Spaces:
Sleeping
Sleeping
File size: 1,591 Bytes
46a9200 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | from flask import Flask, render_template, request
import pandas as pd
import joblib
app = Flask(__name__)
# Load model pipeline
model = joblib.load("ckd_rf_model_pca.pkl")
scaler = joblib.load("ckd_scaler.pkl")
pca = joblib.load("ckd_pca.pkl")
# Feature list
features = [
'age', 'blood_pressure', 'specific_gravity', 'albumin', 'sugar',
'red_blood_cells', 'pus_cell', 'pus_cell_clumps', 'bacteria',
'blood_glucose_random', 'blood_urea', 'serum_creatinine', 'sodium',
'potassium', 'haemoglobin', 'packed_cell_volume', 'white_blood_cell_count',
'red_blood_cell_count', 'hypertension', 'diabetes_mellitus',
'coronary_artery_disease', 'appetite', 'peda_edema', 'aanemia'
]
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
input_data = {feature: float(request.form[feature]) for feature in features}
# Convert to DataFrame
input_df = pd.DataFrame([input_data])
# Preprocess
scaled = scaler.transform(input_df)
pca_input = pca.transform(scaled)
# Predict
prediction = model.predict(pca_input)[0]
prob = model.predict_proba(pca_input)[0][1]
if prediction == 1:
result = f"🟢 CKD Detected with {prob:.2%} confidence"
else:
result = f"🟡 No CKD Detected with {(1 - prob):.2%} confidence"
return render_template("index.html", result=result)
return render_template("index.html", result=None)
if __name__ == '__main__':
app.run(debug=True,port=5000)
|