js02vel commited on
Commit
0491fbe
·
verified ·
1 Parent(s): 38805d3

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +49 -32
src/streamlit_app.py CHANGED
@@ -1,8 +1,14 @@
1
  import streamlit as st
2
-
3
  # 1. Basic Configuration
4
  st.set_page_config(page_title="FitPlan AI", page_icon="💪", layout="centered")
5
-
 
 
 
 
 
 
6
  # 2. Enhanced CSS
7
  st.markdown("""
8
  <style>
@@ -110,34 +116,45 @@ with st.form("fitness_form", clear_on_submit=False):
110
  # Submission Button
111
  submit = st.form_submit_button("GENERATE MY PLAN")
112
 
113
- # --------------------------------------------------
114
- # Logic & Calculation
115
- # --------------------------------------------------
116
- if submit:
117
- if not name.strip() or height <= 50 or weight <= 10:
118
- st.error("🚨 Please provide a valid name, height, and weight.")
 
 
 
 
 
119
  else:
120
- # BMI Calculation
121
- height_m = height / 100
122
- bmi = round(weight / (height_m ** 2), 2)
123
-
124
- if bmi < 18.5:
125
- cat, color = "Underweight", "blue"
126
- elif 18.5 <= bmi < 25:
127
- cat, color = "Normal", "green"
128
- elif 25 <= bmi < 30:
129
- cat, color = "Overweight", "orange"
130
- else:
131
- cat, color = "Obese", "red"
132
-
133
- # Results Display
134
- st.balloons()
135
- st.success(f"✅ Profile created for {name}")
136
-
137
- c1, c2 = st.columns(2)
138
- with c1:
139
- st.metric("Calculated BMI", bmi)
140
- with c2:
141
- st.markdown(f"### Status: :{color}[{cat}]")
142
-
143
- st.info(f"*Goal:* {goal} | *Experience:* {level}")
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
  # 1. Basic Configuration
4
  st.set_page_config(page_title="FitPlan AI", page_icon="💪", layout="centered")
5
+ def load_model():
6
+ return pipeline(
7
+ "text-generation",
8
+ model="google/flan-t5-base"
9
+ )
10
+
11
+ generator = load_model()
12
  # 2. Enhanced CSS
13
  st.markdown("""
14
  <style>
 
116
  # Submission Button
117
  submit = st.form_submit_button("GENERATE MY PLAN")
118
 
119
+ if st.button("🚀 Submit Profile"):
120
+
121
+ if not name:
122
+ st.error("Please enter your name.")
123
+
124
+ elif height <= 0 or weight <= 0:
125
+ st.error("Please enter valid height and weight.")
126
+
127
+ elif not equipment:
128
+ st.error("Please select at least one equipment option.")
129
+
130
  else:
131
+ st.success("✅ Profile Submitted Successfully!")
132
+
133
+ bmi_status = bmi_category(bmi)
134
+ equipment_list = ", ".join(equipment)
135
+
136
+ prompt = f"""
137
+ Generate a 5-day structured workout plan.
138
+
139
+ User Details:
140
+ Name: {name}
141
+ Gender: {gender}
142
+ BMI: {bmi:.2f} ({bmi_status})
143
+ Goal: {goal}
144
+ Fitness Level: {fitness_level}
145
+ Available Equipment: {equipment_list}
146
+
147
+ Requirements:
148
+ - Include warmup
149
+ - Include exercises with sets and reps
150
+ - Include rest time
151
+ - Adjust intensity based on BMI and fitness level
152
+ - Keep it structured day-wise
153
+ """
154
+
155
+ with st.spinner("Generating your AI workout plan..."):
156
+ response = generator(prompt, max_new_tokens=400)
157
+ result = response[0]["generated_text"]
158
+
159
+ st.subheader("🏋️ Your Personalized Workout Plan")
160
+ st.write(result)