Jegree commited on
Commit
dfd59f2
·
verified ·
1 Parent(s): bde63d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +131 -64
app.py CHANGED
@@ -1,64 +1,131 @@
1
- import streamlit as st
2
-
3
- def calculate_bmi(weight, height):
4
- # Calculate BMI
5
- bmi = weight / (height ** 2)
6
-
7
- return bmi
8
-
9
- def is_number(text):
10
- try:
11
- # Try to convert the text to a float
12
- float(text)
13
- return True
14
- except ValueError:
15
- # If conversion fails, it's not a number
16
- return False
17
-
18
-
19
-
20
- if "question_no" not in st.session_state:
21
- st.session_state.question_no = 1
22
-
23
- st.title(f"{st.session_state.question_no}Know your diabetic status")
24
- if st.session_state.question_no == 1:
25
- name = st.text_input(f"{st.session_state.question_no}What is your name?", key=st.session_state.question_no,placeholder="Type your answer here")
26
-
27
- if st.button("Next->"):
28
- if name:
29
- st.session_state.name = name
30
- else:
31
- st.session_state.name = "Anonymous user"
32
- st.session_state.question_no += 1
33
-
34
- elif st.session_state.question_no == 2:
35
- age = st.number_input(f"{st.session_state.question_no}How old are you?", key=st.session_state.question_no, placeholder="Type your answer")
36
- if st.button("Next->"):
37
- if not is_number(age):
38
- st.warning("Please enter a valid age")
39
- else:
40
- st.session_state.age = int(age)
41
- st.session_state.question_no += 1
42
-
43
- elif st.session_state.question_no == 3:
44
- gender = st.selectbox(f"{st.session_state.question_no}What is your gender?", ["Male", "Female", "Other"], key=st.session_state.question_no)
45
- if st.button("Next->"):
46
- st.session_state.gender = gender
47
- if gender == "Male":
48
- st.session_state.pregnancies = 0
49
- st.session_state.question_no += 2
50
- else:
51
- st.session_state.question_no += 1
52
-
53
- elif st.session_state.question_no == 4:
54
- pregnancies = st.number_input(f"{st.session_state.question_no}How many times have you been pregnant?", key=st.session_state.question_no)
55
- if st.button("Next->"):
56
- st.session_state.pregnancies = int(pregnancies)
57
- st.session_state.question_no += 1
58
-
59
- elif st.session_state.question_no == 5:
60
- glucose = st.number_input(f"{st.session_state.question_no}Enter your glucose level", key=st.session_state.question_no)
61
- if st.button("Next->"):
62
- st.session_state.glucose = int(glucose)
63
- st.session_state.question_no += 1
64
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def calculate_bmi(weight, height):
4
+ # Calculate BMI
5
+ bmi = weight / (height ** 2)
6
+
7
+ return bmi
8
+
9
+ def is_number(text):
10
+ try:
11
+ # Try to convert the text to a float
12
+ float(text)
13
+ return True
14
+ except ValueError:
15
+ # If conversion fails, it's not a number
16
+ return False
17
+
18
+ def diabetic_pedigree_function(mother, father, siblings):
19
+ """
20
+ Calculate a scaled Diabetic Pedigree Function (DPF) for an individual,
21
+ aiming for an output range of approximately (0.078, 2.42).
22
+
23
+ Parameters:
24
+ mother (int): 1 if the mother has diabetes, 0 otherwise.
25
+ father (int): 1 if the father has diabetes, 0 otherwise.
26
+ siblings (list): A list of 0s and 1s representing siblings' diabetes status.
27
+
28
+ Returns:
29
+ float: The scaled diabetic pedigree function score.
30
+ """
31
+ # Assign weights to each family member
32
+ mother_weight = 0.5
33
+ father_weight = 0.5
34
+ sibling_weight = 0.25
35
+
36
+ # Calculate the weighted contributions
37
+ family_history = (mother * mother_weight) + (father * father_weight) + (sum(siblings) * sibling_weight)
38
+
39
+ # Add a scaling factor to shift the range
40
+ scaling_factor = 1.2
41
+ bias = 0.078 # Minimum value in the desired range
42
+
43
+ # Final scaled DPF score
44
+ dpf_score = family_history * scaling_factor + bias
45
+
46
+ return round(dpf_score, 3) # Rounded for clarity
47
+
48
+
49
+
50
+ if "question_no" not in st.session_state:
51
+ st.session_state.question_no = 1
52
+
53
+ st.title(f"{st.session_state.question_no}Know your diabetic status")
54
+ if st.session_state.question_no == 1:
55
+ name = st.text_input(f"{st.session_state.question_no}What is your name?", key=st.session_state.question_no,placeholder="Type your answer here")
56
+
57
+ if st.button("Next->"):
58
+ if name:
59
+ st.session_state.name = name
60
+ else:
61
+ st.session_state.name = "Anonymous user"
62
+ st.session_state.question_no += 1
63
+
64
+ elif st.session_state.question_no == 2:
65
+ age = st.number_input(f"{st.session_state.question_no}How old are you?", key=st.session_state.question_no, placeholder="Type your answer")
66
+ if st.button("Next->"):
67
+ if not is_number(age):
68
+ st.warning("Please enter a valid age")
69
+ else:
70
+ st.session_state.age = int(age)
71
+ st.session_state.question_no += 1
72
+
73
+ elif st.session_state.question_no == 3:
74
+ gender = st.selectbox(f"{st.session_state.question_no}What is your gender?", ["Male", "Female", "Other"], key=st.session_state.question_no)
75
+ if st.button("Next->"):
76
+ st.session_state.gender = gender
77
+ if gender == "Male":
78
+ st.session_state.pregnancies = 0
79
+ st.session_state.question_no += 2
80
+ else:
81
+ st.session_state.question_no += 1
82
+
83
+ elif st.session_state.question_no == 4:
84
+ pregnancies = st.number_input(f"{st.session_state.question_no}How many times have you been pregnant?", key=st.session_state.question_no)
85
+ if st.button("Next->"):
86
+ st.session_state.pregnancies = int(pregnancies)
87
+ st.session_state.question_no += 1
88
+
89
+ elif st.session_state.question_no == 5:
90
+ glucose = st.number_input(f"{st.session_state.question_no}Enter your glucose level", key=st.session_state.question_no)
91
+ if st.button("Next->"):
92
+ st.session_state.glucose = int(glucose)
93
+ st.session_state.question_no += 1
94
+
95
+ elif st.session_state.question_no == 6:
96
+ bp = st.number_input(f"{st.session_state.question_no}Enter your blood pressure", key=st.session_state.question_no)
97
+ if st.button("Next->"):
98
+ st.session_state.bp = int(bp)
99
+ st.session_state.question_no += 1
100
+
101
+ elif st.session_state.question_no == 7:
102
+ height = st.number_input(f"{st.session_state.question_no}Enter your height in cm:")
103
+ if st.button("Next->"):
104
+ st.session_state.height = float(height/100)
105
+ st.session_state.question_no += 1
106
+
107
+ elif st.session_state.question_no == 8:
108
+ weight = st.number_input(f"{st.session_state.question_no}Enter your weight in KG")
109
+ if st.button("Next->"):
110
+ st.session_state.weight = float(weight)
111
+ st.session_state.bmi = calculate_bmi(st.session_state.weight, st.session_state.height)
112
+ st.session_state.question_no += 1
113
+
114
+ elif st.session_state.question_no == 9:
115
+ st.write("Select the members with diabetes in your family")
116
+ diabeticMother = st.checkbox("Mother")
117
+ diabeticFather = st.checkbox("Father")
118
+ diabeticSibling = st.number_input("Enter the number of diabetic siblings in your family", key=st.session_state.question_no)
119
+ if st.button("Next->"):
120
+ st.session_state.diabeticMother = 1 if diabeticMother else 0
121
+ st.session_state.diabeticFather = 1 if diabeticFather else 0
122
+ st.session_state.diabeticSibling = int(diabeticSibling)
123
+ st.session_state.dpf = diabetic_pedigree_function(st.session_state.diabeticMother, st.session_state.diabeticFather, st.session_state.diabeticSibling, st.session_state.diabeticSibling)
124
+ st.session_state.question_no += 1
125
+
126
+ elif st.session_state.question_no == 10:
127
+
128
+
129
+
130
+
131
+