Spaces:
Sleeping
Sleeping
File size: 3,946 Bytes
1f6d7ba 7f56c8a 1f6d7ba 7f56c8a 8d6f3e2 1f6d7ba 7f56c8a c704836 7f56c8a 8d6f3e2 7f56c8a 8d6f3e2 7f56c8a 8d6f3e2 7f56c8a c704836 8d6f3e2 7f56c8a 8d6f3e2 7f56c8a 8d6f3e2 7f56c8a 8d6f3e2 7f56c8a 8d6f3e2 7f56c8a 8d6f3e2 7f56c8a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | import streamlit as st
from transformers import pipeline
# ---------------------------------------------------
# PAGE CONFIG
# ---------------------------------------------------
st.set_page_config(page_title="FitPlan AI", layout="centered")
st.title("🏋️ FitPlan AI – Personalized Fitness Plan")
# ---------------------------------------------------
# LOAD MODEL (Cached)
# ---------------------------------------------------
@st.cache_resource
def load_model():
return pipeline(
"text-generation",
model="google/flan-t5-base"
)
generator = load_model()
# ---------------------------------------------------
# USER NAME
# ---------------------------------------------------
name = st.text_input("Enter Your Name")
# ---------------------------------------------------
# GOALS
# ---------------------------------------------------
goal = st.selectbox(
"Fitness Goal",
[
"Flexible",
"Weight Loss",
"Build Muscle",
"Strength Gaining",
"Abs Building"
]
)
# ---------------------------------------------------
# EQUIPMENT
# ---------------------------------------------------
st.subheader("Available Equipment")
col1, col2 = st.columns(2)
with col1:
dumbbells = st.checkbox("Dumbbells")
resistance_band = st.checkbox("Resistance Band")
yoga_mat = st.checkbox("Yoga Mat")
no_equipment = st.checkbox("No Equipment")
inclined_bench = st.checkbox("Inclined Bench")
treadmill = st.checkbox("Treadmill")
cycle = st.checkbox("Cycle")
with col2:
skipping_rope = st.checkbox("Skipping Rope")
hand_gripper = st.checkbox("Hand Gripper")
pullups_bar = st.checkbox("Pullups Bar")
weight_plates = st.checkbox("Weight Plates")
hula_hoop = st.checkbox("Hula Hoop Ring")
bosu_ball = st.checkbox("Bosu Ball")
equipment = []
equipment_map = {
"Dumbbells": dumbbells,
"Resistance Band": resistance_band,
"Yoga Mat": yoga_mat,
"No Equipment": no_equipment,
"Inclined Bench": inclined_bench,
"Treadmill": treadmill,
"Cycle": cycle,
"Skipping Rope": skipping_rope,
"Hand Gripper": hand_gripper,
"Pullups Bar": pullups_bar,
"Weight Plates": weight_plates,
"Hula Hoop Ring": hula_hoop,
"Bosu Ball": bosu_ball,
}
for item, selected in equipment_map.items():
if selected:
equipment.append(item)
# ---------------------------------------------------
# FITNESS LEVEL
# ---------------------------------------------------
st.subheader("Fitness Level")
fitness_level = st.radio(
"",
["Beginner", "Intermediate", "Advanced"],
horizontal=True
)
# ---------------------------------------------------
# PROMPT BUILDER
# ---------------------------------------------------
def build_prompt(name, goal, fitness_level, equipment):
equipment_text = ", ".join(equipment)
prompt = f"""
Generate a detailed 5-day workout plan for {name}.
Goal: {goal}
Fitness Level: {fitness_level}
Available Equipment: {equipment_text}
Include:
- Day-wise workout split
- Exercises
- Sets and reps
- Rest time
- Warm-up and cool-down
"""
return prompt
# ---------------------------------------------------
# SUBMIT BUTTON
# ---------------------------------------------------
if st.button("Generate Personalised Plan"):
if not name:
st.error("Please enter your name.")
elif not equipment:
st.error("Please select at least one equipment option.")
else:
with st.spinner("Generating your AI workout plan..."):
prompt = build_prompt(name, goal, fitness_level, equipment)
result = generator(
prompt,
max_length=500,
do_sample=True,
temperature=0.7
)
plan = result[0]["generated_text"]
st.success(f"Plan Generated Successfully, {name}! 💪")
st.write(plan)
|