Springboardmen commited on
Commit
7f56c8a
·
verified ·
1 Parent(s): 42c9f73

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +72 -18
src/streamlit_app.py CHANGED
@@ -1,12 +1,33 @@
1
  import streamlit as st
 
2
 
 
 
 
3
  st.set_page_config(page_title="FitPlan AI", layout="centered")
4
 
5
- st.title(" Your Fitness Profile")
6
 
7
- # --------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  # GOALS
9
- # --------------------------
10
  goal = st.selectbox(
11
  "Fitness Goal",
12
  [
@@ -18,9 +39,9 @@ goal = st.selectbox(
18
  ]
19
  )
20
 
21
- # --------------------------
22
  # EQUIPMENT
23
- # --------------------------
24
  st.subheader("Available Equipment")
25
 
26
  col1, col2 = st.columns(2)
@@ -42,7 +63,6 @@ with col2:
42
  hula_hoop = st.checkbox("Hula Hoop Ring")
43
  bosu_ball = st.checkbox("Bosu Ball")
44
 
45
- # Collect equipment into list
46
  equipment = []
47
 
48
  equipment_map = {
@@ -65,9 +85,9 @@ for item, selected in equipment_map.items():
65
  if selected:
66
  equipment.append(item)
67
 
68
- # --------------------------
69
  # FITNESS LEVEL
70
- # --------------------------
71
  st.subheader("Fitness Level")
72
 
73
  fitness_level = st.radio(
@@ -76,17 +96,51 @@ fitness_level = st.radio(
76
  horizontal=True
77
  )
78
 
79
- # --------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  # SUBMIT BUTTON
81
- # --------------------------
82
  if st.button("Generate Personalised Plan"):
83
-
84
- if not equipment:
 
 
85
  st.error("Please select at least one equipment option.")
86
  else:
87
- st.success("Profile Submitted ")
88
- st.json({
89
- "goal": goal,
90
- "fitness_level": fitness_level,
91
- "equipment": equipment
92
- })
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
 
4
+ # ---------------------------------------------------
5
+ # PAGE CONFIG
6
+ # ---------------------------------------------------
7
  st.set_page_config(page_title="FitPlan AI", layout="centered")
8
 
9
+ st.title("🏋️ FitPlan AI – Personalized Fitness Plan")
10
 
11
+ # ---------------------------------------------------
12
+ # LOAD MODEL (Cached)
13
+ # ---------------------------------------------------
14
+ @st.cache_resource
15
+ def load_model():
16
+ return pipeline(
17
+ "text-generation",
18
+ model="google/flan-t5-base"
19
+ )
20
+
21
+ generator = load_model()
22
+
23
+ # ---------------------------------------------------
24
+ # USER NAME
25
+ # ---------------------------------------------------
26
+ name = st.text_input("Enter Your Name")
27
+
28
+ # ---------------------------------------------------
29
  # GOALS
30
+ # ---------------------------------------------------
31
  goal = st.selectbox(
32
  "Fitness Goal",
33
  [
 
39
  ]
40
  )
41
 
42
+ # ---------------------------------------------------
43
  # EQUIPMENT
44
+ # ---------------------------------------------------
45
  st.subheader("Available Equipment")
46
 
47
  col1, col2 = st.columns(2)
 
63
  hula_hoop = st.checkbox("Hula Hoop Ring")
64
  bosu_ball = st.checkbox("Bosu Ball")
65
 
 
66
  equipment = []
67
 
68
  equipment_map = {
 
85
  if selected:
86
  equipment.append(item)
87
 
88
+ # ---------------------------------------------------
89
  # FITNESS LEVEL
90
+ # ---------------------------------------------------
91
  st.subheader("Fitness Level")
92
 
93
  fitness_level = st.radio(
 
96
  horizontal=True
97
  )
98
 
99
+ # ---------------------------------------------------
100
+ # PROMPT BUILDER
101
+ # ---------------------------------------------------
102
+ def build_prompt(name, goal, fitness_level, equipment):
103
+ equipment_text = ", ".join(equipment)
104
+
105
+ prompt = f"""
106
+ Generate a detailed 5-day workout plan for {name}.
107
+
108
+ Goal: {goal}
109
+ Fitness Level: {fitness_level}
110
+ Available Equipment: {equipment_text}
111
+
112
+ Include:
113
+ - Day-wise workout split
114
+ - Exercises
115
+ - Sets and reps
116
+ - Rest time
117
+ - Warm-up and cool-down
118
+ """
119
+
120
+ return prompt
121
+
122
+
123
+ # ---------------------------------------------------
124
  # SUBMIT BUTTON
125
+ # ---------------------------------------------------
126
  if st.button("Generate Personalised Plan"):
127
+
128
+ if not name:
129
+ st.error("Please enter your name.")
130
+ elif not equipment:
131
  st.error("Please select at least one equipment option.")
132
  else:
133
+ with st.spinner("Generating your AI workout plan..."):
134
+ prompt = build_prompt(name, goal, fitness_level, equipment)
135
+
136
+ result = generator(
137
+ prompt,
138
+ max_length=500,
139
+ do_sample=True,
140
+ temperature=0.7
141
+ )
142
+
143
+ plan = result[0]["generated_text"]
144
+
145
+ st.success(f"Plan Generated Successfully, {name}! 💪")
146
+ st.write(plan)