srbhavya01 commited on
Commit
0630897
·
verified ·
1 Parent(s): faf7f58

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +31 -33
src/streamlit_app.py CHANGED
@@ -1,18 +1,17 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
 
 
4
  def load_model():
5
- return pipeline(
6
- "text-generation",
7
- model="google/flan-t5-base"
8
- )
9
-
10
  generator = load_model()
11
 
12
  st.set_page_config(page_title="FitPlan AI - BMI Calculator", page_icon="💪")
13
  st.title("💪 FitPlan AI - Fitness Profile & BMI Calculator")
14
 
15
- st.write("Fill in your details to calculate your BMI and fitness category.")
16
 
17
  # -------------------------
18
  # 1. Personal Information
@@ -20,6 +19,8 @@ st.write("Fill in your details to calculate your BMI and fitness category.")
20
 
21
  name = st.text_input("Enter Your Name *")
22
 
 
 
23
  height_cm = st.number_input("Enter Height (in centimeters) *", min_value=0.0, format="%.2f")
24
  weight_kg = st.number_input("Enter Weight (in kilograms) *", min_value=0.0, format="%.2f")
25
 
@@ -35,30 +36,30 @@ goal = st.selectbox(
35
  )
36
 
37
  equipment = st.multiselect(
38
- "Available Equipment (Select multiple if available)",
39
  ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment"]
40
  )
41
 
42
  fitness_level = st.radio(
43
- "Select Your Fitness Level",
44
  ["Beginner", "Intermediate", "Advanced"]
45
  )
46
 
47
  # -------------------------
48
- # BMI Calculation Function
49
  # -------------------------
50
 
51
  def calculate_bmi(weight, height_cm):
52
- height_m = height_cm / 100 # Convert cm to meters
53
  bmi = weight / (height_m ** 2)
54
  return round(bmi, 2)
55
 
56
  def bmi_category(bmi):
57
  if bmi < 18.5:
58
  return "Underweight"
59
- elif 18.5 <= bmi < 24.9:
60
  return "Normal"
61
- elif 25 <= bmi < 29.9:
62
  return "Overweight"
63
  else:
64
  return "Obese"
@@ -68,44 +69,41 @@ def bmi_category(bmi):
68
  # -------------------------
69
 
70
  if st.button("Submit Profile"):
71
-
 
72
  if not name:
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 bmi is None:
79
- st.error("Please enter valid height and weight.")
80
-
81
  else:
82
  st.success("✅ Profile Submitted Successfully!")
83
-
 
 
84
  bmi_status = bmi_category(bmi)
 
 
 
85
  equipment_list = ", ".join(equipment)
86
-
87
  prompt = f"""
88
  Generate a 5-day structured workout plan.
89
-
90
  User Details:
91
  Name: {name}
92
  Gender: {gender}
93
- BMI: {bmi:.2f} ({bmi_status})
94
  Goal: {goal}
95
  Fitness Level: {fitness_level}
96
  Available Equipment: {equipment_list}
97
-
98
- Requirements:
99
- - Include warmup
100
- - Include exercises with sets and reps
101
- - Include rest time
102
- - Adjust intensity based on BMI and fitness level
103
- - Keep it structured day-wise
104
  """
105
-
106
  with st.spinner("Generating your AI workout plan..."):
107
  result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
108
-
109
  st.subheader("🏋️ Your Personalized Workout Plan")
110
  st.write(result)
111
-
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ # Load model only once
5
+ @st.cache_resource
6
  def load_model():
7
+ return pipeline("text-generation", model="google/flan-t5-base")
8
+
 
 
 
9
  generator = load_model()
10
 
11
  st.set_page_config(page_title="FitPlan AI - BMI Calculator", page_icon="💪")
12
  st.title("💪 FitPlan AI - Fitness Profile & BMI Calculator")
13
 
14
+ st.write("Fill in your details to calculate your BMI and get AI workout plan.")
15
 
16
  # -------------------------
17
  # 1. Personal Information
 
19
 
20
  name = st.text_input("Enter Your Name *")
21
 
22
+ gender = st.selectbox("Select Gender", ["Male", "Female", "Other"])
23
+
24
  height_cm = st.number_input("Enter Height (in centimeters) *", min_value=0.0, format="%.2f")
25
  weight_kg = st.number_input("Enter Weight (in kilograms) *", min_value=0.0, format="%.2f")
26
 
 
36
  )
37
 
38
  equipment = st.multiselect(
39
+ "Available Equipment",
40
  ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment"]
41
  )
42
 
43
  fitness_level = st.radio(
44
+ "Fitness Level",
45
  ["Beginner", "Intermediate", "Advanced"]
46
  )
47
 
48
  # -------------------------
49
+ # BMI Functions
50
  # -------------------------
51
 
52
  def calculate_bmi(weight, height_cm):
53
+ height_m = height_cm / 100
54
  bmi = weight / (height_m ** 2)
55
  return round(bmi, 2)
56
 
57
  def bmi_category(bmi):
58
  if bmi < 18.5:
59
  return "Underweight"
60
+ elif bmi < 24.9:
61
  return "Normal"
62
+ elif bmi < 29.9:
63
  return "Overweight"
64
  else:
65
  return "Obese"
 
69
  # -------------------------
70
 
71
  if st.button("Submit Profile"):
72
+
73
+ # Validation
74
  if not name:
75
  st.error("Please enter your name.")
76
+ elif height_cm <= 0 or weight_kg <= 0:
77
+ st.error("Enter valid height and weight.")
78
  elif not equipment:
79
+ st.error("Select at least one equipment option.")
 
 
 
 
80
  else:
81
  st.success("✅ Profile Submitted Successfully!")
82
+
83
+ # Calculate BMI
84
+ bmi = calculate_bmi(weight_kg, height_cm)
85
  bmi_status = bmi_category(bmi)
86
+
87
+ st.write(f"### 📊 BMI: {bmi} ({bmi_status})")
88
+
89
  equipment_list = ", ".join(equipment)
90
+
91
  prompt = f"""
92
  Generate a 5-day structured workout plan.
93
+
94
  User Details:
95
  Name: {name}
96
  Gender: {gender}
97
+ BMI: {bmi} ({bmi_status})
98
  Goal: {goal}
99
  Fitness Level: {fitness_level}
100
  Available Equipment: {equipment_list}
101
+
102
+ Include warmup, exercises with sets & reps, rest time.
 
 
 
 
 
103
  """
104
+
105
  with st.spinner("Generating your AI workout plan..."):
106
  result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
107
+
108
  st.subheader("🏋️ Your Personalized Workout Plan")
109
  st.write(result)