Springboardmen commited on
Commit
8dedb65
Β·
verified Β·
1 Parent(s): 6178398

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +53 -11
src/streamlit_app.py CHANGED
@@ -1,10 +1,20 @@
1
  import streamlit as st
 
2
 
3
  # ---------------------------------------------------
4
  # PAGE CONFIG
5
  # ---------------------------------------------------
6
  st.set_page_config(page_title="FitPlan AI", layout="centered")
7
 
 
 
 
 
 
 
 
 
 
8
  st.title(" FitPlan AI – User Fitness Profile")
9
 
10
  # ---------------------------------------------------
@@ -40,6 +50,16 @@ if height > 0 and weight > 0:
40
  height_m = height / 100
41
  bmi = weight / (height_m ** 2)
42
  st.write(f"### πŸ“Š Your BMI: {bmi:.2f}")
 
 
 
 
 
 
 
 
 
 
43
 
44
  # ---------------------------------------------------
45
  # FITNESS GOAL
@@ -102,23 +122,45 @@ fitness_level = st.radio(
102
  horizontal=True
103
  )
104
 
105
- # ---------------------------------------------------
106
- # SUBMIT BUTTON
107
- # ---------------------------------------------------
108
  if st.button("Submit Profile"):
109
 
110
  if not name:
111
  st.error("Please enter your name.")
 
112
  elif not equipment:
113
  st.error("Please select at least one equipment option.")
 
 
 
 
114
  else:
115
  st.success("βœ… Profile Submitted Successfully!")
116
 
117
- st.json({
118
- "Name": name,
119
- "Gender": gender,
120
- "BMI": round(bmi, 2) if bmi else None,
121
- "Goal": goal,
122
- "Fitness Level": fitness_level,
123
- "Equipment": equipment
124
- })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.cache_resource
10
+ def load_model():
11
+ return pipeline(
12
+ "text-generation",
13
+ model="google/flan-t5-base"
14
+ )
15
+
16
+ generator = load_model()
17
+
18
  st.title(" FitPlan AI – User Fitness Profile")
19
 
20
  # ---------------------------------------------------
 
50
  height_m = height / 100
51
  bmi = weight / (height_m ** 2)
52
  st.write(f"### πŸ“Š Your BMI: {bmi:.2f}")
53
+
54
+ def bmi_category(bmi):
55
+ if bmi < 18.5:
56
+ return "Underweight"
57
+ elif 18.5 <= bmi < 25:
58
+ return "Normal weight"
59
+ elif 25 <= bmi < 30:
60
+ return "Overweight"
61
+ else:
62
+ return "Obese"
63
 
64
  # ---------------------------------------------------
65
  # FITNESS GOAL
 
122
  horizontal=True
123
  )
124
 
125
+
 
 
126
  if st.button("Submit Profile"):
127
 
128
  if not name:
129
  st.error("Please enter your name.")
130
+
131
  elif not equipment:
132
  st.error("Please select at least one equipment option.")
133
+
134
+ elif bmi is None:
135
+ st.error("Please enter valid height and weight.")
136
+
137
  else:
138
  st.success("βœ… Profile Submitted Successfully!")
139
 
140
+ bmi_status = bmi_category(bmi)
141
+ equipment_list = ", ".join(equipment)
142
+
143
+ prompt = f"""
144
+ Generate a 5-day structured workout plan.
145
+
146
+ User Details:
147
+ Name: {name}
148
+ Gender: {gender}
149
+ BMI: {bmi:.2f} ({bmi_status})
150
+ Goal: {goal}
151
+ Fitness Level: {fitness_level}
152
+ Available Equipment: {equipment_list}
153
+
154
+ Requirements:
155
+ - Include warmup
156
+ - Include exercises with sets and reps
157
+ - Include rest time
158
+ - Adjust intensity based on BMI and fitness level
159
+ - Keep it structured day-wise
160
+ """
161
+
162
+ with st.spinner("Generating your AI workout plan..."):
163
+ result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
164
+
165
+ st.subheader("πŸ‹οΈ Your Personalized Workout Plan")
166
+ st.write(result)