|
import numpy as np |
|
import pickle |
|
import streamlit as st |
|
|
|
|
|
models = { |
|
"Logistic Regression": "LogisticRegression_model.pkl", |
|
"Decision Tree Classifier": "DecisionTreeClassifier_model.pkl", |
|
"Random Forest Classifier": "RandomForestClassifier_model.pkl", |
|
"SVC": "SVC_model.pkl" |
|
} |
|
|
|
def load_model(model_name): |
|
model_path = models.get(model_name) |
|
if model_path: |
|
return pickle.load(open(model_path, 'rb')) |
|
return None |
|
|
|
def diabetes_prediction(input_data, model): |
|
prediction = model.predict([input_data]) |
|
return 'The person is diabetic' if prediction[0] else 'The person is not diabetic' |
|
|
|
def main(): |
|
st.title('MultiModel Diabetes Predictor') |
|
|
|
selected_model_name = st.selectbox("Choose Prediction Method (Default: Logistic Regression)", list(models.keys())) |
|
|
|
loaded_model = load_model(selected_model_name) |
|
|
|
if loaded_model is None: |
|
st.error("Model not found!") |
|
return |
|
|
|
Pregnancies = st.text_input('Number of Pregnancies') |
|
Glucose = st.text_input('Glucose Level') |
|
BloodPressure = st.text_input('Blood Pressure Value') |
|
SkinThickness = st.text_input('Skin Thickness Value') |
|
Insulin = st.text_input('Insulin Level') |
|
BMI = st.text_input('BMI Value') |
|
DiabetesPedigreeFunction = st.text_input('Diabetes Pedigree Function Value') |
|
Age = st.text_input('Age of the Person') |
|
|
|
diagnosis = '' |
|
if st.button('Diabetes Test Result'): |
|
try: |
|
input_data = np.array([ |
|
float(Pregnancies), float(Glucose), float(BloodPressure), |
|
float(SkinThickness), float(Insulin), float(BMI), |
|
float(DiabetesPedigreeFunction), float(Age) |
|
]) |
|
diagnosis = diabetes_prediction(input_data, loaded_model) |
|
except ValueError: |
|
diagnosis = "Invalid input. Please enter numeric values for all fields." |
|
|
|
st.success(diagnosis) |
|
|
|
st.markdown('### Demo - Test with Dummy Entries') |
|
|
|
default_values = { |
|
"Number of Pregnancies": 5, |
|
"Glucose Level": 130, |
|
"Blood Pressure Value": 80, |
|
"Skin Thickness Value": 30, |
|
"Insulin Level": 100, |
|
"BMI Value": 35, |
|
"Diabetes Pedigree Function Value": 0.5, |
|
"Age of the Person": 40 |
|
} |
|
|
|
if st.button('Run Demo'): |
|
demo_input_data = np.array([ |
|
default_values["Number of Pregnancies"], default_values["Glucose Level"], |
|
default_values["Blood Pressure Value"], default_values["Skin Thickness Value"], |
|
default_values["Insulin Level"], default_values["BMI Value"], |
|
default_values["Diabetes Pedigree Function Value"], default_values["Age of the Person"] |
|
]) |
|
demo_diagnosis = diabetes_prediction(demo_input_data, loaded_model) |
|
st.success(f'Demo Result: {demo_diagnosis} with inputs: {default_values}') |
|
|
|
if __name__ == '__main__': |
|
main() |
|
|