Springboardmen commited on
Commit
89aa247
Β·
verified Β·
1 Parent(s): ef06325

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +19 -31
src/streamlit_app.py CHANGED
@@ -4,7 +4,7 @@ import torch
4
 
5
  st.set_page_config(page_title="FitPlan AI", layout="centered")
6
 
7
- # LOAD MODEL (FIXED FOR FLAN-T5)
8
  @st.cache_resource
9
  def load_model():
10
  tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
@@ -13,15 +13,11 @@ def load_model():
13
 
14
  tokenizer, model = load_model()
15
 
16
- # ---------------------------------------------------
17
  # TITLE
18
- # ---------------------------------------------------
19
- st.title("πŸ’ͺ FitPlan AI – User Fitness Profile")
20
 
21
- # ---------------------------------------------------
22
  # PERSONAL INFORMATION
23
- # ---------------------------------------------------
24
- st.subheader("πŸ‘€ Personal Information")
25
 
26
  name = st.text_input("Enter Your Name")
27
 
@@ -54,9 +50,7 @@ with col2:
54
  step=0.1
55
  )
56
 
57
- # ---------------------------------------------------
58
- # BMI FUNCTION
59
- # ---------------------------------------------------
60
  def bmi_category(bmi):
61
  if bmi < 18.5:
62
  return "Underweight"
@@ -67,9 +61,7 @@ def bmi_category(bmi):
67
  else:
68
  return "Obese"
69
 
70
- # ---------------------------------------------------
71
  # BMI CALCULATION
72
- # ---------------------------------------------------
73
  bmi = None
74
 
75
  if height > 0 and weight > 0:
@@ -79,9 +71,7 @@ if height > 0 and weight > 0:
79
  st.metric("πŸ“Š Your BMI", f"{bmi:.2f}")
80
  st.info(f"BMI Category: {bmi_category(bmi)}")
81
 
82
- # ---------------------------------------------------
83
  # FITNESS GOAL
84
- # ---------------------------------------------------
85
  st.subheader("🎯 Fitness Goal")
86
 
87
  goal = st.selectbox(
@@ -95,10 +85,9 @@ goal = st.selectbox(
95
  ]
96
  )
97
 
98
- # ---------------------------------------------------
99
  # EQUIPMENT
100
- # ---------------------------------------------------
101
- st.subheader("πŸ‹οΈ Available Equipment")
102
 
103
  equipment_map = {}
104
 
@@ -130,9 +119,8 @@ with col3:
130
 
131
  equipment = [item for item, selected in equipment_map.items() if selected]
132
 
133
- # ---------------------------------------------------
134
  # FITNESS LEVEL
135
- # ---------------------------------------------------
136
  st.subheader("πŸ“ˆ Fitness Level")
137
 
138
  fitness_level = st.radio(
@@ -141,10 +129,8 @@ fitness_level = st.radio(
141
  horizontal=True
142
  )
143
 
144
- # ---------------------------------------------------
145
  # SUBMIT BUTTON
146
- # ---------------------------------------------------
147
- if st.button("πŸš€ Submit Profile"):
148
 
149
  if not name:
150
  st.error("Please enter your name.")
@@ -156,12 +142,11 @@ if st.button("πŸš€ Submit Profile"):
156
  st.error("Please select at least one equipment option.")
157
 
158
  else:
159
- st.success("βœ… Profile Submitted Successfully!")
160
 
161
  bmi_status = bmi_category(bmi)
162
  equipment_list = ", ".join(equipment)
163
 
164
- # Improved Prompt
165
  prompt = f"""
166
  You are a certified professional fitness trainer.
167
 
@@ -180,14 +165,17 @@ Day 1:
180
  """
181
 
182
  with st.spinner("Generating your AI workout plan..."):
 
183
  inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
184
 
185
- outputs = model.generate(
186
- **inputs,
187
- max_new_tokens=400,
188
- temperature=0.7,
189
- do_sample=True
190
- )
191
 
192
- result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
193
 
 
 
 
4
 
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-base")
 
13
 
14
  tokenizer, model = load_model()
15
 
 
16
  # TITLE
17
+ st.title(" FitPlan AI – User Fitness Profile")
 
18
 
 
19
  # PERSONAL INFORMATION
20
+ st.subheader(" Personal Information")
 
21
 
22
  name = st.text_input("Enter Your Name")
23
 
 
50
  step=0.1
51
  )
52
 
53
+ #BMI Function
 
 
54
  def bmi_category(bmi):
55
  if bmi < 18.5:
56
  return "Underweight"
 
61
  else:
62
  return "Obese"
63
 
 
64
  # BMI CALCULATION
 
65
  bmi = None
66
 
67
  if height > 0 and weight > 0:
 
71
  st.metric("πŸ“Š Your BMI", f"{bmi:.2f}")
72
  st.info(f"BMI Category: {bmi_category(bmi)}")
73
 
 
74
  # FITNESS GOAL
 
75
  st.subheader("🎯 Fitness Goal")
76
 
77
  goal = st.selectbox(
 
85
  ]
86
  )
87
 
 
88
  # EQUIPMENT
89
+
90
+ st.subheader(" Available Equipment")
91
 
92
  equipment_map = {}
93
 
 
119
 
120
  equipment = [item for item, selected in equipment_map.items() if selected]
121
 
122
+
123
  # FITNESS LEVEL
 
124
  st.subheader("πŸ“ˆ Fitness Level")
125
 
126
  fitness_level = st.radio(
 
129
  horizontal=True
130
  )
131
 
 
132
  # SUBMIT BUTTON
133
+ if st.button(" Submit Profile"):
 
134
 
135
  if not name:
136
  st.error("Please enter your name.")
 
142
  st.error("Please select at least one equipment option.")
143
 
144
  else:
145
+ st.success(" Profile Submitted Successfully!")
146
 
147
  bmi_status = bmi_category(bmi)
148
  equipment_list = ", ".join(equipment)
149
 
 
150
  prompt = f"""
151
  You are a certified professional fitness trainer.
152
 
 
165
  """
166
 
167
  with st.spinner("Generating your AI workout plan..."):
168
+
169
  inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
170
 
171
+ outputs = model.generate(
172
+ **inputs,
173
+ max_new_tokens=300,
174
+ temperature=0.7,
175
+ do_sample=True
176
+ )
177
 
178
+ result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
179
 
180
+ st.subheader(" Your Personalized Workout Plan")
181
+ st.write(result)