Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +32 -35
src/streamlit_app.py
CHANGED
|
@@ -6,9 +6,6 @@ import torch
|
|
| 6 |
# -------------------------
|
| 7 |
|
| 8 |
def create_workout_prompt(days, level, goal, equipment):
|
| 9 |
-
"""
|
| 10 |
-
Creates a detailed prompt for the AI model
|
| 11 |
-
"""
|
| 12 |
|
| 13 |
prompt = f"""
|
| 14 |
Generate a {days}-day workout plan.
|
|
@@ -29,56 +26,56 @@ def create_workout_prompt(days, level, goal, equipment):
|
|
| 29 |
|
| 30 |
|
| 31 |
# -------------------------
|
| 32 |
-
# 2. Load Model
|
| 33 |
# -------------------------
|
| 34 |
|
|
|
|
| 35 |
def load_model():
|
| 36 |
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-small")
|
| 37 |
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small")
|
| 38 |
return tokenizer, model
|
| 39 |
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# -------------------------
|
| 42 |
-
#
|
| 43 |
# -------------------------
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
| 48 |
-
|
| 49 |
-
outputs = model.generate(
|
| 50 |
-
**inputs,
|
| 51 |
-
max_new_tokens=300,
|
| 52 |
-
temperature=0.7,
|
| 53 |
-
do_sample=True
|
| 54 |
-
)
|
| 55 |
-
|
| 56 |
-
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 57 |
-
|
| 58 |
-
return result
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
# -------------------------
|
| 62 |
-
#
|
| 63 |
# -------------------------
|
| 64 |
|
| 65 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
days=5,
|
| 70 |
-
level="Beginner",
|
| 71 |
-
goal="Build Muscle",
|
| 72 |
-
equipment="Dumbbells"
|
| 73 |
-
)
|
| 74 |
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
|
| 78 |
-
tokenizer, model = load_model()
|
| 79 |
|
| 80 |
-
|
| 81 |
-
workout_plan = generate_workout_plan(prompt, tokenizer, model)
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
|
|
|
| 6 |
# -------------------------
|
| 7 |
|
| 8 |
def create_workout_prompt(days, level, goal, equipment):
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
prompt = f"""
|
| 11 |
Generate a {days}-day workout plan.
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
# -------------------------
|
| 29 |
+
# 2. Load Model (Cached)
|
| 30 |
# -------------------------
|
| 31 |
|
| 32 |
+
@st.cache_resource
|
| 33 |
def load_model():
|
| 34 |
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-small")
|
| 35 |
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small")
|
| 36 |
return tokenizer, model
|
| 37 |
|
| 38 |
+
tokenizer, model = load_model()
|
| 39 |
+
|
| 40 |
|
| 41 |
# -------------------------
|
| 42 |
+
# Streamlit UI
|
| 43 |
# -------------------------
|
| 44 |
|
| 45 |
+
st.title("💪 FitPlan AI — Workout Generator")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
days = st.selectbox("Number of Days", [3, 4, 5, 6])
|
| 48 |
+
level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
|
| 49 |
+
goal = st.selectbox("Goal", ["Build Muscle", "Weight Loss", "Strength Gain"])
|
| 50 |
+
equipment = st.text_input("Equipment (e.g., Dumbbells)")
|
| 51 |
|
| 52 |
# -------------------------
|
| 53 |
+
# Generate Button
|
| 54 |
# -------------------------
|
| 55 |
|
| 56 |
+
if st.button("Generate Workout Plan"):
|
| 57 |
+
|
| 58 |
+
if not equipment:
|
| 59 |
+
st.error("Please enter equipment")
|
| 60 |
+
else:
|
| 61 |
+
prompt = create_workout_prompt(days, level, goal, equipment)
|
| 62 |
+
|
| 63 |
+
st.write("### Generated Prompt")
|
| 64 |
+
st.code(prompt)
|
| 65 |
|
| 66 |
+
with st.spinner("Generating plan..."):
|
| 67 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
+
outputs = model.generate(
|
| 70 |
+
**inputs,
|
| 71 |
+
max_new_tokens=300,
|
| 72 |
+
temperature=0.7,
|
| 73 |
+
do_sample=True
|
| 74 |
+
)
|
| 75 |
|
| 76 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
| 77 |
|
| 78 |
+
st.success("Workout Plan Generated ✅")
|
|
|
|
| 79 |
|
| 80 |
+
st.subheader("🏋️ Your Workout Plan")
|
| 81 |
+
st.write(result)
|