srbhavya01 commited on
Commit
45cabc8
Β·
verified Β·
1 Parent(s): 61ad82a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -75
app.py CHANGED
@@ -1,109 +1,81 @@
1
  import streamlit as st
2
 
3
- # -------------------------
4
- # Page Config
5
- # -------------------------
6
 
7
- st.set_page_config(page_title="FitPlan AI", page_icon="πŸ’ͺ")
8
 
9
- st.title("πŸ’ͺ FitPlan AI β€” Personalized Workout Generator")
10
 
11
  # -------------------------
12
- # BMI Functions
13
  # -------------------------
14
 
15
- def calculate_bmi(weight, height):
16
- height_m = height / 100
17
- return weight / (height_m ** 2)
18
 
19
- def bmi_category(bmi):
20
- if bmi < 18.5:
21
- return "Underweight"
22
- elif bmi < 25:
23
- return "Normal Weight"
24
- elif bmi < 30:
25
- return "Overweight"
26
- else:
27
- return "Obese"
28
 
29
  # -------------------------
30
- # Prompt Builder Function
31
  # -------------------------
32
 
33
- def build_prompt(name, gender, height, weight, goal, fitness_level, equipment):
34
-
35
- bmi = calculate_bmi(weight, height)
36
- bmi_status = bmi_category(bmi)
37
-
38
- equipment_list = ", ".join(equipment) if equipment else "No Equipment"
39
-
40
- prompt = f"""
41
- You are a certified professional fitness trainer.
42
-
43
- Create a STRICTLY FORMATTED 5-day personalized workout plan.
44
-
45
- User Profile:
46
- Name: {name}
47
- Gender: {gender}
48
- Height: {height} cm
49
- Weight: {weight} kg
50
- BMI: {bmi:.2f} ({bmi_status})
51
- Goal: {goal}
52
- Fitness Level: {fitness_level}
53
- Available Equipment: {equipment_list}
54
-
55
- Instructions:
56
- β€’ Divide into Day 1 to Day 5
57
- β€’ Include Warm-up
58
- β€’ Include Exercises with Sets Γ— Reps
59
- β€’ Include Rest Time
60
- β€’ Adjust intensity based on BMI
61
- """
62
-
63
- return prompt, bmi, bmi_status
64
- # -------------------------
65
- # User Inputs
66
- # -------------------------
67
-
68
- name = st.text_input("Enter Your Name")
69
- gender = st.selectbox("Gender", ["Male", "Female", "Other"])
70
- height = st.number_input("Height (cm)", min_value=0.0)
71
- weight = st.number_input("Weight (kg)", min_value=0.0)
72
 
73
  goal = st.selectbox(
74
- "Fitness Goal",
75
  ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
76
  )
77
 
78
  equipment = st.multiselect(
79
- "Available Equipment",
80
- ["Dumbbells", "Resistance Band", "Yoga Mat", "Skipping Rope",
81
- "Weight Plates", "Cycling", "Inclined Bench", "Pullups Bar", "No Equipment"]
82
  )
83
 
84
  fitness_level = st.radio(
85
- "Fitness Level",
86
  ["Beginner", "Intermediate", "Advanced"]
87
  )
88
 
89
  # -------------------------
90
- # Generate Plan
91
  # -------------------------
92
 
93
- if st.button("Generate Workout Plan"):
 
 
 
94
 
95
- if not name or height <= 0 or weight <= 0:
96
- st.error("Please fill all required fields")
 
 
 
 
 
97
  else:
 
 
 
 
 
98
 
99
- prompt, bmi, bmi_status = build_prompt(
100
- name, gender, height, weight,
101
- goal, fitness_level, equipment
102
- )
 
 
 
 
103
 
104
- st.success(f"BMI: {bmi:.2f} ({bmi_status})")
105
 
106
- with st.spinner("Generating your personalized workout plan..."):
 
 
107
 
108
- st.subheader("πŸ‹οΈ Your Workout Plan")
109
- st.write(result)
 
 
 
 
1
  import streamlit as st
2
 
3
+ st.set_page_config(page_title="FitPlan AI - BMI Calculator", page_icon="πŸ’ͺ")
 
 
4
 
5
+ st.title("πŸ’ͺ FitPlan AI - Fitness Profile & BMI Calculator")
6
 
7
+ st.write("Fill in your details to calculate your BMI and fitness category.")
8
 
9
  # -------------------------
10
+ # 1. Personal Information
11
  # -------------------------
12
 
13
+ name = st.text_input("Enter Your Name *")
 
 
14
 
15
+ height_cm = st.number_input("Enter Height (in centimeters) *", min_value=0.0, format="%.2f")
16
+ weight_kg = st.number_input("Enter Weight (in kilograms) *", min_value=0.0, format="%.2f")
 
 
 
 
 
 
 
17
 
18
  # -------------------------
19
+ # 2. Fitness Details
20
  # -------------------------
21
 
22
+ st.subheader("Fitness Details")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  goal = st.selectbox(
25
+ "Select Your Fitness Goal",
26
  ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
27
  )
28
 
29
  equipment = st.multiselect(
30
+ "Available Equipment (Select multiple if available)",
31
+ ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment"]
 
32
  )
33
 
34
  fitness_level = st.radio(
35
+ "Select Your Fitness Level",
36
  ["Beginner", "Intermediate", "Advanced"]
37
  )
38
 
39
  # -------------------------
40
+ # BMI Calculation Function
41
  # -------------------------
42
 
43
+ def calculate_bmi(weight, height_cm):
44
+ height_m = height_cm / 100 # Convert cm to meters
45
+ bmi = weight / (height_m ** 2)
46
+ return round(bmi, 2)
47
 
48
+ def bmi_category(bmi):
49
+ if bmi < 18.5:
50
+ return "Underweight"
51
+ elif 18.5 <= bmi < 24.9:
52
+ return "Normal"
53
+ elif 25 <= bmi < 29.9:
54
+ return "Overweight"
55
  else:
56
+ return "Obese"
57
+
58
+ # -------------------------
59
+ # Submit Button
60
+ # -------------------------
61
 
62
+ if st.button("Calculate BMI"):
63
+
64
+ # Validation
65
+ if not name or height_cm <= 0 or weight_kg <= 0:
66
+ st.error("⚠ Please fill all required fields with valid values!")
67
+ else:
68
+ bmi = calculate_bmi(weight_kg, height_cm)
69
+ category = bmi_category(bmi)
70
 
71
+ st.success("βœ… Calculation Successful!")
72
 
73
+ st.write(f"### πŸ‘€ Name: {name}")
74
+ st.write(f"### πŸ“Š Your BMI: {bmi}")
75
+ st.write(f"### 🏷 BMI Category: {category}")
76
 
77
+ st.write("---")
78
+ st.write("### πŸ‹ Fitness Summary")
79
+ st.write(f"**Goal:** {goal}")
80
+ st.write(f"**Fitness Level:** {fitness_level}")
81
+ st.write(f"**Equipment Available:** {', '.join(equipment) if equipment else 'None selected'}")