File size: 1,161 Bytes
17e1cb8
 
750ebae
 
 
 
 
 
 
 
17e1cb8
 
 
 
 
 
 
 
 
 
750ebae
 
 
8684c7a
750ebae
17e1cb8
 
8684c7a
bb6c8db
17e1cb8
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
    ],
    outputs="text",
    title="BMI Calculator",
    description="Enter your weight in kilograms (kg), height in feet, and inches. Click 'Submit' to calculate your BMI.",
    live=False  # This will require user to click "Submit" button to trigger the function
)

# Launch the interface
interface.launch()