Spaces:
Sleeping
Sleeping
KrSharangrav
commited on
Commit
·
eac2c25
1
Parent(s):
569c166
streamlit bmi app
Browse files
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# give a title to our app
|
| 4 |
+
st.title('Welcome to BMI Calculator')
|
| 5 |
+
|
| 6 |
+
# TAKE WEIGHT INPUT in kgs
|
| 7 |
+
weight = st.number_input("Enter your weight (in kgs)")
|
| 8 |
+
|
| 9 |
+
# TAKE HEIGHT INPUT
|
| 10 |
+
# radio button to choose height format
|
| 11 |
+
status = st.radio('Select your height format: ', ('cms', 'meters', 'feet'))
|
| 12 |
+
|
| 13 |
+
# compare status value
|
| 14 |
+
if status == 'cms':
|
| 15 |
+
# take height input in centimeters
|
| 16 |
+
height = st.number_input('Centimeters')
|
| 17 |
+
try:
|
| 18 |
+
bmi = weight / ((height / 100) ** 2)
|
| 19 |
+
except:
|
| 20 |
+
st.text("Enter some value of height")
|
| 21 |
+
|
| 22 |
+
elif status == 'meters':
|
| 23 |
+
# take height input in meters
|
| 24 |
+
height = st.number_input('Meters')
|
| 25 |
+
try:
|
| 26 |
+
bmi = weight / (height ** 2)
|
| 27 |
+
except:
|
| 28 |
+
st.text("Enter some value of height")
|
| 29 |
+
|
| 30 |
+
else:
|
| 31 |
+
# take height input in feet
|
| 32 |
+
height = st.number_input('Feet')
|
| 33 |
+
# 1 meter = 3.28 feet
|
| 34 |
+
try:
|
| 35 |
+
bmi = weight / ((height / 3.28) ** 2)
|
| 36 |
+
except:
|
| 37 |
+
st.text("Enter some value of height")
|
| 38 |
+
|
| 39 |
+
# check if the button is pressed or not
|
| 40 |
+
if st.button('Calculate BMI'):
|
| 41 |
+
# print the BMI INDEX
|
| 42 |
+
st.text("Your BMI Index is {}.".format(bmi))
|
| 43 |
+
|
| 44 |
+
# give the interpretation of BMI index
|
| 45 |
+
if bmi < 16:
|
| 46 |
+
st.error("You are Extremely Underweight")
|
| 47 |
+
elif bmi >= 16 and bmi < 18.5:
|
| 48 |
+
st.warning("You are Underweight")
|
| 49 |
+
elif bmi >= 18.5 and bmi < 25:
|
| 50 |
+
st.success("Healthy")
|
| 51 |
+
elif bmi >= 25 and bmi < 30:
|
| 52 |
+
st.warning("Overweight")
|
| 53 |
+
elif bmi >= 30:
|
| 54 |
+
st.error("Extremely Overweight")
|