Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +27 -16
src/streamlit_app.py
CHANGED
|
@@ -5,9 +5,10 @@ import torch
|
|
| 5 |
st.set_page_config(page_title="FitPlan AI", layout="centered")
|
| 6 |
|
| 7 |
# LOAD MODEL
|
|
|
|
| 8 |
def load_model():
|
| 9 |
-
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-
|
| 10 |
-
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-
|
| 11 |
return tokenizer, model
|
| 12 |
|
| 13 |
tokenizer, model = load_model()
|
|
@@ -147,31 +148,41 @@ if st.button(" Submit Profile"):
|
|
| 147 |
equipment_list = ", ".join(equipment)
|
| 148 |
|
| 149 |
prompt = f"""
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
Start directly with:
|
| 162 |
-
|
| 163 |
Day 1:
|
| 164 |
"""
|
| 165 |
|
|
|
|
| 166 |
with st.spinner("Generating your AI workout plan..."):
|
| 167 |
|
| 168 |
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
| 169 |
|
| 170 |
outputs = model.generate(
|
| 171 |
**inputs,
|
| 172 |
-
max_new_tokens=
|
| 173 |
-
|
| 174 |
-
|
|
|
|
| 175 |
)
|
| 176 |
|
| 177 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
|
|
|
|
| 5 |
st.set_page_config(page_title="FitPlan AI", layout="centered")
|
| 6 |
|
| 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()
|
|
|
|
| 148 |
equipment_list = ", ".join(equipment)
|
| 149 |
|
| 150 |
prompt = f"""
|
| 151 |
+
Instruction:
|
| 152 |
+
Generate a structured 5-day workout plan.
|
| 153 |
+
|
| 154 |
+
User:
|
| 155 |
+
Gender: {gender}
|
| 156 |
+
BMI: {bmi:.2f} ({bmi_status})
|
| 157 |
+
Goal: {goal}
|
| 158 |
+
Level: {fitness_level}
|
| 159 |
+
Equipment: {equipment_list}
|
| 160 |
+
|
| 161 |
+
Rules:
|
| 162 |
+
- Only 5 days.
|
| 163 |
+
- Each day must include:
|
| 164 |
+
Focus
|
| 165 |
+
4 Exercises
|
| 166 |
+
Sets x Reps
|
| 167 |
+
Rest
|
| 168 |
+
- No repetition.
|
| 169 |
+
- No extra explanation.
|
| 170 |
|
| 171 |
Start directly with:
|
|
|
|
| 172 |
Day 1:
|
| 173 |
"""
|
| 174 |
|
| 175 |
+
|
| 176 |
with st.spinner("Generating your AI workout plan..."):
|
| 177 |
|
| 178 |
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
| 179 |
|
| 180 |
outputs = model.generate(
|
| 181 |
**inputs,
|
| 182 |
+
max_new_tokens=400,
|
| 183 |
+
num_beams=4,
|
| 184 |
+
early_stopping=True,
|
| 185 |
+
no_repeat_ngram_size=3
|
| 186 |
)
|
| 187 |
|
| 188 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
|