import streamlit as st
import os
import pickle
from streamlit_option_menu import option_menu
import numpy as np
st.set_page_config(page_title="Disease Prediction System ( AI Based )",
page_icon="⚕", layout="wide")
def init_session_state():
if "logged_in" not in st.session_state:
st.session_state["logged_in"] = False
init_session_state()
# Admin Credentials
ADMIN_USERNAME = "admin"
ADMIN_PASSWORD = "admin123"
with [Link]:
selected = option_menu( 'Disease Prediction System',
['Home', 'Prediction Services', 'Health Tips', 'About
Us', 'Contact', 'Logout'],
menu_icon='hospital-fill',
icons=['house', 'activity', 'capsule', 'info-circle',
'envelope', 'box-arrow-right'],
default_index=0,
styles={"container": {"padding": "5px"},"nav-link":
{"font-size": "18px", "text-align": "left", "margin": "5px"}
}
)
# Home Page --
if selected == "Home":
[Link]("<h1 style='text-align: center; color: #0A66C2;'>Welcome to the
Disease Prediction System</h1>", unsafe_allow_html=True)
[Link]("""
Our system leverages Machine Learning to predict diseases such as
Diabetes , Heart Disease and Kidney Disease.
- Secure and User-Friendly
- Accurate Predictions
- Fast and Reliable
""")
[Link]("[Link]
ri/950/src/images/news/ImageForNews_776422_17123165547518811.jpg",width=400)
# Admin Login Page
if not st.session_state["logged_in"]:
if selected!="Home":
[Link]("Please Login First" )
[Link]("<h2 style='text-align: center; color: #0A66C2;'>Admin Login</h2>",
unsafe_allow_html=True)
username = st.text_input("Username")
password = st.text_input("Password", type="password")
if [Link]("Login"):
if username == ADMIN_USERNAME and password == ADMIN_PASSWORD:
st.session_state["logged_in"] = True
[Link]()
else:
[Link]("Invalid username or password")
[Link]()
[Link]("Logged in as Admin")
[Link]("<h1 style='text-align: center; color:
#A66C2;'></h1",unsafe_allow_html=True)
diabetes_model = [Link](open(r"C:\Users\Anudeep\Documents\Prediction\
training_models\diabetes_model.sav",'rb'))
heart_disease_model = [Link](open(r"C:\Users\Anudeep\Documents\Prediction\
training_models\heart_model_rf.sav",'rb'))
kidney_disease_model = [Link](open(r"c:\Users\Anudeep\Documents\Prediction\
training_models\Kidney_model_rf.sav", 'rb'))
#Prediction Services Page
if selected == "Prediction Services":
service = [Link]("Choose a prediction service:", ["Diabetes", "Heart Disease",
"Kidney Disease"])
# Diabetes Prediction Page
if service == "Diabetes":
[Link]("Diabetes Prediction using Machine Learning")
with [Link]("diabetes_form"):
col1, col2, col3 = [Link](3)
with col1:
pregnancies = st.number_input('Number of Pregnancies', min_value=0,
step=1)
skin_thickness = st.number_input('Skin Thickness value',
min_value=0, step=1)
diabetes_pedigree = st.number_input('Diabetes Pedigree Function',
min_value=0.0, step=0.01)
with col2:
glucose = st.number_input('Glucose Level', min_value=0, step=1)
insulin = st.number_input('Insulin Level', min_value=0, step=1)
age = st.number_input('Age of the Person', min_value=0, step=1)
with col3:
blood_pressure = st.number_input('Blood Pressure Value',
min_value=0, step=1)
bmi = st.number_input('BMI Value', min_value=0.0, step=0.1)
submit = st.form_submit_button("Predict")
# Prediction Logic
if submit:
input_data = [[pregnancies, glucose, blood_pressure, skin_thickness,
insulin, bmi, diabetes_pedigree, age]]
prediction = diabetes_model.predict(input_data)
if prediction[0] == 1:
[Link]("The person is Diabetes.")
else:
[Link]("The person is not Diabetes.")
else:
[Link]("Please Enter all Required Values before submitting")
# Heart Disease Prediction Page
if service == "Heart Disease":
[Link]("Heart Disease Prediction using Machine Learning")
with [Link]("heart_disease_form"):
col1, col2, col3, col4 = [Link](4)
with col1:
age = st.number_input('Age', min_value=1, step=1)
resting_bp = st.number_input('Resting Blood Pressure (mm Hg)',
min_value=0, step=1)
cholesterol = st.number_input('Serum Cholesterol (mg/dl)',
min_value=0, step=1)
fasting_bs = [Link]('Fasting Blood Sugar > 120 mg/dl', [0,
1], format_func=lambda x: "Yes" if x == 1 else "No")
with col2:
sex = [Link]('Sex', [0, 1], format_func=lambda x: "Male" if x
== 1 else "Female")
max_hr = st.number_input('Maximum Heart Rate Achieved',
min_value=0, step=1)
exercise_angina = [Link]('Exercise-Induced Angina', [0, 1],
format_func=lambda x: "Yes" if x == 1 else "No")
with col3:
chest_pain = [Link]('Chest Pain Type', [0, 1, 2, 3],
format_func=lambda x: ["Typical Angina", "Atypical Angina", "Non-Anginal Pain",
"Asymptomatic"][x])
oldpeak = st.number_input('ST Depression Induced by Exercise',
min_value=0.0, step=0.1)
st_slope = [Link]('ST Segment Slope', [0, 1, 2],
format_func=lambda x: ["Upsloping", "Flat", "Downsloping"][x])
with col4:
resting_ECG = [Link]('Resting ECG', [0, 1, 2],
format_func=lambda x: ["Normal", "ST-T wave abnormality", "Left Ventricular
Hypertrophy"][x])
major_vessels = st.number_input('Number of Major Vessels (0-3)
Colored by Fluoroscopy', min_value=0, max_value=3, step=1)
thalassemia = [Link]('Thalassemia Type', [0, 1, 2],
format_func=lambda x: ["Normal", "Fixed Defect", "Reversible Defect"][x])
submit = st.form_submit_button("Predict")
# Prediction Logic
if submit:
input_data = [[age, sex, chest_pain, resting_bp, cholesterol,
fasting_bs, max_hr, exercise_angina, oldpeak, st_slope, resting_ECG, major_vessels,
thalassemia]]
prediction = heart_disease_model.predict(input_data)
if prediction[0] == 1:
[Link]("The person is having Heart Disease.")
else:
[Link]("The person does't Heart Disease.")
else:
[Link]("Please Enter all Required Values before submitting")
# Kidney Disease Prediction Page
if service == "Kidney Disease":
[Link]("Kidney Disease Prediction using Machine Learning")
with [Link]("kidney_disease_form"):
col1, col2, col3, col4= [Link](4)
with col1:
age = st.number_input("Age", min_value=1, step=1)
blood_pressure = st.number_input("Blood Pressure", min_value=0,
step=1)
specific_gravity = st.number_input("Specific Gravity",
min_value=1.000, max_value=1.030, step=0.001)
albumin = st.number_input("Albumin Level", min_value=0, step=1)
with col2:
sugar_level = st.number_input("Sugar Level", min_value=0, step=1)
red_blood_cells = [Link]("Red Blood Cell Count",
["abnormal","normal"])
pus_cell = st.number_input("Pus Cell Count", min_value=0.0,
step=0.1)
serum_creatinine = st.number_input("Serum Creatinine",
min_value=0.0, step=0.1)
with col3:
sodium = st.number_input("Sodium Level", min_value=0.0, step=0.1)
pus_cell_clumps = [Link]("puss cell clumps",["Present","Not
Present"])
bacteria = [Link]("Bacteria",["Present","Not Present"])
with col4:
blood_glucose_random = st.number_input("blood glucose
random",min_value=0.0,step=0.1)
blood_urea = st.number_input ("bloood urea
(mg/dl)",min_value=0.0,step=0.1)
submit = st.form_submit_button("Predict")
if submit:
red_blood_cells=1 if red_blood_cells == "Abnormal" else 0
pus_cell=1 if pus_cell == "Abnormal" else 0
pus_cell_clumps=1 if pus_cell_clumps == "Present" else 0
bacteria = 1 if bacteria == "Present" else 0
input_data = [Link]([[age, blood_pressure, specific_gravity, albumin,
sugar_level, red_blood_cells, pus_cell, pus_cell_clumps , bacteria, blood_urea ,
blood_glucose_random ,serum_creatinine, sodium]])
prediction = kidney_disease_model.predict(input_data)
if prediction[0] == 1:
[Link]("The person is having Kidney Disease.")
else:
[Link]("The person does't have Kidney Disease.")
else:
[Link]("Please Enter all Required Values before submitting")
#Health Tips Section
if selected == "Health Tips":
[Link]("Health Tips")
[Link](""" Tips to Reduce Diabetes
1. Limit sugar and refined carbs (white bread, soda, sweets).
2. Eat more fiber – whole grains, vegetables, legumes.
3. Maintain a healthy weight – even small weight loss helps.
4. Exercise regularly – at least 30 minutes, 5 times a week.
5. Drink water – avoid sugary drinks.
6. Control portion sizes and eat balanced meals.
7. Choose low glycemic index foods – oats, barley, legumes.
8. Get enough sleep – poor sleep affects insulin sensitivity.
Tips to Reduce Heart Disease
1. Eat heart-healthy foods – like salmon, nuts, olive oil, berries.
2. Avoid trans fats and cut back on saturated fats.
3. Stay physically active – walk, swim, cycle.
4. Quit smoking – it's a major risk factor for heart attacks.
5. Manage stress – try meditation or breathing exercises.
6. Maintain a healthy weight – especially belly fat.
7. Limit salt intake – reduces blood pressure.
8. Sleep well – poor sleep increases heart disease risk.
Tips to Reduce Kidney Disease
1. Stay hydrated – drink enough water daily.
2. Control diabetes and blood pressure – key causes of kidney issues.
3. Eat low-sodium foods – reduce salt intake.
4. Limit processed foods – avoid packaged snacks and fast food.
5. Avoid overuse of painkillers – like NSAIDs, which harm kidneys.
6. Don't smoke – it reduces blood flow to kidneys.
7. Limit protein if advised – too much stresses the kidneys.
8. Avoid sugary drinks and alcohol – they can dehydrate and harm kidneys.""")
#About Us Section
if selected == "About Us":
[Link]("About Us")
[Link](""" <p style='font-size: 18px;'> Welcome to our Disease Prediction
System — a smart health assistant designed to help users take proactive steps
toward managing their well-being. Our platform leverages advanced machine learning
algorithms, including Random Forest models, to analyze user-provided medical data
and deliver accurate predictions for common diseases such as diabetes and heart
disease.
Developed with a modern and user-friendly interface using Python and Flask, our
system aims to bridge the gap between technology and healthcare. Whether you're
monitoring symptoms or looking for early warnings, our tool provides valuable
insights based on real-time data analysis.
We are committed to making health assessments more accessible, faster, and smarter
for everyone. While our system does not replace professional medical advice, it
serves as a reliable first step toward informed healthcare decisions.</p> """,
unsafe_allow_html=True)
#Contact Section
if selected == "Contact":
[Link]("Contact Us")
[Link](""" <p style='font-size: 18px;'> For inquiries, or feedback, please
reach out to us at: <br>Email: support@[Link] <br>Phone: +91-999-999-
9999 </p> """,
unsafe_allow_html=True)
#Logout Section
if selected=="Logout":
st.session_state["logged_in"]=False
[Link]("Logged Out Successfully!")
[Link]()