Spaces:
Sleeping
Sleeping
| import numpy as np | |
| import pickle | |
| import streamlit as st | |
| import pandas as pd | |
| import altair as alt | |
| # Loading the saved model | |
| diabetes_model = pickle.load(open("diabetes_model.sav", 'rb')) | |
| scaler = pickle.load(open("scaler.sav", 'rb')) | |
| # Function for diabetes prediction | |
| def diabetes_prediction(input_data): | |
| input_data_as_numpy_array = np.asarray(input_data) | |
| input_data_reshaped = input_data_as_numpy_array.reshape(1, -1) | |
| scaled_input = scaler.transform(input_data_reshaped) | |
| prediction = diabetes_model.predict(scaled_input) | |
| return prediction | |
| def main(): | |
| st.title('Early Diabetes Prediction Model') | |
| st.markdown(""" | |
| Welcome to my Early Diabetes Prediction Model! | |
| This model utilizes advanced machine learning algorithms to provide users with a quick and accurate assessment of their risk for diabetes. | |
| According to the World Health Organization (WHO), diabetes can often go undetected for several years with warning signs that may be subtle. | |
| By simply entering your health metrics, you can know whether you have diabetes or not at an early stage. | |
| This proactive approach empowers individuals to take informed steps towards managing and preventing diabetes. | |
| """) | |
| # Getting the input data from the user | |
| Pregnancies = st.number_input('Number of Pregnancies', min_value=0, max_value=20, step=1) | |
| Glucose = st.number_input('Glucose Level', min_value=0, max_value=500, step=1) | |
| BloodPressure = st.number_input('Blood Pressure value', min_value=0, max_value=200, step=1) | |
| SkinThickness = st.number_input('Skin Thickness value', min_value=0, max_value=100, step=1) | |
| Insulin = st.number_input('Insulin Level', min_value=0, max_value=1000, step=1) | |
| BMI = st.number_input('BMI value', min_value=0.0, max_value=100.0) | |
| DiabetesPedigreeFunction = st.number_input('Diabetes Pedigree Function value', min_value=0.001, max_value=2.999, format="%.3f") | |
| Age = st.number_input('Age of the Person', min_value=0, max_value=150, step=1) | |
| # Code for Prediction | |
| if st.button('Diabetes Test Result'): | |
| prediction = diabetes_prediction([Pregnancies, Glucose, BloodPressure, SkinThickness, Insulin, BMI, DiabetesPedigreeFunction, Age]) | |
| if prediction[0] == 0: | |
| st.success('The person is not diabetic.') | |
| else: | |
| st.success('The person is diabetic.') | |
| st.markdown('**Medical advice:** Please consult a healthcare professional for further evaluation and treatment.') | |
| # Example data table | |
| st.markdown("### Example Data") | |
| st.markdown("The following data were recorded from patients at Sunyani Regional Hospital for testing.") | |
| examples = [ | |
| [6, 148, 72, 35, 0, 33.6, 0.627, 50], | |
| [1, 85, 66, 29, 0, 26.6, 0.351, 31], | |
| [8, 183, 64, 0, 0, 23.3, 0.672, 32], | |
| [1, 89, 66, 23, 94, 28.1, 0.167, 21], | |
| [0, 137, 40, 35, 168, 43.1, 2.288, 33] | |
| ] | |
| columns = ['Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness', 'Insulin', 'BMI', 'DiabetesPedigreeFunction', 'Age'] | |
| df = pd.DataFrame(examples, columns=columns) | |
| st.table(df) | |
| # Educational content | |
| st.markdown("### Learn More About Diabetes") | |
| st.markdown(""" | |
| - [Diabetes Overview](https://www.cdc.gov/diabetes/about/index.html) | |
| - [Preventing Diabetes](https://www.mayoclinic.org/diseases-conditions/type-2-diabetes/in-depth/diabetes-prevention/art-20047639) | |
| """) | |
| # Research and Development section | |
| st.markdown("### Research and Development of My Diabetes Prediction Model") | |
| st.markdown(""" | |
| Learn more about the research and development process behind this diabetes prediction model. | |
| The document includes details about the data, model selection, and evaluation metrics used in the project. | |
| """) | |
| # Path to your PDF file | |
| pdf_file_path = "Research and Development of the Diabetes Prediction Model.pdf" | |
| with open(pdf_file_path, "rb") as pdf_file: | |
| pdf_contents = pdf_file.read() | |
| st.download_button(label="Download PDF", data=pdf_contents, file_name="Research and Development.pdf", mime="application/pdf") | |
| # Determine the current Streamlit theme (light or dark) | |
| theme = st.get_option("theme.base") | |
| # Define button styling based on theme | |
| if theme == "light": | |
| button_bg_color = "#2c2e35" | |
| button_border_color = "1px solid black" | |
| button_text_color = "black" | |
| else: | |
| button_bg_color = "#2c2e35" | |
| button_border_color = "1px solid #fff" | |
| button_text_color = "#fff" | |
| # Rounded button-like element with dynamic styling | |
| st.markdown(f""" | |
| <style> | |
| .rounded-button {{ | |
| display: inline-block; | |
| padding: 7px 15px; | |
| font-size: 16px; | |
| color: {button_text_color}; | |
| background-color: {button_bg_color}; | |
| border: {button_border_color}; | |
| border-radius: 7px; | |
| text-align: center; | |
| text-decoration: none; | |
| cursor: default; | |
| }} | |
| </style> | |
| <div style="text-align: center;"> | |
| <div class="rounded-button"> | |
| Created by: Samuel Ameyaw | |
| </div> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| if __name__ == '__main__': | |
| main() | |