Springboardmen commited on
Commit
2cf4a4b
Β·
verified Β·
1 Parent(s): 850b633

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +27 -104
src/streamlit_app.py CHANGED
@@ -1,67 +1,44 @@
1
  import streamlit as st
2
- from transformers import pipeline
3
 
4
  # ---------------------------------------------------
5
  # PAGE CONFIG
6
  # ---------------------------------------------------
7
- st.set_page_config(page_title="FitPlan AI", layout="centered")
8
 
9
- st.title("πŸ‹οΈ FitPlan AI – Personalized Fitness Plan")
10
 
11
  # ---------------------------------------------------
12
- # LOAD MODEL (Cached)
13
- # ---------------------------------------------------
14
- @st.cache_resource
15
- def load_model():
16
- return pipeline(
17
- "text-generation",
18
- model="google/flan-t5-base"
19
- )
20
-
21
- generator = load_model()
22
-
23
- # ---------------------------------------------------
24
- # USER DETAILS
25
  # ---------------------------------------------------
26
  st.subheader("πŸ‘€ Personal Information")
27
 
28
  name = st.text_input("Enter Your Name")
29
 
 
 
 
 
 
30
  col1, col2 = st.columns(2)
31
 
32
  with col1:
33
- height = st.number_input("Height (in cm)", min_value=100, max_value=250, value=170)
34
 
35
  with col2:
36
- weight = st.number_input("Weight (in kg)", min_value=30, max_value=200, value=70)
37
 
38
  # ---------------------------------------------------
39
- # BMI CALCULATION
40
  # ---------------------------------------------------
41
  bmi = None
42
- bmi_category = ""
43
 
44
  if height > 0 and weight > 0:
45
  height_m = height / 100
46
  bmi = weight / (height_m ** 2)
47
-
48
  st.write(f"### πŸ“Š Your BMI: {bmi:.2f}")
49
 
50
- if bmi < 18.5:
51
- bmi_category = "Underweight"
52
- st.info("Category: Underweight")
53
- elif 18.5 <= bmi < 24.9:
54
- bmi_category = "Normal weight"
55
- st.success("Category: Normal weight")
56
- elif 25 <= bmi < 29.9:
57
- bmi_category = "Overweight"
58
- st.warning("Category: Overweight")
59
- else:
60
- bmi_category = "Obese"
61
- st.error("Category: Obese")
62
-
63
  # ---------------------------------------------------
64
- # GOAL
65
  # ---------------------------------------------------
66
  st.subheader("🎯 Fitness Goal")
67
 
