-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstressapp.py
58 lines (38 loc) · 1.66 KB
/
stressapp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import numpy as np
import pickle
import streamlit as st
loaded_model=pickle.load(open('C:\\Users\\Tanya Gupta\\Downloads\\Iot_domain_project\\trained_model.sav','rb'))
#creating a function
def stress_prediction(input_data):
# changing the input_data to numpy array
input_data_as_numpy_array = np.asarray(input_data)
input_data_as_numpy_array = input_data_as_numpy_array.astype(np.float64)
# reshape the array as we are predicting for one instance
input_data_reshaped = [input_data_as_numpy_array]
prediction = loaded_model.predict(input_data_reshaped)
print(prediction)
if (prediction[0] == 0):
return 'The person is not stressed'
elif (prediction[0] == 1):
return 'The person is slightly stressed'
elif (prediction[0] == 2):
return 'The person is stressed'
elif(prediction[0]==3):
return 'The person is highly stressed'
def main():
# giving a title
st.title('Stress level predictor')
# getting the input data from the user
body_temperature = st.text_input('Body temperature')
limb_movement = st.text_input('Limb movement')
Blood_oxygen = st.text_input('Blood oxygen')
Sleeping_hours = st.text_input('Sleeping hours')
Heart_rate = st.text_input('Heart rate')
# code for Prediction
diagnosis = ''
# creating a button for Prediction
if st.button('Predict stress'):
diagnosis = stress_prediction([body_temperature, limb_movement, Blood_oxygen, Sleeping_hours, Heart_rate])
st.success(diagnosis)
if __name__ == '__main__':
main()