srbhavya01 commited on
Commit
7da4ce0
·
verified ·
1 Parent(s): 66f098b

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +111 -71
src/streamlit_app.py CHANGED
@@ -1,77 +1,89 @@
1
  import streamlit as st
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
- import torch
4
-
5
- # -------------------------
6
- # Page Config FIRST
7
- # -------------------------
8
-
9
- st.set_page_config(page_title="FitPlan AI", page_icon="💪")
10
-
11
- # 🎨 Background Style
12
- st.markdown(
13
- """
14
- <style>
15
- .stApp {
16
- background: linear-gradient(to right, #ff512f, #dd2476);
17
- }
18
- </style>
19
- """,
20
- unsafe_allow_html=True
21
- )
22
-
23
- # -------------------------
24
- # Load Model (Small for HF)
25
- # -------------------------
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  @st.cache_resource
28
  def load_model():
29
- tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-small")
30
- model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small")
31
  return tokenizer, model
32
 
33
  tokenizer, model = load_model()
34
 
35
- # -------------------------
36
- # App Title
37
- # -------------------------
38
-
39
- st.title("💪 FitPlan AI - BMI Calculator & Workout Planner")
40
- st.write("Enter your details to get AI workout plan.")
41
-
42
- # -------------------------
43
- # Personal Info
44
- # -------------------------
45
-
46
  name = st.text_input("Enter Your Name *")
47
  gender = st.selectbox("Gender", ["Male", "Female", "Other"])
48
  height_cm = st.number_input("Height (cm)", min_value=0.0)
49
  weight_kg = st.number_input("Weight (kg)", min_value=0.0)
50
 
51
- # -------------------------
52
- # Fitness Details
53
- # -------------------------
54
 
55
  goal = st.selectbox(
56
  "Fitness Goal",
57
- ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
58
  )
59
 
60
  equipment = st.multiselect(
61
  "Available Equipment",
62
  ["Dumbbells", "Resistance Band", "Yoga Mat", "Skipping Rope",
63
- "Weight Plates", "Cycling", "Inclined Bench", "Pullups Bar", "No Equipment"]
64
- )
65
-
66
- fitness_level = st.radio(
67
- "Fitness Level",
68
- ["Beginner", "Intermediate", "Advanced"]
69
  )
70
 
71
- # -------------------------
72
- # BMI Functions
73
- # -------------------------
74
 
 
 
 
75
  def calculate_bmi(weight, height):
76
  height_m = height / 100
77
  return round(weight / (height_m ** 2), 2)
@@ -86,11 +98,10 @@ def bmi_category(bmi):
86
  else:
87
  return "Obese"
88
 
89
- # -------------------------
90
- # Generate Plan
91
- # -------------------------
92
-
93
- if st.button("Generate Workout Plan"):
94
 
95
  if not name:
96
  st.error("Enter your name")
@@ -99,35 +110,64 @@ if st.button("Generate Workout Plan"):
99
  elif not equipment:
100
  st.error("Select equipment")
101
  else:
 
 
102
  bmi = calculate_bmi(weight_kg, height_cm)
103
  bmi_status = bmi_category(bmi)
104
 
105
- st.success(f"BMI: {bmi} ({bmi_status})")
106
 
107
  equipment_list = ", ".join(equipment)
108
 
 
 
 
109
  prompt = f"""
110
- Create a 5-day workout plan.
111
-
112
- Name: {name}
113
- Gender: {gender}
114
- BMI: {bmi} ({bmi_status})
115
- Goal: {goal}
116
- Level: {fitness_level}
117
- Equipment: {equipment_list}
118
-
119
- Include warmup, exercises, sets, reps, rest time.
120
- """
121
-
122
- with st.spinner("Generating workout plan..."):
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
124
  outputs = model.generate(
125
  **inputs,
126
- max_new_tokens=400,
127
  temperature=0.7,
128
  do_sample=True
129
  )
130
  result = tokenizer.decode(outputs[0], skip_special_tokens=True)
131
 
