BMI-calculator / app.py
pratikshahp's picture
Update app.py
428932b verified
raw
history blame
1.15 kB
import gradio as gr
def calculate_bmi(weight, feet, inches):
# Convert height to meters (1 foot = 0.3048 meters, 1 inch = 0.0254 meters)
height_in_meters = (feet * 0.3048) + (inches * 0.0254)
# Calculate BMI
bmi = weight / (height_in_meters ** 2)
# Return BMI category
if bmi < 18.5:
return f"Your BMI is {bmi:.2f}. You are underweight."
elif 18.5 <= bmi < 24.9:
return f"Your BMI is {bmi:.2f}. You have a normal weight."
else:
return f"Your BMI is {bmi:.2f}. You are overweight."
# Create the Gradio interface with a title and custom layout
interface = gr.Interface(
fn=calculate_bmi,
inputs=[
gr.Number(label="Weight (kg)"), # Input for weight
gr.Number(label="Feet"), # Input for feet
gr.Number(label="Inches"), # Input for inches
gr.Button("Submit") # Submit button
],
outputs="text",
title="BMI Calculator",
description="Enter your weight in kilograms (kg), height in feet, and inches to calculate your Body Mass Index (BMI).",
live=True
)
# Launch the interface
interface.launch()