Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,40 @@
|
|
| 1 |
-
|
| 2 |
import streamlit as st
|
| 3 |
-
st.title("BMI Calculator")
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
height =
|
| 9 |
-
if
|
| 10 |
-
height = height
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
else:
|
| 25 |
-
st.error("
|
| 26 |
-
else:
|
| 27 |
-
st.error("Please enter a valid height.")
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
+
st.title("BMI Calculator App")
|
| 4 |
+
|
| 5 |
+
# Input weight
|
| 6 |
+
weight = st.number_input("Enter your weight (in kgs)", min_value=0.0, step=0.1)
|
| 7 |
+
|
| 8 |
+
# Select height format
|
| 9 |
+
status = st.radio('Select your height format:', ('cms', 'meters', 'feet'))
|
| 10 |
|
| 11 |
+
# Input height based on selection
|
| 12 |
+
height = 0
|
| 13 |
+
if status == 'cms':
|
| 14 |
+
height = st.number_input('Enter height in Centimeters', min_value=0.0, step=0.1)
|
| 15 |
+
height /= 100 # Convert to meters
|
| 16 |
+
elif status == 'meters':
|
| 17 |
+
height = st.number_input('Enter height in Meters', min_value=0.0, step=0.01)
|
| 18 |
+
elif status == 'feet':
|
| 19 |
+
height = st.number_input('Enter height in Feet', min_value=0.0, step=0.1)
|
| 20 |
+
height /= 3.281 # Convert to meters
|
| 21 |
|
| 22 |
+
# BMI Calculation and Display
|
| 23 |
+
if st.button('Calculate BMI'):
|
| 24 |
+
if height > 0:
|
| 25 |
+
bmi = weight / (height ** 2)
|
| 26 |
+
st.text(f"Your BMI Index is {bmi:.2f}.")
|
| 27 |
|
| 28 |
+
# Categorizing BMI
|
| 29 |
+
if bmi < 16:
|
| 30 |
+
st.error("You are Extremely Underweight")
|
| 31 |
+
elif 16 <= bmi < 18.5:
|
| 32 |
+
st.warning("You are Underweight")
|
| 33 |
+
elif 18.5 <= bmi < 25:
|
| 34 |
+
st.success("You are Healthy")
|
| 35 |
+
elif 25 <= bmi < 30:
|
| 36 |
+
st.warning("You are Overweight")
|
| 37 |
+
else:
|
| 38 |
+
st.error("You are Extremely Overweight")
|
| 39 |
else:
|
| 40 |
+
st.error("Please enter a valid height greater than 0.")
|
|
|
|
|
|