Springboardmen commited on
Commit
e14cd6a
·
verified ·
1 Parent(s): 1ecb439

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +52 -59
src/streamlit_app.py CHANGED
@@ -7,13 +7,12 @@ st.set_page_config(page_title="FitPlan AI", layout="centered")
7
  # LOAD MODEL
8
  @st.cache_resource
9
  def load_model():
10
- tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-large")
11
- model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large")
12
  return tokenizer, model
13
 
14
  tokenizer, model = load_model()
15
 
16
-
17
  # TITLE
18
  st.title(" FitPlan AI – User Fitness Profile")
19
 
@@ -130,70 +129,64 @@ fitness_level = st.radio(
130
  horizontal=True
131
  )
132
 
133
- def create_prompt(gender, bmi, bmi_status, goal, level, equipment):
134
-
135
- equipment_list = ", ".join(equipment)
136
-
137
- prompt = f"""
138
- Instruction:
139
- You are a certified professional fitness trainer.
140
-
141
- Generate a structured 5-day workout plan.
142
-
143
- User Information:
144
- Gender: {gender}
145
- BMI: {bmi:.2f} ({bmi_status})
146
- Goal: {goal}
147
- Fitness Level: {level}
148
- Equipment Available: {equipment_list}
149
-
150
- Rules:
151
- 1. Only generate Day 1 to Day 5.
152
- 2. Each day must include:
153
- - Focus
154
- - 4 exercises
155
- - Sets x Reps
156
- - Rest time
157
- 3. Do not repeat days.
158
- 4. Do not generate explanations.
159
- 5. Keep output clean and professional.
160
-
161
- Start directly with:
162
- Day 1:
163
- """
164
 
165
- return prompt
 
166
 
167
- def generate_workout_plan(prompt):
 
168
 
169
- inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
 
170
 
171
- outputs = model.generate(
172
- **inputs,
173
- max_new_tokens=400,
174
- num_beams=4,
175
- early_stopping=True,
176
- no_repeat_ngram_size=3
177
- )
178
 
179
- result = tokenizer.decode(outputs[0], skip_special_tokens=True)
 
180
 
181
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
 
 
183
 
184
- if st.button("Submit Profile"):
185
 
186
- prompt = create_prompt(
187
- gender,
188
- bmi,
189
- bmi_status,
190
- goal,
191
- fitness_level,
192
- equipment
193
- )
194
 
195
- with st.spinner("Generating AI workout plan..."):
196
- result = generate_workout_plan(prompt)
197
 
198
- st.subheader("Your Personalized Workout Plan")
199
- st.write(result)
 
7
  # LOAD MODEL
8
  @st.cache_resource
9
  def load_model():
10
+ tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
11
+ model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
12
  return tokenizer, model
13
 
14
  tokenizer, model = load_model()
15
 
 
16
  # TITLE
17
  st.title(" FitPlan AI – User Fitness Profile")
18
 
 
129
  horizontal=True
130
  )
131
 
132
+ # SUBMIT BUTTON
133
+ if st.button(" Submit Profile"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
 
135
+ if not name:
136
+ st.error("Please enter your name.")
137
 
138
+ elif height <= 0 or weight <= 0:
139
+ st.error("Please enter valid height and weight.")
140
 
141
+ elif not equipment:
142
+ st.error("Please select at least one equipment option.")
143
 
144
+ else:
145
+ st.success("✅ Profile Submitted Successfully!")
 
 
 
 
 
146
 
147
+ bmi_status = bmi_category(bmi)
148
+ equipment_list = ", ".join(equipment)
149
 
150
+ prompt = f"""
151
+ You are a certified professional fitness trainer.
152
+ Generate a structured 5-day workout plan based on the following user profile.
153
+ User Profile:
154
+ - Gender: {gender}
155
+ - BMI: {bmi:.2f} ({bmi_status})
156
+ - Goal: {goal}
157
+ - Fitness Level: {fitness_level}
158
+ - Available Equipment: {equipment_list}
159
+ Instructions:
160
+ - Divide into Day 1 to Day 5
161
+ - Use EXACT format below
162
+ - Do not change format
163
+ - Do not add extra text
164
+ Strict Format:
165
+ Day 1: <Workout Focus>
166
+ 1. <Exercise Name>
167
+ Sets: <number>
168
+ Reps: <range>
169
+ Rest: <seconds>
170
+ 2. <Exercise Name>
171
+ Sets: <number>
172
+ Reps: <range>
173
+ Rest: <seconds>
174
+ Repeat same structure for all 5 days.
175
+ Only return the workout plan.
176
+ """
177
 
178
+ with st.spinner("Generating your AI workout plan..."):
179
 
180
+ inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
181
 
182
+ outputs = model.generate(
183
+ **inputs,
184
+ max_new_tokens=300,
185
+ temperature=0.7,
186
+ do_sample=True
187
+ )
 
 
188
 
189
+ result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
 
190
 
191
+ st.subheader("🏋️ Your Personalized Workout Plan")
192
+ st.write(result)