@@ -79,7 +56,7 @@ goal = st.selectbox(
79
  # ---------------------------------------------------
80
  # EQUIPMENT
81
  # ---------------------------------------------------
82
- st.subheader("πŸ‹οΈ Available Equipment")
83
 
84
  col1, col2 = st.columns(2)
85
 
@@ -88,17 +65,12 @@ with col1:
88
  resistance_band = st.checkbox("Resistance Band")
89
  yoga_mat = st.checkbox("Yoga Mat")
90
  no_equipment = st.checkbox("No Equipment")
91
- inclined_bench = st.checkbox("Inclined Bench")
92
- treadmill = st.checkbox("Treadmill")
93
- cycle = st.checkbox("Cycle")
94
 
95
  with col2:
96
- skipping_rope = st.checkbox("Skipping Rope")
97
- hand_gripper = st.checkbox("Hand Gripper")
98
  pullups_bar = st.checkbox("Pullups Bar")
99
  weight_plates = st.checkbox("Weight Plates")
100
- hula_hoop = st.checkbox("Hula Hoop Ring")
101
- bosu_ball = st.checkbox("Bosu Ball")
102
 
103
  equipment = []
104
 
@@ -107,15 +79,10 @@ equipment_map = {
107
  "Resistance Band": resistance_band,
108
  "Yoga Mat": yoga_mat,
109
  "No Equipment": no_equipment,
110
- "Inclined Bench": inclined_bench,
111
  "Treadmill": treadmill,
112
  "Cycle": cycle,
113
- "Skipping Rope": skipping_rope,
114
- "Hand Gripper": hand_gripper,
115
  "Pullups Bar": pullups_bar,
116
  "Weight Plates": weight_plates,
117
- "Hula Hoop Ring": hula_hoop,
118
- "Bosu Ball": bosu_ball,
119
  }
120
 
121
  for item, selected in equipment_map.items():
@@ -134,66 +101,22 @@ fitness_level = st.radio(
134
  )
135
 
136
  # ---------------------------------------------------
137
- # PROMPT BUILDER
138
- # ---------------------------------------------------
139
- def build_prompt(name, goal, fitness_level, equipment, bmi, bmi_category):
140
- equipment_text = ", ".join(equipment)
141
-
142
- prompt = f"""
143
- Generate a detailed 5-day personalized workout plan.
144
-
145
- Name: {name}
146
- Goal: {goal}
147
- Fitness Level: {fitness_level}
148
- BMI: {bmi:.2f}
149
- BMI Category: {bmi_category}
150
- Available Equipment: {equipment_text}
151
-
152
- Adjust workout intensity according to BMI and fitness level.
153
-
154
- Include:
155
- - Day-wise workout split
156
- - Exercises
157
- - Sets and reps
158
- - Rest time
159
- - Warm-up and cool-down
160
- """
161
-
162
- return prompt
163
-
164
-
165
- # ---------------------------------------------------
166
- # GENERATE PLAN BUTTON
167
  # ---------------------------------------------------
168
- if st.button("πŸš€ Generate Personalized Plan"):
169
 
170
  if not name:
171
  st.error("Please enter your name.")
172
  elif not equipment:
173
  st.error("Please select at least one equipment option.")
174
- elif bmi is None:
175
- st.error("Please enter valid height and weight.")
176
  else:
177
- with st.spinner("Generating your AI workout plan..."):
178
-
179
- prompt = build_prompt(
180
- name,
181
- goal,
182
- fitness_level,
183
- equipment,
184
- bmi,
185
- bmi_category
186
- )
187
-
188
- result = generator(
189
- prompt,
190
- max_length=600,
191
- do_sample=True,
192
- temperature=0.7
193
- )
194
-
195
- plan = result[0]["generated_text"]
196
-
197
- st.success(f"βœ… Plan Generated Successfully, {name}!")
198
- st.markdown("## πŸ“ Your Personalized Workout Plan")
199
- st.write(plan)
 
1
  import streamlit as st
 
2
 
3
  # ---------------------------------------------------
4
  # PAGE CONFIG
5
  # ---------------------------------------------------
6
+ st.set_page_config(page_title="FitPlan AI", layout="wide")
7
 
8
+ st.title(" FitPlan AI – User Fitness Profile")
9
 
10
  # ---------------------------------------------------
11
+ # PERSONAL INFORMATION
 
 
 
 
 
 
 
 
 
 
 
 
12
  # ---------------------------------------------------
13
  st.subheader("πŸ‘€ Personal Information")
14
 
15
  name = st.text_input("Enter Your Name")
16
 
17
+ gender = st.selectbox(
18
+ "Gender",
19
+ ["Male", "Female", "Other"]
20
+ )
21
+
22
  col1, col2 = st.columns(2)
23
 
24
  with col1:
25
+ height = st.number_input("Height (in cm)", min_value=100, max_value=250)
26
 
27
  with col2:
28
+ weight = st.number_input("Weight (in kg)", min_value=30, max_value=200)
29
 
30
  # ---------------------------------------------------
31
+ # BMI CALCULATION (Basic Logic Only)
32
  # ---------------------------------------------------
33
  bmi = None
 
34
 
35
  if height > 0 and weight > 0:
36
  height_m = height / 100
37
  bmi = weight / (height_m ** 2)
 
38
  st.write(f"### πŸ“Š Your BMI: {bmi:.2f}")
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  # ---------------------------------------------------
41
+ # FITNESS GOAL
42
  # ---------------------------------------------------
43
  st.subheader("🎯 Fitness Goal")
44
 
 
56
  # ---------------------------------------------------
57
  # EQUIPMENT
58
  # ---------------------------------------------------
59
+ st.subheader("Available Equipment")
60
 
61
  col1, col2 = st.columns(2)
62
 
 
65
  resistance_band = st.checkbox("Resistance Band")
66
  yoga_mat = st.checkbox("Yoga Mat")
67
  no_equipment = st.checkbox("No Equipment")
 
 
 
68
 
69
  with col2:
70
+ treadmill = st.checkbox("Treadmill")
71
+ cycle = st.checkbox("Cycle")
72
  pullups_bar = st.checkbox("Pullups Bar")
73
  weight_plates = st.checkbox("Weight Plates")
 
 
74
 
75
  equipment = []
76
 
 
79
  "Resistance Band": resistance_band,
80
  "Yoga Mat": yoga_mat,
81
  "No Equipment": no_equipment,
 
82
  "Treadmill": treadmill,
83
  "Cycle": cycle,
 
 
84
  "Pullups Bar": pullups_bar,
85
  "Weight Plates": weight_plates,
 
 
86
  }
87
 
88
  for item, selected in equipment_map.items():
 
101
  )
102
 
103
  # ---------------------------------------------------
104
+ # SUBMIT BUTTON (Backend Receiving Data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  # ---------------------------------------------------
106
+ if st.button("Submit Profile"):
107
 
108
  if not name:
109
  st.error("Please enter your name.")
110
  elif not equipment:
111
  st.error("Please select at least one equipment option.")
 
 
112
  else:
113
+ st.success("βœ… Profile Submitted Successfully!")
114
+
115
+ st.json({
116
+ "Name": name,
117
+ "Gender": gender,
118
+ "BMI": round(bmi, 2) if bmi else None,
119
+ "Goal": goal,
120
+ "Fitness Level": fitness_level,
121
+ "Equipment": equipment
122
+ })