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

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +63 -34
src/streamlit_app.py CHANGED
@@ -1,29 +1,16 @@
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
@@ -35,11 +22,10 @@ def load_model():
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
@@ -94,6 +80,7 @@ def bmi_category(bmi):
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:
@@ -101,31 +88,64 @@ if st.button("Generate Workout Plan"):
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,
@@ -135,5 +155,14 @@ Day 5 – Cardio & Conditioning: 25-min Run, Skipping 3Γ—2min, Burpees 3Γ—12, Mo
135
  )
136
  result = tokenizer.decode(outputs[0], skip_special_tokens=True)
137
 
138
- st.subheader("πŸ‹οΈ Your Workout Plan")
139
- st.write(result)
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
  import torch
4
+ import time
5
 
6
  # -------------------------
7
+ # Page Config
8
  # -------------------------
9
 
10
  st.set_page_config(page_title="FitPlan AI", page_icon="πŸ’ͺ")
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # -------------------------
13
+ # Load Model
14
  # -------------------------
15
 
16
  @st.cache_resource
 
22
  tokenizer, model = load_model()
23
 
24
  # -------------------------
25
+ # Title
26
  # -------------------------
27
 
28
  st.title("πŸ’ͺ FitPlan AI - BMI Calculator & Workout Planner")
 
29
 
30
  # -------------------------
31
  # Personal Info
 
80
 
81
  if st.button("Generate Workout Plan"):
82
 
83
+ # Validation
84
  if not name:
85
  st.error("Enter your name")
86
  elif height_cm <= 0 or weight_kg <= 0:
 
88
  elif not equipment:
89
  st.error("Select equipment")
90
  else:
91
+
92
+ # BMI
93
  bmi = calculate_bmi(weight_kg, height_cm)
94
  bmi_status = bmi_category(bmi)
95
 
96
+ st.success(f"βœ… Welcome {name}! BMI: {bmi} ({bmi_status})")
97
 
98
+ # -------------------------
99
+ # Progress Bar Animation
100
+ # -------------------------
101
 
102
+ progress = st.progress(0)
103
+ status = st.empty()
104
+
105
+ for i in range(100):
106
+ time.sleep(0.01)
107
+ progress.progress(i + 1)
108
+ status.text("Generating personalized fitness plan...")
109
+
110
+ st.divider()
111
+
112
+ # -------------------------
113
+ # Core AI Module Layout
114
+ # -------------------------
115
+
116
+ st.subheader("🧠 Core AI Inference Module")
117
+
118
+ col1, col2, col3 = st.columns(3)
119
 
120
+ with col1:
121
+ st.info("πŸ”½ Input Layer\nUser goals, equipment, fitness level")
 
122
 
123
+ with col2:
124
+ st.info("βš™ Processing\nAI model analysis")
125
 
126
+ with col3:
127
+ st.info("πŸ“€ Output Layer\nWorkout plan")
128
 
129
+ st.divider()
130
+
131
+ # -------------------------
132
+ # Model Input & Output
133
+ # -------------------------
134
+
135
+ equipment_list = ", ".join(equipment)
136
+
137
+ prompt = f"""
138
+ Create a structured 5-day workout plan.
139
+
140
+ User:
141
+ Goal: {goal}
142
+ Fitness Level: {fitness_level}
143
+ Equipment: {equipment_list}
144
+
145
+ Include exercises with sets, reps, and rest time.
146
  """
147
 
148
+ with st.spinner("AI is creating your plan..."):
149
  inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
150
  outputs = model.generate(
151
  **inputs,
 
155
  )
156
  result = tokenizer.decode(outputs[0], skip_special_tokens=True)
157
 
158
+ col4, col5 = st.columns(2)
159
+
160
+ with col4:
161
+ st.subheader("πŸ“₯ Model Input")
162
+ st.write(prompt)
163
+
164
+ with col5:
165
+ st.subheader("πŸ“€ Model Output")
166
+ st.write(result)
167
+
168
+ st.success("πŸ‹οΈ Your Personalized Workout Plan Ready!")