Springboardmen commited on
Commit
167ab39
Β·
verified Β·
1 Parent(s): 6c1c18c

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +49 -30
src/streamlit_app.py CHANGED
@@ -6,6 +6,7 @@ from transformers import pipeline
6
  # ---------------------------------------------------
7
  st.set_page_config(page_title="FitPlan AI", layout="centered")
8
 
 
9
  @st.cache_resource
10
  def load_model():
11
  return pipeline(
@@ -15,7 +16,10 @@ def load_model():
15
 
16
  generator = load_model()
17
 
18
- st.title(" FitPlan AI – User Fitness Profile")
 
 
 
19
 
20
  # ---------------------------------------------------
21
  # PERSONAL INFORMATION
@@ -24,50 +28,62 @@ st.subheader("πŸ‘€ Personal Information")
24
 
25
  name = st.text_input("Enter Your Name")
26
 
27
- st.subheader("Gender")
28
-
29
  gender = st.radio(
30
- "",
31
  ["Male", "Female"],
32
- horizontal=True,index=0
33
  )
34
 
35
-
 
 
36
  col1, col2 = st.columns(2)
37
 
38
  with col1:
39
- height = st.number_input("Height (in cm)", min_value=100, max_value=250)
 
 
 
 
 
 
40
 
41
  with col2:
42
- weight = st.number_input("Weight (in kg)", min_value=30, max_value=200)
43
-
44
- # ---------------------------------------------------
45
- # BMI CALCULATION
46
- # ---------------------------------------------------
47
- bmi = None
 
48
 
49
- if height > 0 and weight > 0:
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
66
  # ---------------------------------------------------
67
  st.subheader("🎯 Fitness Goal")
68
 
69
  goal = st.selectbox(
70
- "",
71
  [
72
  "Flexible",
73
  "Weight Loss",
@@ -77,6 +93,9 @@ goal = st.selectbox(
77
  ]
78
  )
79
 
 
 
 
80
  st.subheader("πŸ‹οΈ Available Equipment")
81
 
82
  equipment_map = {}
@@ -107,33 +126,33 @@ with col3:
107
  equipment_map["Exercise Bike"] = st.checkbox("Exercise Bike")
108
  equipment_map["Skipping Rope"] = st.checkbox("Skipping Rope")
109
 
110
- # Convert selected to list
111
  equipment = [item for item, selected in equipment_map.items() if selected]
112
 
113
-
114
  # ---------------------------------------------------
115
  # FITNESS LEVEL
116
  # ---------------------------------------------------
117
  st.subheader("πŸ“ˆ Fitness Level")
118
 
119
  fitness_level = st.radio(
120
- "",
121
  ["Beginner", "Intermediate", "Advanced"],
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
 
@@ -163,4 +182,4 @@ if st.button("Submit Profile"):
163
  result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
164
 
165
  st.subheader("πŸ‹οΈ Your Personalized Workout Plan")
166
- st.write(result)
 
6
  # ---------------------------------------------------
7
  st.set_page_config(page_title="FitPlan AI", layout="centered")
8
 
9
+
10
  @st.cache_resource
11
  def load_model():
12
  return pipeline(
 
16
 
17
  generator = load_model()
18
 
19
+ # ---------------------------------------------------
20
+ # TITLE
21
+ # ---------------------------------------------------
22
+ st.title("πŸ’ͺ FitPlan AI – User Fitness Profile")
23
 
24
  # ---------------------------------------------------
25
  # PERSONAL INFORMATION
 
28
 
29
  name = st.text_input("Enter Your Name")
30
 
 
 
31
  gender = st.radio(
32
+ "Gender",
33
  ["Male", "Female"],
34
+ horizontal=True
35
  )
36
 
37
+ # ---------------------------------------------------
38
+ # HEIGHT & WEIGHT
39
+ # ---------------------------------------------------
40
  col1, col2 = st.columns(2)
41
 
42
  with col1:
43
+ height = st.number_input(
44
+ "Height (in cm)",
45
+ min_value=0.0,
46
+ max_value=250.0,
47
+ value=0.0,
48
+ step=0.1
49
+ )
50
 
51
  with col2:
52
+ weight = st.number_input(
53
+ "Weight (in kg)",
54
+ min_value=0.0,
55
+ max_value=200.0,
56
+ value=0.0,
57
+ step=0.1
58
+ )
59
 
 
 
 
 
 
60
  def bmi_category(bmi):
61
  if bmi < 18.5:
62
  return "Underweight"
63
+ elif bmi < 25:
64
  return "Normal weight"
65
+ elif bmi < 30:
66
  return "Overweight"
67
  else:
68
  return "Obese"
69
 
70
+
71
+ bmi = None
72
+
73
+ if height > 0 and weight > 0:
74
+ height_m = height / 100
75
+ bmi = weight / (height_m ** 2)
76
+
77
+ st.metric("πŸ“Š Your BMI", f"{bmi:.2f}")
78
+ st.info(f"BMI Category: {bmi_category(bmi)}")
79
+
80
  # ---------------------------------------------------
81
  # FITNESS GOAL
82
  # ---------------------------------------------------
83
  st.subheader("🎯 Fitness Goal")
84
 
85
  goal = st.selectbox(
86
+ "Select Your Goal",
87
  [
88
  "Flexible",
89
  "Weight Loss",
 
93
  ]
94
  )
95
 
96
+ # ---------------------------------------------------
97
+ # EQUIPMENT
98
+ # ---------------------------------------------------
99
  st.subheader("πŸ‹οΈ Available Equipment")
100
 
101
  equipment_map = {}
 
126
  equipment_map["Exercise Bike"] = st.checkbox("Exercise Bike")
127
  equipment_map["Skipping Rope"] = st.checkbox("Skipping Rope")
128
 
 
129
  equipment = [item for item, selected in equipment_map.items() if selected]
130
 
 
131
  # ---------------------------------------------------
132
  # FITNESS LEVEL
133
  # ---------------------------------------------------
134
  st.subheader("πŸ“ˆ Fitness Level")
135
 
136
  fitness_level = st.radio(
137
+ "Select Fitness Level",
138
  ["Beginner", "Intermediate", "Advanced"],
139
  horizontal=True
140
  )
141
 
142
+ # ---------------------------------------------------
143
+ # SUBMIT BUTTON
144
+ # ---------------------------------------------------
145
+ if st.button("πŸš€ Submit Profile"):
146
 
147
  if not name:
148
  st.error("Please enter your name.")
149
 
150
+ elif height <= 0 or weight <= 0:
151
+ st.error("Please enter valid height and weight.")
152
+
153
  elif not equipment:
154
  st.error("Please select at least one equipment option.")
155
 
 
 
 
156
  else:
157
  st.success("βœ… Profile Submitted Successfully!")
158
 
 
182
  result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
183
 
184
  st.subheader("πŸ‹οΈ Your Personalized Workout Plan")
185
+ st.write(result)