-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
587 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
{ | ||
"Sleep Prediction Form": { | ||
"Age": { | ||
"field_name": "Age", | ||
"type": "number", | ||
"min_value": 0, | ||
"max_value": 120, | ||
"default_value": 25, | ||
"step": 1 | ||
}, | ||
"Sleep_Duration": { | ||
"field_name": "Sleep_Duration", | ||
"type": "float", | ||
"min_value": 0.0, | ||
"max_value": 24.0, | ||
"default_value": 8.0, | ||
"step": 0.1 | ||
}, | ||
"Heart_Rate": { | ||
"field_name": "Heart_Rate", | ||
"type": "number", | ||
"min_value": 10, | ||
"max_value": 200, | ||
"default_value": 72, | ||
"step": 1 | ||
}, | ||
"Daily_Steps": { | ||
"field_name": "Daily_Steps", | ||
"type": "number", | ||
"min_value": 0, | ||
"max_value": 1000000, | ||
"default_value": 0, | ||
"step": 10 | ||
}, | ||
"Systolic": { | ||
"field_name": "Systolic", | ||
"type": "float", | ||
"min_value": 0.0, | ||
"max_value": 250.0, | ||
"default_value": 120.0, | ||
"step": 0.1 | ||
}, | ||
"Diastolic": { | ||
"field_name": "Diastolic", | ||
"type": "float", | ||
"min_value": 0.0, | ||
"max_value": 250.0, | ||
"default_value": 80.0, | ||
"step": 0.1 | ||
}, | ||
"Occupation": { | ||
"field_name": "Occupation", | ||
"type": "dropdown", | ||
"options": [ | ||
"Software Engineer" ,"Doctor" ,"Sales Representative","Teacher" ,"Nurse", | ||
"Engineer" ,"Accountant" ,"Scientist", "Lawyer" ,"Salesperson" ,"Manager" | ||
], | ||
"default_value": "Software Engineer" | ||
}, | ||
"Quality_of_Sleep": { | ||
"field_name": "Quality_of_Sleep", | ||
"type": "number", | ||
"min_value": 0, | ||
"max_value": 10, | ||
"default_value": 0, | ||
"step": 1 | ||
}, | ||
"Gender": { | ||
"field_name": "Gender", | ||
"type": "dropdown", | ||
"options": [ | ||
"Male", | ||
"Female" | ||
], | ||
"default_value": "Male" | ||
|
||
}, | ||
"Physical_Activity_Level": { | ||
"field_name": "Physical_Activity_Level", | ||
"type": "number", | ||
"min_value": 0, | ||
"max_value": 200, | ||
"default_value": 0, | ||
"step": 1 | ||
}, | ||
"Stress_Level": { | ||
"field_name": "Stress_Level", | ||
"type": "number", | ||
"min_value": 0, | ||
"max_value": 10, | ||
"default_value": 0, | ||
"step": 1 | ||
}, | ||
"BMI_Category": { | ||
"field_name": "BMI_Category", | ||
"type": "dropdown", | ||
"options": [ | ||
"Normal Weight", | ||
"Obese", | ||
"Overweight" | ||
], | ||
"default_value": "Normal Weight" | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import streamlit as st | ||
import pickle | ||
import pandas as pd # Import pandas to handle DataFrames | ||
import numpy as np | ||
import warnings | ||
warnings.filterwarnings("ignore") | ||
|
||
# Load the model and the scaler | ||
model_path = 'models/sleep_disorder_predictor/saved_models/Model_Prediction.sav' | ||
preprocessor_path = 'models/sleep_disorder_predictor/saved_models/preprocessor.sav' | ||
|
||
# Load the pre-trained model and scaler using pickle | ||
loaded_model = pickle.load(open(model_path, 'rb')) | ||
preprocessor = pickle.load(open(preprocessor_path, 'rb')) | ||
|
||
# Define the prediction function | ||
def disease_get_prediction(Age, Sleep_Duration, | ||
Heart_Rate, Daily_Steps, | ||
Systolic, Diastolic, Occupation, Quality_of_Sleep, Gender, | ||
Physical_Activity_Level, Stress_Level, BMI_Category): | ||
# Create a DataFrame with the features using correct column names | ||
features = pd.DataFrame({ | ||
'Age': [int(Age)], | ||
'Sleep Duration': [float(Sleep_Duration)], # Changed to match expected name | ||
'Heart Rate': [int(Heart_Rate)], # Changed to match expected name | ||
'Daily Steps': [int(Daily_Steps)], # Changed to match expected name | ||
'Systolic': [float(Systolic)], | ||
'Diastolic': [float(Diastolic)], | ||
'Occupation': [Occupation], | ||
'Quality of Sleep': [int(Quality_of_Sleep)], # Changed to match expected name | ||
'Gender': [Gender], | ||
'Physical Activity Level': [int(Physical_Activity_Level)], # Changed to match expected name | ||
'Stress Level': [int(Stress_Level)], # Changed to match expected name | ||
'BMI Category': [BMI_Category] # Changed to match expected name | ||
}) | ||
|
||
# Apply the preprocessor (make sure it expects a DataFrame) | ||
preprocessed_data = preprocessor.transform(features) | ||
|
||
# Make prediction | ||
prediction = loaded_model.predict(preprocessed_data) | ||
|
||
return prediction |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from models.sleep_disorder_predictor.model import disease_get_prediction | ||
|
||
def get_prediction(Age, Sleep_Duration, | ||
Heart_Rate, Daily_Steps, | ||
Systolic, Diastolic,Occupation,Quality_of_Sleep,Gender, | ||
Physical_Activity_Level, Stress_Level, BMI_Category): | ||
|
||
prediction = disease_get_prediction(Age, Sleep_Duration, | ||
Heart_Rate, Daily_Steps, | ||
Systolic, Diastolic,Occupation,Quality_of_Sleep,Gender, | ||
Physical_Activity_Level, Stress_Level, BMI_Category) | ||
|
||
message = "" | ||
|
||
# Provide message based on the prediction value | ||
if prediction==0: | ||
message= "Insomnia" | ||
elif prediction==1: | ||
message = "No disorder" | ||
elif prediction==2: | ||
message = "Sleep Apnea" | ||
else: | ||
message="Invalid details." | ||
|
||
return message+"\n\nRecommendation - To prevent sleep disorders, maintain a balanced lifestyle with regular exercise, a healthy diet, and stress management. Stick to a consistent sleep schedule, limit caffeine and alcohol, and create a relaxing bedtime routine." |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from page_handler import PageHandler | ||
|
||
page_handler = PageHandler("pages/pages.json") | ||
page_handler.render_page("Sleep Disorder Predictor") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters