Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,62 +1,36 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
app = Flask(__name__)
|
| 4 |
-
|
| 5 |
-
HTML_TEMPLATE = '''
|
| 6 |
-
<!DOCTYPE html>
|
| 7 |
-
<html lang="en">
|
| 8 |
-
<head>
|
| 9 |
-
<meta charset="UTF-8">
|
| 10 |
-
<title>BMI Converter</title>
|
| 11 |
-
</head>
|
| 12 |
-
<body>
|
| 13 |
-
<h2>BMI Converter</h2>
|
| 14 |
-
<form method="post">
|
| 15 |
-
<label>Weight (in kg):</label><br>
|
| 16 |
-
<input type="number" step="any" name="weight" required><br><br>
|
| 17 |
-
|
| 18 |
-
<label>Height:</label><br>
|
| 19 |
-
<input type="number" name="feet" placeholder="Feet" required> ft
|
| 20 |
-
<input type="number" name="inches" placeholder="Inches" required> in<br><br>
|
| 21 |
-
|
| 22 |
-
<input type="submit" value="Calculate BMI">
|
| 23 |
-
</form>
|
| 24 |
-
|
| 25 |
-
{% if bmi %}
|
| 26 |
-
<h3>Your BMI is: {{ bmi }}</h3>
|
| 27 |
-
<p>{{ message }}</p>
|
| 28 |
-
{% endif %}
|
| 29 |
-
</body>
|
| 30 |
-
</html>
|
| 31 |
-
'''
|
| 32 |
|
| 33 |
def calculate_bmi(weight, feet, inches):
|
| 34 |
-
total_inches =
|
| 35 |
height_meters = total_inches * 0.0254
|
| 36 |
bmi = weight / (height_meters ** 2)
|
| 37 |
return round(bmi, 2)
|
| 38 |
|
| 39 |
-
def
|
| 40 |
if bmi < 18.5:
|
| 41 |
-
return "
|
| 42 |
elif 18.5 <= bmi < 24.9:
|
| 43 |
-
return "
|
| 44 |
elif 25 <= bmi < 29.9:
|
| 45 |
-
return "
|
| 46 |
else:
|
| 47 |
-
return "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
bmi = calculate_bmi(weight, feet, inches)
|
| 58 |
-
message = bmi_message(bmi)
|
| 59 |
-
return render_template_string(HTML_TEMPLATE, bmi=bmi, message=message)
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
| 62 |
-
|
|
|
|
| 1 |
+
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def calculate_bmi(weight, feet, inches):
|
| 4 |
+
total_inches = feet * 12 + inches
|
| 5 |
height_meters = total_inches * 0.0254
|
| 6 |
bmi = weight / (height_meters ** 2)
|
| 7 |
return round(bmi, 2)
|
| 8 |
|
| 9 |
+
def bmi_category(bmi):
|
| 10 |
if bmi < 18.5:
|
| 11 |
+
return "Underweight"
|
| 12 |
elif 18.5 <= bmi < 24.9:
|
| 13 |
+
return "Normal weight"
|
| 14 |
elif 25 <= bmi < 29.9:
|
| 15 |
+
return "Overweight"
|
| 16 |
else:
|
| 17 |
+
return "Obesity"
|
| 18 |
+
|
| 19 |
+
def main():
|
| 20 |
+
st.title("BMI Converter")
|
| 21 |
+
|
| 22 |
+
weight = st.number_input("Enter your weight (in kg):", min_value=0.0, format="%.2f")
|
| 23 |
+
feet = st.number_input("Enter your height - Feet:", min_value=0, format="%d")
|
| 24 |
+
inches = st.number_input("Enter your height - Inches:", min_value=0, max_value=11, format="%d")
|
| 25 |
|
| 26 |
+
if st.button("Calculate BMI"):
|
| 27 |
+
if feet == 0 and inches == 0:
|
| 28 |
+
st.error("Height cannot be zero!")
|
| 29 |
+
else:
|
| 30 |
+
bmi = calculate_bmi(weight, feet, inches)
|
| 31 |
+
category = bmi_category(bmi)
|
| 32 |
+
st.success(f"Your BMI is: {bmi}")
|
| 33 |
+
st.info(f"Category: {category}")
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
if __name__ == "__main__":
|
| 36 |
+
main()
|