Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import matplotlib.pyplot as plt
|
|
|
|
| 3 |
|
| 4 |
st.set_page_config(page_title="BMI Calculator", page_icon="βοΈ")
|
| 5 |
st.title("βοΈ BMI Calculator")
|
|
@@ -7,6 +8,41 @@ st.title("βοΈ BMI Calculator")
|
|
| 7 |
# Gender/age group selector
|
| 8 |
category = st.selectbox("Select Category", ["Male", "Female", "Child"])
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Height input unit toggle
|
| 11 |
height_unit = st.radio("Choose height input unit", ["Centimeters (cm)", "Feet & Inches"])
|
| 12 |
|
|
@@ -49,10 +85,13 @@ if height_m > 0 and weight_kg > 0:
|
|
| 49 |
return "Obese"
|
| 50 |
|
| 51 |
category_label = bmi_category(bmi, category)
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
# Graphical representation
|
| 55 |
-
st.subheader("BMI Category Ranges")
|
| 56 |
|
| 57 |
fig, ax = plt.subplots(figsize=(8, 2))
|
| 58 |
|
|
@@ -76,3 +115,4 @@ if height_m > 0 and weight_kg > 0:
|
|
| 76 |
ax.legend(loc="upper center", bbox_to_anchor=(0.5, 1.25), ncol=4)
|
| 77 |
st.pyplot(fig)
|
| 78 |
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
+
from datetime import datetime
|
| 4 |
|
| 5 |
st.set_page_config(page_title="BMI Calculator", page_icon="βοΈ")
|
| 6 |
st.title("βοΈ BMI Calculator")
|
|
|
|
| 8 |
# Gender/age group selector
|
| 9 |
category = st.selectbox("Select Category", ["Male", "Female", "Child"])
|
| 10 |
|
| 11 |
+
# Age input
|
| 12 |
+
age = st.number_input("Enter your age (in years)", min_value=1, max_value=120, step=1)
|
| 13 |
+
|
| 14 |
+
# Approximate average height/weight based on age and gender
|
| 15 |
+
def get_avg_hw(age, group):
|
| 16 |
+
if group == "Child":
|
| 17 |
+
if age <= 2:
|
| 18 |
+
return (85, 12)
|
| 19 |
+
elif age <= 5:
|
| 20 |
+
return (105, 17)
|
| 21 |
+
elif age <= 10:
|
| 22 |
+
return (130, 25)
|
| 23 |
+
elif age <= 15:
|
| 24 |
+
return (155, 45)
|
| 25 |
+
else:
|
| 26 |
+
return (160, 50)
|
| 27 |
+
elif group == "Male":
|
| 28 |
+
if age < 20:
|
| 29 |
+
return (170, 60)
|
| 30 |
+
else:
|
| 31 |
+
return (175, 70)
|
| 32 |
+
elif group == "Female":
|
| 33 |
+
if age < 20:
|
| 34 |
+
return (160, 55)
|
| 35 |
+
else:
|
| 36 |
+
return (162, 60)
|
| 37 |
+
|
| 38 |
+
avg_height, avg_weight = get_avg_hw(age, category)
|
| 39 |
+
st.info(f"π Average for {category}, Age {age}: Height β {avg_height} cm | Weight β {avg_weight} kg")
|
| 40 |
+
|
| 41 |
+
# Date selector
|
| 42 |
+
st.subheader("π
Date of Measurement")
|
| 43 |
+
year = st.selectbox("Year", list(range(datetime.now().year, 1900, -1)))
|
| 44 |
+
month = st.selectbox("Month", list(range(1, 13)))
|
| 45 |
+
|
| 46 |
# Height input unit toggle
|
| 47 |
height_unit = st.radio("Choose height input unit", ["Centimeters (cm)", "Feet & Inches"])
|
| 48 |
|
|
|
|
| 85 |
return "Obese"
|
| 86 |
|
| 87 |
category_label = bmi_category(bmi, category)
|
| 88 |
+
|
| 89 |
+
# Display result with date
|
| 90 |
+
month_name = datetime(year, month, 1).strftime("%B")
|
| 91 |
+
st.success(f"Your BMI on **{month_name} {year}** is **{bmi}** ({category_label})")
|
| 92 |
|
| 93 |
# Graphical representation
|
| 94 |
+
st.subheader("π BMI Category Ranges")
|
| 95 |
|
| 96 |
fig, ax = plt.subplots(figsize=(8, 2))
|
| 97 |
|
|
|
|
| 115 |
ax.legend(loc="upper center", bbox_to_anchor=(0.5, 1.25), ncol=4)
|
| 116 |
st.pyplot(fig)
|
| 117 |
|
| 118 |
+
|