manaskhan commited on
Commit
c7504d2
·
verified ·
1 Parent(s): 3e445fe

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # BMI Calculation function
4
+ def calculate_bmi(weight, height):
5
+ try:
6
+ weight = float(weight)
7
+ height = float(height)
8
+
9
+ if height <= 0 or weight <= 0:
10
+ return "❌ Height and weight must be greater than zero."
11
+
12
+ bmi = weight / (height ** 2)
13
+
14
+ if bmi < 18.5:
15
+ category = "Underweight"
16
+ elif 18.5 <= bmi < 24.9:
17
+ category = "Normal weight"
18
+ elif 25 <= bmi < 29.9:
19
+ category = "Overweight"
20
+ else:
21
+ category = "Obese"
22
+
23
+ return f"📊 Your BMI is: {bmi:.2f} ({category})"
24
+
25
+ except Exception as e:
26
+ return f"❌ Error: {str(e)}"
27
+
28
+ # Gradio interface
29
+ demo = gr.Interface(
30
+ fn=calculate_bmi,
31
+ inputs=[
32
+ gr.Textbox(label="Weight (kg)", placeholder="Enter your weight in kg"),
33
+ gr.Textbox(label="Height (m)", placeholder="Enter your height in meters")
34
+ ],
35
+ outputs="text",
36
+ title="⚖️ BMI Calculator",
37
+ description="Enter your weight (kg) and height (m) to calculate your Body Mass Index."
38
+ )
39
+
40
+ if __name__ == "__main__":
41
+ demo.launch()