Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # BMI Calculation function | |
| def calculate_bmi(weight, height): | |
| try: | |
| weight = float(weight) | |
| height = float(height) | |
| if height <= 0 or weight <= 0: | |
| return "β Height and weight must be greater than zero." | |
| bmi = weight / (height ** 2) | |
| if bmi < 18.5: | |
| category = "Underweight" | |
| elif 18.5 <= bmi < 24.9: | |
| category = "Normal weight" | |
| elif 25 <= bmi < 29.9: | |
| category = "Overweight" | |
| else: | |
| category = "Obese" | |
| return f"π Your BMI is: {bmi:.2f} ({category})" | |
| except Exception as e: | |
| return f"β Error: {str(e)}" | |
| # Gradio interface | |
| demo = gr.Interface( | |
| fn=calculate_bmi, | |
| inputs=[ | |
| gr.Textbox(label="Weight (kg)", placeholder="Enter your weight in kg"), | |
| gr.Textbox(label="Height (m)", placeholder="Enter your height in meters") | |
| ], | |
| outputs="text", | |
| title="βοΈ BMI Calculator", | |
| description="Enter your weight (kg) and height (m) to calculate your Body Mass Index." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |