srustik123 commited on
Commit
72d882d
·
verified ·
1 Parent(s): 1ecf138

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +45 -65
src/streamlit_app.py CHANGED
@@ -2,7 +2,7 @@ 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
 
@@ -24,14 +24,11 @@ def get_category(bmi):
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
 
@@ -43,7 +40,6 @@ st.title("💪 FitPlan-AI: Personalized Fitness Profile")
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
 
49
  col1, col2 = st.columns(2)
@@ -53,17 +49,11 @@ with st.form("fitness_form"):
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",
59
  ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
60
  )
61
-
62
- level = st.radio(
63
- "Fitness Level",
64
- ["Beginner", "Intermediate", "Advanced"]
65
- )
66
-
67
  equipment = st.multiselect(
68
  "Available Equipment",
69
  ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment", "Kettlebell", "Pull-up Bar"]
@@ -71,54 +61,44 @@ with st.form("fitness_form"):
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)
 
2
  from transformers import pipeline
3
 
4
  # -------------------------
5
+ # PAGE CONFIG
6
  # -------------------------
7
  st.set_page_config(page_title="FitPlan-AI", page_icon="💪")
8
 
 
24
  return "Obese"
25
 
26
  # -------------------------
27
+ # LOAD AI MODEL
28
  # -------------------------
29
  @st.cache_resource
30
  def load_model():
31
+ return pipeline("text2text-generation", model="google/flan-t5-base")
 
 
 
32
 
33
  generator = load_model()
34
 
 
40
  with st.form("fitness_form"):
41
 
42
  st.subheader("Personal Information")
 
43
  name = st.text_input("Full Name*", placeholder="Enter your name")
44
 
45
  col1, col2 = st.columns(2)
 
49
  weight = st.number_input("Weight (kg)*", min_value=1.0, step=0.1)
50
 
51
  st.subheader("Fitness Details")
 
52
  goal = st.selectbox(
53
  "Fitness Goal",
54
  ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
55
  )
56
+ level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
 
 
 
 
 
57
  equipment = st.multiselect(
58
  "Available Equipment",
59
  ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment", "Kettlebell", "Pull-up Bar"]
 
61
 
62
  submit = st.form_submit_button("Generate Workout Plan")
63
 
64
+ # ✅ ALL LOGIC INSIDE FORM
65
+ if submit:
66
+ # Validation
67
+ if not name.strip():
68
+ st.error("Please enter your name.")
69
+ elif height <= 0 or weight <= 0:
70
+ st.error("Height and Weight must be positive values.")
71
+ elif not equipment:
72
+ st.error("Please select at least one equipment option.")
73
+ else:
74
+ # Calculate BMI
75
+ user_bmi = calculate_bmi(weight, height)
76
+ bmi_status = get_category(user_bmi)
77
+
78
+ st.success(f"✅ Profile Created Successfully for {name}!")
79
+ st.metric("Your BMI", user_bmi)
80
+ st.info(f"Health Category: **{bmi_status}**")
81
+
82
+ equipment_list = ", ".join(equipment)
83
+
84
+ prompt = f"""
85
+ Create a professional 5-day structured workout plan.
86
+ User Details:
87
+ Name: {name}
88
+ BMI: {user_bmi} ({bmi_status})
89
+ Goal: {goal}
90
+ Fitness Level: {level}
91
+ Equipment: {equipment_list}
92
+ Include:
93
+ - Warm-up
94
+ - Exercises with sets and reps
95
+ - Rest time
96
+ - Intensity adjustment
97
+ - Day-wise structure
98
+ """
99
+
100
+ with st.spinner("Generating your AI workout plan..."):
101
+ result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
102
+
103
+ st.subheader("🏋️ Your Personalized Workout Plan")
104
+ st.write(result)