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

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +56 -55
src/streamlit_app.py CHANGED
@@ -1,18 +1,17 @@
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
- # -----------------------------
12
  def calculate_bmi(weight, height_cm):
13
  height_m = height_cm / 100
14
- bmi = weight / (height_m ** 2)
15
- return round(bmi, 2)
16
 
17
  def get_category(bmi):
18
  if bmi < 18.5:
@@ -24,26 +23,26 @@ def get_category(bmi):
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
 
37
  generator = load_model()
38
 
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
 
@@ -53,7 +52,7 @@ with st.form("fitness_form"):
53
  with col2:
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",
@@ -72,52 +71,54 @@ with st.form("fitness_form"):
72
 
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)
93
- bmi_status = get_category(user_bmi)
94
-
95
- st.success(f" Profile Created Successfully for {name}!")
96
- st.metric("Your BMI", user_bmi)
97
- st.info(f"Health Category: **{bmi_status}**")
98
-
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..."):
120
- result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
121
-
122
- st.subheader("🏋️ Your Personalized Workout Plan")
123
- st.write(result)
 
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
+ # -------------------------
12
  def calculate_bmi(weight, height_cm):
13
  height_m = height_cm / 100
14
+ return round(weight / (height_m ** 2), 2)
 
15
 
16
  def get_category(bmi):
17
  if bmi < 18.5:
 
23
  else:
24
  return "Obese"
25
 
26
+ # -------------------------
27
+ # LOAD MODEL (Correct Pipeline)
28
+ # -------------------------
29
  @st.cache_resource
30
  def load_model():
31
  return pipeline(
32
+ "text2text-generation", # Correct for FLAN-T5
33
  model="google/flan-t5-base"
34
  )
35
 
36
  generator = load_model()
37
 
38
+ # -------------------------
39
+ # UI STARTS
40
+ # -------------------------
41
  st.title("💪 FitPlan-AI: Personalized Fitness Profile")
42
 
43
  with st.form("fitness_form"):
44
 
45
+ st.subheader("Personal Information")
46
 
47
  name = st.text_input("Full Name*", placeholder="Enter your name")
48
 
 
52
  with col2:
53
  weight = st.number_input("Weight (kg)*", min_value=1.0, step=0.1)
54
 
55
+ st.subheader("Fitness Details")
56
 
57
  goal = st.selectbox(
58
  "Fitness Goal",
 
71
 
72
  submit = st.form_submit_button("Generate Workout Plan")
73
 
74
+ # -------------------------
75
+ # HANDLE SUBMISSION
76
+ # -------------------------
77
  if submit:
78
 
79
  # Validation
80
  if name.strip() == "":
81
  st.error("Please enter your name.")
82
+ st.stop()
83
 
84
+ if height <= 0 or weight <= 0:
85
  st.error("Height and Weight must be positive values.")
86
+ st.stop()
87
 
88
+ if len(equipment) == 0:
89
  st.error("Please select at least one equipment option.")
90
+ st.stop()
91
 
92
+ # Calculate BMI
93
+ user_bmi = calculate_bmi(weight, height)
94
+ bmi_status = get_category(user_bmi)
95
+
96
+ st.success(f"✅ Profile Created Successfully for {name}!")
97
+ st.metric("Your BMI", user_bmi)
98
+ st.info(f"Health Category: **{bmi_status}**")
99
+
100
+ equipment_list = ", ".join(equipment)
101
+
102
+ prompt = f"""
103
+ Create a professional 5-day structured workout plan.
104
+
105
+ User Details:
106
+ Name: {name}
107
+ BMI: {user_bmi} ({bmi_status})
108
+ Goal: {goal}
109
+ Fitness Level: {level}
110
+ Equipment: {equipment_list}
111
+
112
+ Include:
113
+ - Warm-up
114
+ - Exercises with sets and reps
115
+ - Rest time
116
+ - Intensity adjustment
117
+ - Day-wise structure
118
+ """
119
+
120
+ with st.spinner("Generating your AI workout plan..."):
121
+ result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
122
+
123
+ st.subheader("🏋️ Your Personalized Workout Plan")
124
+ st.write(result)