-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmi.py
125 lines (117 loc) · 3.37 KB
/
bmi.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import streamlit as st
def calculate_bmi(height, weight):
return weight / ((height/100) ** 2)
def interpret_bmi(bmi):
if bmi < 18.5:
return 'Underweight'
elif bmi < 25:
return 'Normal weight'
elif bmi < 30:
return 'Overweight'
else:
return 'Obese'
# Sidebar with BMI information
st.sidebar.title('BMI Information')
st.sidebar.write("""
BMI (Body Mass Index) is a measure of body fat based on your height and weight. It is commonly used to categorize individuals into underweight, normal weight, overweight, or obese.
""")
st.sidebar.write("""
- **Underweight:** BMI less than 18.5 😟
- **Normal weight:** BMI between 18.5 and 24.9 🙂
- **Overweight:** BMI between 25 and 29.9 😕
- **Obese:** BMI 30 or greater 😟
""")
st.title('BMI Calculator')
height = st.number_input('Height (in cm)', min_value=0.0, step=1.0)
weight = st.number_input('Weight (in kg)', min_value=0.0, step=0.1)
if st.button('Calculate BMI'):
bmi = calculate_bmi(height, weight)
bmi_category = interpret_bmi(bmi)
# Display BMI value and category
st.write(f'Your BMI is: **{bmi:.2f}**')
st.write(f'You are in the **{bmi_category}** category.')
# Display colored meter
if bmi_category == 'Underweight':
st.markdown("""
<style>
.meter {
height: 20px;
width: 200px;
background-color: #f4f4f4;
border-radius: 10px;
margin-bottom: 20px;
}
.meter-fill {
height: 100%;
width: 100%;
background-color: #2ecc71;
border-radius: 10px;
}
</style>
<div class="meter">
<div class="meter-fill"></div>
</div>
""", unsafe_allow_html=True)
elif bmi_category == 'Normal weight':
st.markdown("""
<style>
.meter {
height: 20px;
width: 200px;
background-color: #f4f4f4;
border-radius: 10px;
margin-bottom: 20px;
}
.meter-fill {
height: 100%;
width: 100%;
background-color: #f39c12;
border-radius: 10px;
}
</style>
<div class="meter">
<div class="meter-fill"></div>
</div>
""", unsafe_allow_html=True)
elif bmi_category == 'Overweight':
st.markdown("""
<style>
.meter {
height: 20px;
width: 200px;
background-color: #f4f4f4;
border-radius: 10px;
margin-bottom: 20px;
}
.meter-fill {
height: 100%;
width: 100%;
background-color: #e74c3c;
border-radius: 10px;
}
</style>
<div class="meter">
<div class="meter-fill"></div>
</div>
""", unsafe_allow_html=True)
else: # Obese
st.markdown("""
<style>
.meter {
height: 20px;
width: 200px;
background-color: #f4f4f4;
border-radius: 10px;
margin-bottom: 20px;
}
.meter-fill {
height: 100%;
width: 100%;
background-color: #3498db;
border-radius: 10px;
}
</style>
<div class="meter">
<div class="meter-fill"></div>
</div>
""", unsafe_allow_html=True)