ARaffay01's picture
Rename app.py_2 to app.py
8e15f7e verified
import streamlit as st
# Title of the app
st.title("BMI Calculator")
# Description
st.write("Calculate your Body Mass Index (BMI) by entering your weight and height.")
# Input fields
weight = st.number_input("Enter your weight (kg):", min_value=0.0, value=70.0)
height = st.number_input("Enter your height (cm):", min_value=0.0, value=170.0)
# Calculate BMI
if st.button("Calculate BMI"):
if height <= 0 or weight <= 0:
st.error("Weight and height must be positive numbers.")
else:
bmi = weight / ((height / 100) ** 2) # BMI formula
bmi = round(bmi, 2)
# Categorize BMI
if bmi < 18.5:
category = "Underweight"
elif 18.5 <= bmi < 24.9:
category = "Normal weight"
elif 25 <= bmi < 29.9:
category = "Overweight"
else:
category = "Obesity"
st.success(f"Your BMI is **{bmi}** ({category}).")
# Display BMI Chart
st.write("### BMI Chart")
st.image("bmi_chart.jpg", caption="BMI Categories", use_column_width=True)