132
- st.subheader("🏋️ Your Workout Plan")
133
- st.write(result)
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
+ # -----------------------------
5
+ # PAGE CONFIG
6
+ # -----------------------------
7
+ st.set_page_config(page_title="FitPlan AI", page_icon="💪", layout="centered")
8
+
9
+ # -----------------------------
10
+ # BACKGROUND + STYLES
11
+ # -----------------------------
12
+ st.markdown("""
13
+ <style>
14
+ .stApp {
15
+ background: linear-gradient(to right, #ff512f, #dd2476);
16
+ }
17
+
18
+ /* Title */
19
+ .main-title {
20
+ font-size: 40px;
21
+ font-weight: bold;
22
+ text-align: center;
23
+ color: white;
24
+ }
25
+
26
+ /* Workout Output Box */
27
+ .workout-box {
28
+ background-color: #111;
29
+ padding: 25px;
30
+ border-radius: 15px;
31
+ border: 1px solid #444;
32
+ color: white;
33
+ font-size: 18px;
34
+ line-height: 1.7;
35
+ }
36
+
37
+ /* Section Title */
38
+ .title-box {
39
+ font-size: 28px;
40
+ font-weight: bold;
41
+ color: #ff7b00;
42
+ margin-top: 20px;
43
+ }
44
+ </style>
45
+ """, unsafe_allow_html=True)
46
+
47
+ st.markdown('<div class="main-title">💪 FitPlan AI</div>', unsafe_allow_html=True)
48
+ st.write("### Fitness Profile & BMI Calculator")
49
+
50
+ # -----------------------------
51
+ # LOAD MODEL (HUGGING FACE)
52
+ # -----------------------------
53
  @st.cache_resource
54
  def load_model():
55
+ tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-large")
56
+ model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large")
57
  return tokenizer, model
58
 
59
  tokenizer, model = load_model()
60
 
61
+ # -----------------------------
62
+ # USER INPUT
63
+ # -----------------------------
 
 
 
 
 
 
 
 
64
  name = st.text_input("Enter Your Name *")
65
  gender = st.selectbox("Gender", ["Male", "Female", "Other"])
66
  height_cm = st.number_input("Height (cm)", min_value=0.0)
67
  weight_kg = st.number_input("Weight (kg)", min_value=0.0)
68
 
69
+ st.subheader("Fitness Details")
 
 
70
 
71
  goal = st.selectbox(
72
  "Fitness Goal",
73
+ ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexibility"]
74
  )
75
 
76
  equipment = st.multiselect(
77
  "Available Equipment",
78
  ["Dumbbells", "Resistance Band", "Yoga Mat", "Skipping Rope",
79
+ "Weight Plates", "Cycling", "Inclined Bench", "Pull-up Bar", "No Equipment"]
 
 
 
 
 
80
  )
81
 
82
+ fitness_level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
 
 
83
 
84
+ # -----------------------------
85
+ # BMI FUNCTIONS
86
+ # -----------------------------
87
  def calculate_bmi(weight, height):
88
  height_m = height / 100
89
  return round(weight / (height_m ** 2), 2)
 
98
  else:
99
  return "Obese"
100
 
101
+ # -----------------------------
102
+ # SUBMIT BUTTON
103
+ # -----------------------------
104
+ if st.button("Generate Fitness Plan 💥"):
 
105
 
106
  if not name:
107
  st.error("Enter your name")
 
110
  elif not equipment:
111
  st.error("Select equipment")
112
  else:
113
+ st.success("Profile Submitted Successfully!")
114
+
115
  bmi = calculate_bmi(weight_kg, height_cm)
116
  bmi_status = bmi_category(bmi)
117
 
118
+ st.write(f"### 📊 BMI: {bmi} ({bmi_status})")
119
 
120
  equipment_list = ", ".join(equipment)
121
 
122
+ # -----------------------------
123
+ # PROMPT FOR AI
124
+ # -----------------------------
125
  prompt = f"""
126
+ Create a STRICT 5-day structured workout plan.
127
+
128
+ Format EXACTLY like:
129
+
130
+ Day 1:
131
+ Warm-up:
132
+ Exercises:
133
+ Sets & Reps:
134
+ Rest:
135
+
136
+ Day 2:
137
+ ...
138
+
139
+ User Details:
140
+ Name: {name}
141
+ Gender: {gender}
142
+ BMI: {bmi} ({bmi_status})
143
+ Goal: {goal}
144
+ Fitness Level: {fitness_level}
145
+ Equipment: {equipment_list}
146
+ """
147
+
148
+ # -----------------------------
149
+ # GENERATE PLAN
150
+ # -----------------------------
151
+ with st.spinner("Generating your AI workout plan..."):
152
  inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
153
  outputs = model.generate(
154
  **inputs,
155
+ max_new_tokens=600,
156
  temperature=0.7,
157
  do_sample=True
158
  )
159
  result = tokenizer.decode(outputs[0], skip_special_tokens=True)
160
 
161
+ # -----------------------------
162
+ # DISPLAY OUTPUT (Styled)
163
+ # -----------------------------
164
+ st.markdown(
165
+ '<div class="title-box">🏋️ Your Personalized Workout Plan</div>',
166
+ unsafe_allow_html=True
167
+ )
168
+
169
+ st.markdown(f"""
170
+ <div class="workout-box">
171
+ {result.replace("Day", "<br><br><b>Day").replace("\n", "<br>")}
172
+ </div>
173
+ """, unsafe_allow_html=True)