Harry2406 commited on
Commit
1a7c734
·
verified ·
1 Parent(s): 42dcdc4

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +80 -19
src/streamlit_app.py CHANGED
@@ -1,15 +1,28 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
- st.set_page_config(page_title="Fitness Profile", page_icon="🏋️", layout="centered")
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  def load_model():
5
  return pipeline(
6
  "text-generation",
7
  model="google/flan-t5-base"
8
  )
9
-
10
  generator = load_model()
11
- st.title("🏋️ Personalized Fitness Profile")
12
 
 
13
  st.markdown("---")
14
 
15
  # =========================
@@ -19,8 +32,49 @@ st.header("1. Personal Information")
19
 
20
  name = st.text_input("Name *")
21
 
22
- height_cm = st.number_input("Height (in centimeters) *", min_value=0.0, format="%.2f")
23
- weight_kg = st.number_input("Weight (in kilograms) *", min_value=0.0, format="%.2f")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  # =========================
26
  # 2️⃣ Fitness Details
@@ -45,35 +99,37 @@ fitness_level = st.radio(
45
 
46
  st.markdown("---")
47
 
 
 
48
  # =========================
49
  if st.button("Submit Profile"):
50
-
51
  if not name:
52
  st.error("Please enter your name.")
53
-
 
 
 
54
  elif not equipment:
55
  st.error("Please select at least one equipment option.")
56
-
57
- elif bmi is None:
58
- st.error("Please enter valid height and weight.")
59
-
60
  else:
61
  st.success("✅ Profile Submitted Successfully!")
62
-
63
  bmi_status = bmi_category(bmi)
64
  equipment_list = ", ".join(equipment)
65
-
66
  prompt = f"""
67
  Generate a 5-day structured workout plan.
68
-
69
  User Details:
70
  Name: {name}
71
  Gender: {gender}
72
  BMI: {bmi:.2f} ({bmi_status})
73
- Goal: {goal}
74
  Fitness Level: {fitness_level}
75
  Available Equipment: {equipment_list}
76
-
77
  Requirements:
78
  - Include warmup
79
  - Include exercises with sets and reps
@@ -81,9 +137,14 @@ if st.button("Submit Profile"):
81
  - Adjust intensity based on BMI and fitness level
82
  - Keep it structured day-wise
83
  """
84
-
85
  with st.spinner("Generating your AI workout plan..."):
86
- result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
87
-
 
 
 
 
 
88
  st.subheader("🏋️ Your Personalized Workout Plan")
89
  st.write(result)
 
1
  import streamlit as st
2
  from transformers import pipeline
3
+
4
+ # =========================
5
+ # Page Configuration
6
+ # =========================
7
+ st.set_page_config(
8
+ page_title="Fitness Profile",
9
+ page_icon="🏋️",
10
+ layout="centered"
11
+ )
12
+
13
+ # =========================
14
+ # Load Model
15
+ # =========================
16
+ @st.cache_resource
17
  def load_model():
18
  return pipeline(
19
  "text-generation",
20
  model="google/flan-t5-base"
21
  )
22
+
23
  generator = load_model()
 
24
 
25
+ st.title("🏋️ Personalized Fitness Profile")
26
  st.markdown("---")
27
 
28
  # =========================
 
32
 
33
  name = st.text_input("Name *")
34
 
35
+ gender = st.selectbox(
36
+ "Gender *",
37
+ ["Male", "Female"]
38
+ )
39
+
40
+ height_cm = st.number_input(
41
+ "Height (in centimeters) *",
42
+ min_value=0.0,
43
+ format="%.2f"
44
+ )
45
+
46
+ weight_kg = st.number_input(
47
+ "Weight (in kilograms) *",
48
+ min_value=0.0,
49
+ format="%.2f"
50
+ )
51
+
52
+ # =========================
53
+ # BMI Calculation
54
+ # =========================
55
+ def calculate_bmi(height_cm, weight_kg):
56
+ if height_cm > 0 and weight_kg > 0:
57
+ height_m = height_cm / 100
58
+ return weight_kg / (height_m ** 2)
59
+ return None
60
+
61
+ def bmi_category(bmi):
62
+ if bmi < 18.5:
63
+ return "Underweight"
64
+ elif 18.5 <= bmi < 25:
65
+ return "Normal weight"
66
+ elif 25 <= bmi < 30:
67
+ return "Overweight"
68
+ else:
69
+ return "Obese"
70
+
71
+ bmi = calculate_bmi(height_cm, weight_kg)
72
+
73
+ # Show BMI instantly when values are entered
74
+ if bmi:
75
+ st.info(f"Your BMI is: {bmi:.2f} ({bmi_category(bmi)})")
76
+
77
+ st.markdown("---")
78
 
79
  # =========================
80
  # 2️⃣ Fitness Details
 
99
 
100
  st.markdown("---")
101
 
102
+ # =========================
103
+ # Submit Button
104
  # =========================
105
  if st.button("Submit Profile"):
106
+
107
  if not name:
108
  st.error("Please enter your name.")
109
+
110
+ elif height_cm <= 0 or weight_kg <= 0:
111
+ st.error("Please enter valid height and weight.")
112
+
113
  elif not equipment:
114
  st.error("Please select at least one equipment option.")
115
+
 
 
 
116
  else:
117
  st.success("✅ Profile Submitted Successfully!")
118
+
119
  bmi_status = bmi_category(bmi)
120
  equipment_list = ", ".join(equipment)
121
+
122
  prompt = f"""
123
  Generate a 5-day structured workout plan.
124
+
125
  User Details:
126
  Name: {name}
127
  Gender: {gender}
128
  BMI: {bmi:.2f} ({bmi_status})
129
+ Goal: {fitness_goal}
130
  Fitness Level: {fitness_level}
131
  Available Equipment: {equipment_list}
132
+
133
  Requirements:
134
  - Include warmup
135
  - Include exercises with sets and reps
 
137
  - Adjust intensity based on BMI and fitness level
138
  - Keep it structured day-wise
139
  """
140
+
141
  with st.spinner("Generating your AI workout plan..."):
142
+ result = generator(
143
+ prompt,
144
+ max_new_tokens=400,
145
+ do_sample=True,
146
+ temperature=0.7
147
+ )[0]["generated_text"]
148
+
149
  st.subheader("🏋️ Your Personalized Workout Plan")
150
  st.write(result)