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