srustik123 commited on
Commit
3b0b8ca
·
verified ·
1 Parent(s): 6f4353a

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +34 -25
src/streamlit_app.py CHANGED
@@ -1,6 +1,11 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
 
 
 
 
 
4
  # -----------------------------
5
  # BMI Functions
6
  # -----------------------------
@@ -12,20 +17,20 @@ def calculate_bmi(weight, height_cm):
12
  def get_category(bmi):
13
  if bmi < 18.5:
14
  return "Underweight"
15
- elif 18.5 <= bmi < 24.9:
16
  return "Normal"
17
- elif 25 <= bmi < 29.9:
18
  return "Overweight"
19
  else:
20
  return "Obese"
21
 
22
  # -----------------------------
23
- # Load AI Model
24
  # -----------------------------
25
  @st.cache_resource
26
  def load_model():
27
  return pipeline(
28
- "text-generation",
29
  model="google/flan-t5-base"
30
  )
31
 
@@ -34,14 +39,14 @@ generator = load_model()
34
  # -----------------------------
35
  # UI
36
  # -----------------------------
37
- st.set_page_config(page_title="FitPlan-AI", page_icon="💪")
38
  st.title("💪 FitPlan-AI: Personalized Fitness Profile")
39
 
40
  with st.form("fitness_form"):
 
41
  st.header("Personal Information")
42
-
43
  name = st.text_input("Full Name*", placeholder="Enter your name")
44
-
45
  col1, col2 = st.columns(2)
46
  with col1:
47
  height = st.number_input("Height (cm)*", min_value=1.0, step=0.1)
@@ -49,14 +54,17 @@ with st.form("fitness_form"):
49
  weight = st.number_input("Weight (kg)*", min_value=1.0, step=0.1)
50
 
51
  st.header("Fitness Details")
52
-
53
  goal = st.selectbox(
54
  "Fitness Goal",
55
  ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
56
  )
57
-
58
- level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
59
-
 
 
 
60
  equipment = st.multiselect(
61
  "Available Equipment",
62
  ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment", "Kettlebell", "Pull-up Bar"]
@@ -65,19 +73,20 @@ with st.form("fitness_form"):
65
  submit = st.form_submit_button("Generate Workout Plan")
66
 
67
  # -----------------------------
68
- # When Form is Submitted
69
  # -----------------------------
70
  if submit:
71
 
72
- if not name.strip():
 
73
  st.error("Please enter your name.")
74
 
75
- elif not equipment:
76
- st.error("Please select at least one equipment option.")
77
-
78
  elif height <= 0 or weight <= 0:
79
  st.error("Height and Weight must be positive values.")
80
 
 
 
 
81
  else:
82
  # Calculate BMI
83
  user_bmi = calculate_bmi(weight, height)
@@ -90,21 +99,21 @@ if submit:
90
  equipment_list = ", ".join(equipment)
91
 
92
  prompt = f"""
93
- Generate a 5-day structured workout plan.
94
 
95
  User Details:
96
  Name: {name}
97
  BMI: {user_bmi} ({bmi_status})
98
  Goal: {goal}
99
  Fitness Level: {level}
100
- Available Equipment: {equipment_list}
101
-
102
- Requirements:
103
- - Include warmup
104
- - Include exercises with sets and reps
105
- - Include rest time
106
- - Adjust intensity based on BMI and fitness level
107
- - Keep it structured day-wise
108
  """
109
 
110
  with st.spinner("Generating your AI workout plan..."):
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ # -----------------------------
5
+ # PAGE CONFIG (MUST BE FIRST)
6
+ # -----------------------------
7
+ st.set_page_config(page_title="FitPlan-AI", page_icon="💪")
8
+
9
  # -----------------------------
10
  # BMI Functions
11
  # -----------------------------
 
17
  def get_category(bmi):
18
  if bmi < 18.5:
19
  return "Underweight"
20
+ elif bmi < 24.9:
21
  return "Normal"
22
+ elif bmi < 29.9:
23
  return "Overweight"
24
  else:
25
  return "Obese"
26
 
27
  # -----------------------------
28
+ # Load AI Model (Correct Pipeline)
29
  # -----------------------------
30
  @st.cache_resource
31
  def load_model():
32
  return pipeline(
33
+ "text2text-generation", # ✅ Correct for FLAN-T5
34
  model="google/flan-t5-base"
35
  )
36
 
 
39
  # -----------------------------
40
  # UI
41
  # -----------------------------
 
42
  st.title("💪 FitPlan-AI: Personalized Fitness Profile")
43
 
44
  with st.form("fitness_form"):
45
+
46
  st.header("Personal Information")
47
+
48
  name = st.text_input("Full Name*", placeholder="Enter your name")
49
+
50
  col1, col2 = st.columns(2)
51
  with col1:
52
  height = st.number_input("Height (cm)*", min_value=1.0, step=0.1)
 
54
  weight = st.number_input("Weight (kg)*", min_value=1.0, step=0.1)
55
 
56
  st.header("Fitness Details")
57
+
58
  goal = st.selectbox(
59
  "Fitness Goal",
60
  ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
61
  )
62
+
63
+ level = st.radio(
64
+ "Fitness Level",
65
+ ["Beginner", "Intermediate", "Advanced"]
66
+ )
67
+
68
  equipment = st.multiselect(
69
  "Available Equipment",
70
  ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment", "Kettlebell", "Pull-up Bar"]
 
73
  submit = st.form_submit_button("Generate Workout Plan")
74
 
75
  # -----------------------------
76
+ # FORM SUBMISSION LOGIC
77
  # -----------------------------
78
  if submit:
79
 
80
+ # Validation
81
+ if name.strip() == "":
82
  st.error("Please enter your name.")
83
 
 
 
 
84
  elif height <= 0 or weight <= 0:
85
  st.error("Height and Weight must be positive values.")
86
 
87
+ elif len(equipment) == 0:
88
+ st.error("Please select at least one equipment option.")
89
+
90
  else:
91
  # Calculate BMI
92
  user_bmi = calculate_bmi(weight, height)
 
99
  equipment_list = ", ".join(equipment)
100
 
101
  prompt = f"""
102
+ Create a professional 5-day structured workout plan.
103
 
104
  User Details:
105
  Name: {name}
106
  BMI: {user_bmi} ({bmi_status})
107
  Goal: {goal}
108
  Fitness Level: {level}
109
+ Equipment: {equipment_list}
110
+
111
+ Include:
112
+ - Warm-up
113
+ - Exercises with sets and reps
114
+ - Rest time
115
+ - Intensity adjustment
116
+ - Day-wise structure
117
  """
118
 
119
  with st.spinner("Generating your AI workout plan..."):