js02vel commited on
Commit
0085977
Β·
verified Β·
1 Parent(s): aa36e47

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +34 -26
src/streamlit_app.py CHANGED
@@ -1,7 +1,10 @@
1
  import streamlit as st
2
- from transformers import pipeline
 
 
3
  # 1. Basic Configuration
4
  st.set_page_config(page_title="FitPlan AI", page_icon="πŸ’ͺ", layout="centered")
 
5
  def load_model():
6
  tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
7
  model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
@@ -115,10 +118,8 @@ with st.form("fitness_form", clear_on_submit=False):
115
 
116
  level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"], horizontal=True)
117
 
118
- # Submission Button
119
- submit = st.form_submit_button("GENERATE MY PLAN")
120
-
121
- if st.button("πŸš€ Submit Profile"):
122
 
123
  if not name:
124
  st.error("Please enter your name.")
@@ -130,33 +131,40 @@ if st.button("πŸš€ Submit Profile"):
130
  st.error("Please select at least one equipment option.")
131
 
132
  else:
133
- st.success("βœ… Profile Submitted Successfully!")
134
 
135
  bmi_status = bmi_category(bmi)
136
  equipment_list = ", ".join(equipment)
137
 
138
  prompt = f"""
139
- Generate a 5-day structured workout plan.
140
-
141
- User Details:
142
- Name: {name}
143
- Gender: {gender}
144
- BMI: {bmi:.2f} ({bmi_status})
145
- Goal: {goal}
146
- Fitness Level: {fitness_level}
147
- Available Equipment: {equipment_list}
148
-
149
- Requirements:
150
- - Include warmup
151
- - Include exercises with sets and reps
152
- - Include rest time
153
- - Adjust intensity based on BMI and fitness level
154
- - Keep it structured day-wise
155
- """
156
 
157
  with st.spinner("Generating your AI workout plan..."):
158
- response = generator(prompt, max_new_tokens=400)
159
- result = response[0]["generated_text"]
160
 
161
- st.subheader("πŸ‹οΈ Your Personalized Workout Plan")
 
 
 
 
 
 
 
 
 
 
 
162
  st.write(result)
 
1
  import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+ import torch
4
+
5
  # 1. Basic Configuration
6
  st.set_page_config(page_title="FitPlan AI", page_icon="πŸ’ͺ", layout="centered")
7
+
8
  def load_model():
9
  tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
10
  model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
 
118
 
119
  level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"], horizontal=True)
120
 
121
+ # SUBMIT BUTTON
122
+ if st.button(" Submit Profile"):
 
 
123
 
124
  if not name:
125
  st.error("Please enter your name.")
 
131
  st.error("Please select at least one equipment option.")
132
 
133
  else:
134
+ st.success(" Profile Submitted Successfully!")
135
 
136
  bmi_status = bmi_category(bmi)
137
  equipment_list = ", ".join(equipment)
138
 
139
  prompt = f"""
140
+ You are a certified professional fitness trainer.
141
+
142
+ Create a detailed 5-day workout plan.
143
+
144
+ User Information:
145
+ - Gender: {gender}
146
+ - BMI: {bmi:.2f} ({bmi_status})
147
+ - Goal: {goal}
148
+ - Fitness Level: {fitness_level}
149
+ - Equipment Available: {equipment_list}
150
+
151
+ Start directly with:
152
+
153
+ Day 1:
154
+ """
 
 
155
 
156
  with st.spinner("Generating your AI workout plan..."):
 
 
157
 
158
+ inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
159
+
160
+ outputs = model.generate(
161
+ **inputs,
162
+ max_new_tokens=900,
163
+ temperature=0.7,
164
+ do_sample=True
165
+ )
166
+
167
+ result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
168
+
169
+ st.subheader(" Your Personalized Workout Plan")
170
  st.write(result)