Amrutha04 commited on
Commit
9f8a8e0
Β·
verified Β·
1 Parent(s): 0ce92f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -117
app.py CHANGED
@@ -5,7 +5,7 @@ from diet_builder import build_diet_prompt
5
 
6
  st.set_page_config(page_title="FitPlan AI", layout="wide")
7
 
8
- # --- CSS: PRESERVING ALL PREVIOUS STYLES + NEW DASHBOARD ---
9
  st.markdown("""
10
  <style>
11
  header {visibility: hidden;}
@@ -13,146 +13,116 @@ st.markdown("""
13
  section[data-testid="stSidebar"] { background-color: #000000 !important; }
14
  section[data-testid="stSidebar"] h1, section[data-testid="stSidebar"] p { color: #FFFFFF !important; }
15
 
16
- /* Login Box */
17
- .login-box { background: white; padding: 40px; border-radius: 20px; box-shadow: 0 10px 25px rgba(0,0,0,0.1); text-align: center; margin-top: 10vh; }
18
-
19
- /* Assessment Card (Preserved from your original) */
20
  .assessment-card {
21
  background-color: white !important; padding: 25px; border-radius: 15px;
22
  border-left: 10px solid #004d57; color: #000000 !important; margin-bottom: 30px;
23
  }
24
-
25
- /* Dashboard Metric Cards */
26
  .stat-card { background: white; padding: 20px; border-radius: 15px; text-align: center; border-top: 5px solid #004d57; box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
27
- .stat-val { font-size: 22px; font-weight: bold; color: #004d57; }
28
- .stat-lbl { font-size: 12px; color: #636e72; text-transform: uppercase; }
29
-
30
- /* Unified White Box (Preserved from your original) */
31
- .day-container {
32
- background-color: white !important; padding: 30px; border-radius: 25px;
33
- margin-bottom: 40px; box-shadow: 0 10px 30px rgba(0,0,0,0.1);
34
- }
35
  .day-header { color: #004d57; font-size: 26px; font-weight: bold; margin-bottom: 20px; border-bottom: 2px solid #f0f2f6; padding-bottom: 15px; }
36
-
37
  .item-row { display: flex; align-items: center; justify-content: space-between; padding: 18px 0; border-bottom: 1px solid #f1f1f1; }
38
  .item-row:last-child { border-bottom: none; }
39
- .item-name { flex: 2; font-weight: 600; color: #2d3436; font-size: 18px; }
40
-
41
  .stat-group { display: flex; gap: 15px; flex: 1.5; justify-content: flex-end; }
42
  .stat-pill { text-align: center; min-width: 75px; background: #f8f9fa; padding: 6px; border-radius: 12px; }
43
- .pill-val { color: #004d57; font-weight: bold; font-size: 15px; display: block; }
44
- .pill-lbl { font-size: 10px; color: #636e72; text-transform: uppercase; display: block; }
45
  </style>
46
  """, unsafe_allow_html=True)
47
 
48
- # --- STATE MANAGEMENT ---
49
- if 'logged_in' not in st.session_state: st.session_state.logged_in = False
50
  if 'page' not in st.session_state: st.session_state.page = 'dashboard'
51
  if 'user_data' not in st.session_state: st.session_state.user_data = None
52
  if 'workout_plan' not in st.session_state: st.session_state.workout_plan = None
53
  if 'diet_plan' not in st.session_state: st.session_state.diet_plan = None
54
 
55
- # --- LOGIN PAGE ---
56
- if not st.session_state.logged_in:
57
- _, col, _ = st.columns([1, 2, 1])
58
- with col:
59
- st.markdown('<div class="login-box">', unsafe_allow_html=True)
60
- st.title("πŸ‹οΈ FitPlan AI Login")
61
- email = st.text_input("Email ID")
62
- if st.button("Login", use_container_width=True):
63
- if "@" in email:
64
- st.session_state.logged_in = True
65
- st.rerun()
66
- st.markdown('</div>', unsafe_allow_html=True)
67
 
68
- else:
69
- # --- SIDEBAR (Preserved Style) ---
70
- with st.sidebar:
71
- st.markdown("# πŸ‘€ Personalised Fitness")
72
- if st.button("πŸ“Š Dashboard", use_container_width=True): st.session_state.page = 'dashboard'; st.rerun()
73
- if st.button("πŸ‹οΈ Workout Plan", use_container_width=True): st.session_state.page = 'input'; st.rerun()
74
- if st.button("πŸ₯— Dietary Plan", use_container_width=True): st.session_state.page = 'diet'; st.rerun()
 
 
 
75
  st.write("---")
76
- if st.button("Logout"): st.session_state.logged_in = False; st.rerun()
77
-
78
- # --- DASHBOARD ---
79
- if st.session_state.page == 'dashboard':
80
- st.title("πŸ“Š Your Fitness Dashboard")
81
- if st.session_state.user_data:
82
- d = st.session_state.user_data
83
- c1, c2, c3, c4 = st.columns(4)
84
- with c1: st.markdown(f'<div class="stat-card"><div class="stat-val">{d["name"]}</div><div class="stat-lbl">Member</div></div>', unsafe_allow_html=True)
85
- with c2: st.markdown(f'<div class="stat-card"><div class="stat-val">{d["bmi"]:.1f}</div><div class="stat-lbl">BMI</div></div>', unsafe_allow_html=True)
86
- with c3: st.markdown(f'<div class="stat-card"><div class="stat-val" style="color:{d["color"]}">{d["status"]}</div><div class="stat-lbl">Status</div></div>', unsafe_allow_html=True)
87
- with c4: st.markdown(f'<div class="stat-card"><div class="stat-val">{d["goal"]}</div><div class="stat-lbl">Goal</div></div>', unsafe_allow_html=True)
88
- else:
89
- st.info("No profile found. Please click 'Workout Plan' to generate your routine.")
90
 
91
- # --- INPUT PAGE ---
92
- elif st.session_state.page == 'input':
93
- st.title("πŸ‹οΈ Fitness Profile")
94
- col1, col2, col3 = st.columns([2, 1, 1])
95
- with col1: name = st.text_input("Name")
96
- with col2: gender = st.selectbox("Gender", ["Male", "Female", "Other"])
97
- with col3: age = st.number_input("Age", min_value=1, value=19)
98
- h, w = st.columns(2)
99
- with h: height = st.number_input("Height (cm)", min_value=1.0)
100
- with w: weight = st.number_input("Weight (kg)", min_value=1.0)
101
- goal = st.selectbox("Goal", ["Build Muscle", "Weight Loss", "Strength", "Flexibility"])
102
- level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
103
- equip = st.multiselect("Equipment", ["Dumbbells", "Kettlebells", "Pull-up Bar", "Resistance Bands", "Yoga Mat", "No Equipment"])
104
 
105
- if st.button("Generate Plan"):
106
- prompt, bmi, status, color = build_prompt(name, gender, age, height, weight, goal, level, equip)
107
- with st.spinner("AI is crafting your routine..."):
108
- st.session_state.workout_plan = query_model(prompt)
109
- st.session_state.user_data = {"name": name, "bmi": bmi, "status": status, "color": color, "age": age, "gender": gender, "goal": goal, "height": height, "weight": weight}
110
- st.session_state.diet_plan = None # Reset diet for new profile
111
- st.session_state.page = 'result'
112
- st.rerun()
113
 
114
- # --- RESULT PAGE (Workout) ---
115
- elif st.session_state.page == 'result':
116
- d = st.session_state.user_data
117
- st.markdown(f'<div class="assessment-card"><h2>Hello {d["name"]}</h2><p>BMI: <strong>{d["bmi"]:.2f}</strong> | <span style="color:{d["color"]}">{d["status"]}</span></p></div>', unsafe_allow_html=True)
118
-
119
- raw_content = st.session_state.workout_plan
120
- days = ["Day 1:", "Day 2:", "Day 3:", "Day 4:", "Day 5:"]
121
- for i in range(len(days)):
122
- start = raw_content.find(days[i])
123
- if start != -1:
124
- end = raw_content.find(days[i+1]) if i+1 < len(days) else len(raw_content)
125
- day_text = raw_content[start:end].strip()
126
- st.markdown(f'<div class="day-container"><div class="day-header">πŸ”· {days[i][:-1]}</div>', unsafe_allow_html=True)
127
- for line in day_text.split("\n"):
128
- if "|" in line:
129
- parts = [p.strip() for p in line.replace("- ", "").split("|")]
130
- if len(parts) == 4:
131
- n, s, r, rs = parts
132
- st.markdown(f'<div class="item-row"><div class="item-name">πŸ”₯ {n}</div><div class="stat-group"><div class="stat-pill"><span class="pill-val">{s}</span><span class="pill-lbl">Sets</span></div><div class="stat-pill"><span class="pill-val">{r}</span><span class="pill-lbl">Reps</span></div><div class="stat-pill" style="background:#fff3e0;"><span class="pill-val" style="color:#e65100;">{rs}</span><span class="pill-lbl">Rest</span></div></div></div>', unsafe_allow_html=True)
133
- st.markdown('</div>', unsafe_allow_html=True)
134
-
135
- # Download Button Preserved
136
- st.download_button("πŸ“₯ Download Full Plan", data=raw_content, file_name=f"{d['name']}_Workout.txt")
137
-
138
- # --- DIET PAGE ---
139
- elif st.session_state.page == 'diet':
140
- st.title("πŸ₯— Personalized Dietary Plan")
141
- if st.session_state.user_data:
142
- d = st.session_state.user_data
143
- if not st.session_state.diet_plan:
144
- diet_prompt = build_diet_prompt(d['name'], d['gender'], d['age'], d['height'], d['weight'], d['goal'])
145
- with st.spinner("Preparing meal plan..."):
146
- st.session_state.diet_plan = query_model(diet_prompt)
147
-
148
- raw_diet = st.session_state.diet_plan
149
- st.markdown('<div class="day-container"><div class="day-header">🍽️ Daily Nutrition</div>', unsafe_allow_html=True)
150
- for line in raw_diet.split("\n"):
151
  if "|" in line:
152
  parts = [p.strip() for p in line.replace("- ", "").split("|")]
153
  if len(parts) == 4:
154
- m_n, m_t, m_i, m_c = parts
155
- st.markdown(f'<div class="item-row"><div class="item-name">🍴 {m_n}<br><small>{m_i}</small></div><div class="stat-group"><div class="stat-pill"><span class="pill-val">{m_t}</span><span class="pill-lbl">Time</span></div><div class="stat-pill" style="background:#e8f5e9;"><span class="pill-val" style="color:#2e7d32;">{m_c}</span><span class="pill-lbl">Energy</span></div></div></div>', unsafe_allow_html=True)
156
  st.markdown('</div>', unsafe_allow_html=True)
157
- else:
158
- st.warning("Please generate a profile first.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  st.set_page_config(page_title="FitPlan AI", layout="wide")
7
 
8
+ # --- UI STYLING (Preserving your exact original look) ---
9
  st.markdown("""
10
  <style>
11
  header {visibility: hidden;}
 
13
  section[data-testid="stSidebar"] { background-color: #000000 !important; }
14
  section[data-testid="stSidebar"] h1, section[data-testid="stSidebar"] p { color: #FFFFFF !important; }
15
 
 
 
 
 
16
  .assessment-card {
17
  background-color: white !important; padding: 25px; border-radius: 15px;
18
  border-left: 10px solid #004d57; color: #000000 !important; margin-bottom: 30px;
19
  }
 
 
20
  .stat-card { background: white; padding: 20px; border-radius: 15px; text-align: center; border-top: 5px solid #004d57; box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
21
+ .day-container { background-color: white !important; padding: 30px; border-radius: 25px; margin-bottom: 40px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); }
 
 
 
 
 
 
 
22
  .day-header { color: #004d57; font-size: 26px; font-weight: bold; margin-bottom: 20px; border-bottom: 2px solid #f0f2f6; padding-bottom: 15px; }
 
23
  .item-row { display: flex; align-items: center; justify-content: space-between; padding: 18px 0; border-bottom: 1px solid #f1f1f1; }
24
  .item-row:last-child { border-bottom: none; }
25
+ .ex-name { flex: 2; font-weight: 600; color: #2d3436; font-size: 18px; }
 
26
  .stat-group { display: flex; gap: 15px; flex: 1.5; justify-content: flex-end; }
27
  .stat-pill { text-align: center; min-width: 75px; background: #f8f9fa; padding: 6px; border-radius: 12px; }
28
+ .stat-val { color: #004d57; font-weight: bold; font-size: 15px; display: block; }
29
+ .stat-label { font-size: 10px; color: #636e72; text-transform: uppercase; display: block; }
30
  </style>
31
  """, unsafe_allow_html=True)
32
 
33
+ # --- NAVIGATION STATE ---
 
34
  if 'page' not in st.session_state: st.session_state.page = 'dashboard'
35
  if 'user_data' not in st.session_state: st.session_state.user_data = None
36
  if 'workout_plan' not in st.session_state: st.session_state.workout_plan = None
37
  if 'diet_plan' not in st.session_state: st.session_state.diet_plan = None
38
 
39
+ # --- SIDEBAR ---
40
+ with st.sidebar:
41
+ st.markdown("# πŸ‘€ FitPlan AI")
42
+ if st.button("πŸ“Š Dashboard", use_container_width=True): st.session_state.page = 'dashboard'; st.rerun()
43
+ if st.button("πŸ‹οΈ Workout Plan", use_container_width=True): st.session_state.page = 'input'; st.rerun()
44
+ if st.button("πŸ₯— Dietary Plan", use_container_width=True): st.session_state.page = 'diet'; st.rerun()
 
 
 
 
 
 
45
 
46
+ # --- 1. DASHBOARD PAGE ---
47
+ if st.session_state.page == 'dashboard':
48
+ st.title("πŸ“Š Your Dashboard")
49
+ if st.session_state.user_data:
50
+ d = st.session_state.user_data
51
+ col1, col2, col3 = st.columns(3)
52
+ with col1: st.markdown(f'<div class="stat-card"><div style="font-size:24px; font-weight:bold;">{d["name"]}</div><div style="color:#636e72;">USER</div></div>', unsafe_allow_html=True)
53
+ with col2: st.markdown(f'<div class="stat-card"><div style="font-size:24px; font-weight:bold;">{d["bmi"]:.1f}</div><div style="color:#636e72;">BMI</div></div>', unsafe_allow_html=True)
54
+ with col3: st.markdown(f'<div class="stat-card"><div style="font-size:24px; font-weight:bold; color:{d["color"]}">{d["status"]}</div><div style="color:#636e72;">HEALTH STATUS</div></div>', unsafe_allow_html=True)
55
+
56
  st.write("---")
57
+ st.subheader("Current Focus")
58
+ st.info(f"Targeting: **{d['goal']}** at **{d['level']}** intensity.")
59
+ else:
60
+ st.warning("No data found. Please go to 'Workout Plan' and generate your profile.")
 
 
 
 
 
 
 
 
 
 
61
 
62
+ # --- 2. INPUT PAGE (Your Original Logic) ---
63
+ elif st.session_state.page == 'input':
64
+ st.title("πŸ‹οΈ Fitness Profile")
65
+ c1, c2, c3 = st.columns([2, 1, 1])
66
+ with c1: name = st.text_input("Name")
67
+ with c2: gender = st.selectbox("Gender", ["Male", "Female", "Other"])
68
+ with c3: age = st.number_input("Age", min_value=1, value=19)
69
+ h, w = st.columns(2)
70
+ with h: height = st.number_input("Height (cm)", min_value=1.0)
71
+ with w: weight = st.number_input("Weight (kg)", min_value=1.0)
72
+ goal = st.selectbox("Goal", ["Build Muscle", "Weight Loss", "Strength", "Flexibility"])
73
+ level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
74
+ equip = st.multiselect("Equipment", ["Dumbbells", "Kettlebells", "Pull-up Bar", "Resistance Bands", "Yoga Mat", "No Equipment"])
75
 
76
+ if st.button("Generate Complete Plan"):
77
+ prompt, bmi, status, color = build_prompt(name, gender, age, height, weight, goal, level, equip)
78
+ with st.spinner("AI is crafting your routine..."):
79
+ st.session_state.workout_plan = query_model(prompt)
80
+ st.session_state.user_data = {"name": name, "bmi": bmi, "status": status, "color": color, "age": age, "gender": gender, "goal": goal, "height": height, "weight": weight, "level": level}
81
+ st.session_state.diet_plan = None # Reset diet so it generates fresh for this user
82
+ st.session_state.page = 'result'
83
+ st.rerun()
84
 
85
+ # --- 3. WORKOUT RESULT (Preserving your exact Row/Pill layout) ---
86
+ elif st.session_state.page == 'result':
87
+ d = st.session_state.user_data
88
+ st.markdown(f'<div class="assessment-card"><h2>Hello {d["name"]}</h2><p>BMI: <strong>{d["bmi"]:.2f}</strong> | <span style="color:{d["color"]}">{d["status"]}</span></p></div>', unsafe_allow_html=True)
89
+
90
+ raw = st.session_state.workout_plan
91
+ days = ["Day 1:", "Day 2:", "Day 3:", "Day 4:", "Day 5:"]
92
+ for i in range(len(days)):
93
+ start = raw.find(days[i])
94
+ if start != -1:
95
+ end = raw.find(days[i+1]) if i+1 < len(days) else len(raw)
96
+ day_text = raw[start:end].strip()
97
+ st.markdown(f'<div class="day-container"><div class="day-header">πŸ”· {days[i][:-1]}</div>', unsafe_allow_html=True)
98
+ for line in day_text.split("\n"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  if "|" in line:
100
  parts = [p.strip() for p in line.replace("- ", "").split("|")]
101
  if len(parts) == 4:
102
+ n, s, r, rs = parts
103
+ st.markdown(f'<div class="item-row"><div class="ex-name">πŸ”₯ {n}</div><div class="stat-group"><div class="stat-pill"><span class="stat-val">{s}</span><span class="stat-label">Sets</span></div><div class="stat-pill"><span class="stat-val">{r}</span><span class="stat-label">Reps</span></div><div class="stat-pill" style="background:#fff3e0;"><span class="stat-val" style="color:#e65100;">{rs}</span><span class="stat-label">Rest</span></div></div></div>', unsafe_allow_html=True)
104
  st.markdown('</div>', unsafe_allow_html=True)
105
+ st.download_button("πŸ“₯ Download Plan", data=raw, file_name=f"{d['name']}_Plan.txt")
106
+
107
+ # --- 4. DIETARY PAGE (Now Functional) ---
108
+ elif st.session_state.page == 'diet':
109
+ st.title("πŸ₯— Dietary Plan")
110
+ if st.session_state.user_data:
111
+ d = st.session_state.user_data
112
+ if not st.session_state.diet_plan:
113
+ d_prompt = build_diet_prompt(d['name'], d['gender'], d['age'], d['height'], d['weight'], d['goal'])
114
+ with st.spinner("Generating unique meal plan..."):
115
+ st.session_state.diet_plan = query_model(d_prompt)
116
+
117
+ raw_diet = st.session_state.diet_plan
118
+ st.markdown('<div class="day-container"><div class="day-header">🍏 Daily Nutrition</div>', unsafe_allow_html=True)
119
+ for line in raw_diet.split("\n"):
120
+ if "|" in line:
121
+ parts = [p.strip() for p in line.replace("- ", "").split("|")]
122
+ if len(parts) == 4:
123
+ m_n, m_t, m_i, m_c = parts
124
+ st.markdown(f'<div class="item-row"><div class="ex-name">🍴 {m_n}<br><small>{m_i}</small></div><div class="stat-group"><div class="stat-pill"><span class="stat-val">{m_t}</span><span class="stat-label">Time</span></div><div class="stat-pill" style="background:#e8f5e9;"><span class="stat-val" style="color:#2e7d32;">{m_c}</span><span class="stat-label">Energy</span></div></div></div>', unsafe_allow_html=True)
125
+ st.markdown('</div>', unsafe_allow_html=True)
126
+ if st.button("Refresh Meals"): st.session_state.diet_plan = None; st.rerun()
127
+ else:
128
+ st.warning("Generate a profile in 'Workout Plan' first.")