srbhavya01 commited on
Commit
7d1daea
Β·
verified Β·
1 Parent(s): 9af5de4

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +75 -45
src/streamlit_app.py CHANGED
@@ -1,43 +1,68 @@
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
18
  # -------------------------
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
 
27
  # -------------------------
28
- # 2. Fitness Details
29
  # -------------------------
30
 
31
- st.subheader("Fitness Details")
 
 
 
 
 
 
 
32
 
33
  goal = st.selectbox(
34
- "Select Your Fitness Goal",
35
  ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
36
  )
37
 
38
  equipment = st.multiselect(
39
  "Available Equipment",
40
- ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment"]
 
41
  )
42
 
43
  fitness_level = st.radio(
@@ -49,10 +74,9 @@ fitness_level = st.radio(
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:
@@ -65,45 +89,51 @@ def bmi_category(bmi):
65
  return "Obese"
66
 
67
  # -------------------------
68
- # Submit Button
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)
 
1
  import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+ import torch
4
 
5
+ # -------------------------
6
+ # Page Config FIRST
7
+ # -------------------------
 
8
 
9
+ st.set_page_config(page_title="FitPlan AI", page_icon="πŸ’ͺ")
10
 
11
+ # 🎨 Background Style
 
12
 
13
+ st.markdown(
14
+ """
15
+ <style>
16
+ .stApp {
17
+ background-image: url("https://images.unsplash.com/photo-1554284126-aa88f22d8b74");
18
+ background-size: cover;
19
+ }
20
+ </style>
21
+ """,
22
+ unsafe_allow_html=True
23
+ )
24
 
25
  # -------------------------
26
+ # Load Model (Small for HF)
27
  # -------------------------
28
 
29
+ @st.cache_resource
30
+ def load_model():
31
+ tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-small")
32
+ model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small")
33
+ return tokenizer, model
34
 
35
+ tokenizer, model = load_model()
36
 
37
+ # -------------------------
38
+ # App Title
39
+ # -------------------------
40
+
41
+ st.title("πŸ’ͺ FitPlan AI - BMI Calculator & Workout Planner")
42
+ st.write("Enter your details to get AI workout plan.")
43
 
44
  # -------------------------
45
+ # Personal Info
46
  # -------------------------
47
 
48
+ name = st.text_input("Enter Your Name *")
49
+ gender = st.selectbox("Gender", ["Male", "Female", "Other"])
50
+ height_cm = st.number_input("Height (cm)", min_value=0.0)
51
+ weight_kg = st.number_input("Weight (kg)", min_value=0.0)
52
+
53
+ # -------------------------
54
+ # Fitness Details
55
+ # -------------------------
56
 
57
  goal = st.selectbox(
58
+ "Fitness Goal",
59
  ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
60
  )
61
 
62
  equipment = st.multiselect(
63
  "Available Equipment",
64
+ ["Dumbbells", "Resistance Band", "Yoga Mat", "Skipping Rope",
65
+ "Weight Plates", "Cycling", "Inclined Bench", "Pullups Bar", "No Equipment"]
66
  )
67
 
68
  fitness_level = st.radio(
 
74
  # BMI Functions
75
  # -------------------------
76
 
77
+ def calculate_bmi(weight, height):
78
+ height_m = height / 100
79
+ return round(weight / (height_m ** 2), 2)
 
80
 
81
  def bmi_category(bmi):
82
  if bmi < 18.5:
 
89
  return "Obese"
90
 
91
  # -------------------------
92
+ # Generate Plan
93
  # -------------------------
94
 
95
+ if st.button("Generate Workout Plan"):
96
 
 
97
  if not name:
98
+ st.error("Enter your name")
99
  elif height_cm <= 0 or weight_kg <= 0:
100
+ st.error("Enter valid height & weight")
101
  elif not equipment:
102
+ st.error("Select equipment")
103
  else:
 
 
 
104
  bmi = calculate_bmi(weight_kg, height_cm)
105
  bmi_status = bmi_category(bmi)
106
 
107
+ st.success(f"BMI: {bmi} ({bmi_status})")
108
 
109
  equipment_list = ", ".join(equipment)
110
 
111
  prompt = f"""
112
+ Create a 5-day workout plan.
113
 
114
+ Include warmup, exercises, sets, reps, rest time.
115
+
116
+ Day 1 – Chest & Triceps: Bench Press 4Γ—8–10, Incline Press 3Γ—10, Dips 3Γ—12, Tricep Extensions 3Γ—12.
 
 
 
 
117
 
118
+ Day 2 – Back & Biceps: Pull-ups 4Γ—8–10, Rows 4Γ—10, Band Rows 3Γ—12, Bicep Curls 3Γ—12.
 
119
 
120
+ Day 3 – Legs: Squats 4Γ—8–10, Lunges 3Γ—12/leg, Romanian Deadlift 3Γ—10, Calf Raises 4Γ—15.
121
+
122
+ Day 4 – Shoulders & Core: Overhead Press 4Γ—8–10, Lateral Raises 3Γ—12, Plank 3Γ—60s, Leg Raises 3Γ—12.
123
+
124
+ Day 5 – Cardio & Conditioning: 25-min Run, Skipping 3Γ—2min, Burpees 3Γ—12, Mountain Climbers 3Γ—30s.
125
+
126
+ """
127
 
128
+ with st.spinner("Generating workout plan..."):
129
+ inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
130
+ outputs = model.generate(
131
+ **inputs,
132
+ max_new_tokens=400,
133
+ temperature=0.7,
134
+ do_sample=True
135
+ )
136
+ result = tokenizer.decode(outputs[0], skip_special_tokens=True)
137
+
138
+ st.subheader("πŸ‹οΈ Your Workout Plan")
139
  st.write(result)