Nikhithapotnuru's picture
Update app.py
3b274de verified
import streamlit as st
import pickle
import sklearn
from sklearn.preprocessing import RobustScaler, OneHotEncoder, OrdinalEncoder
from sklearn.neighbors import KNeighborsClassifier
import pandas as pd
import numpy as np
# st.markdown("""
# <style>
# .stApp {
# background-image: url('https://tse3.mm.bing.net/th?id=OIP.AmAPg7MnWqITuUdPgrRaUQHaFP&pid=Api&P=0&h=180');
# background-size: contain;
# background-repeat: no-repeat;
# background-position : center;
# }
# .stTitle {
# color: #ffffff;
# font-size: 36px;
# font-weight: bold;
# text-align: center;
# }
# </style>
# """, unsafe_allow_html=True)
st.title("Diabetes Prediction App")
st.header("Patient Information")
gender = st.number_input("Enter Gender:(0 = F, 1 = M)",min_value=0,max_value=1,)
age = st.number_input("Enter Age:",min_value=20,max_value=80,step=1)
urea = st.number_input("Enter Urea Level:",min_value=2.3,max_value=10.00,step=0.02)
cr = st.number_input("Enter Creatinine Level:",min_value=33.00,max_value=112.50,step=0.02)
HbA1c = st.number_input("Enter HbA1c(Glycated hemoglobin) Level:",min_value=0.90,max_value=16.00,step=0.01)
chol = st.number_input("Enter the Cholestrol Level:",min_value=0.00,max_value=10.30,step=0.01)
tg = st.number_input("Enter TG(Triglycerides) Level:",min_value=0.80,max_value=5.10,step=0.01)
hdl = st.number_input("Enter HDL Level:",min_value=0.70,max_value=1.90,step=0.01)
ldl = st.number_input("Enter LDL Level:",min_value=0.75,max_value=5.60,step=0.01)
vldl = st.number_input("Enter VLDL Level:",min_value=0.33,max_value=1.95,step=0.01)
bmi = st.number_input("Enter BMI:",min_value=19.00,max_value=47.75,step=0.01)
with open("knn_model.pkl", "rb") as f:
model = pickle.load(f)
with open("scaler.pkl", "rb") as f:
scaler = pickle.load(f)
with open("features.pkl", "rb") as f:
feature_names = pickle.load(f)
with open("accuracy.pkl", "rb") as f:
accuracy = pickle.load(f)
if st.button("Predict Diabetes Class"):
input_data = np.array([[gender, age, urea, cr, HbA1c, chol, tg, hdl, ldl, vldl, bmi]])
input_scaled = scaler.transform(input_data)
prediction = model.predict(input_scaled)[0]
probabilities = model.predict_proba(input_scaled)[0]
class_labels = model.classes_
label_map = {"N": "Non-diabetes", "P": "Pre-diabetes", "Y": "Diabetes"}
readable_prediction = label_map.get(prediction, prediction)
st.success(f"Predicted Diabetes Class: **{readable_prediction}**")
st.markdown("##### Prediction Confidence:")
for label, prob in zip(class_labels, probabilities):
st.write(f"- **{label_map.get(label, label)}**: {prob * 100:.2f}%")
# Message based on result
if readable_prediction == "Pre-Diabete":
st.warning("You are in the pre-diabetic range. It's advisable to consult a healthcare professional for further evaluation.")
elif readable_prediction == "Diabete":
st.error("You are classified as diabetic. Please seek medical advice for appropriate management.")