Amrutha04 commited on
Commit
dbf471f
Β·
verified Β·
1 Parent(s): fa8dbc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -70
app.py CHANGED
@@ -2,81 +2,95 @@ import streamlit as st
2
  from prompt_builder import build_prompt
3
  from model_api import query_model
4
 
5
- st.set_page_config(page_title="FitPlan AI", layout="wide")
6
 
7
- # Optimized CSS for Unified Daily Cards
8
  st.markdown("""
9
  <style>
 
10
  .stApp { background: linear-gradient(135deg, #f6d365 0%, #fda085 100%); background-attachment: fixed; }
11
  section[data-testid="stSidebar"] { background-color: #000000 !important; }
12
  section[data-testid="stSidebar"] h1, section[data-testid="stSidebar"] p { color: #FFFFFF !important; }
13
 
14
- /* Assessment Card */
15
- .assessment-card {
16
- background-color: white !important; padding: 25px; border-radius: 15px;
17
- border-left: 10px solid #004d57; color: #000000 !important; margin-bottom: 30px;
 
 
 
 
18
  }
 
 
19
 
20
- /* Single Unified White Box Per Day */
21
  .day-container {
22
- background-color: white !important;
23
- padding: 30px;
24
- border-radius: 25px;
25
- margin-bottom: 40px;
26
- box-shadow: 0 10px 30px rgba(0,0,0,0.1);
27
  }
28
-
29
  .day-header {
30
- color: #004d57;
31
- font-size: 26px;
32
- font-weight: bold;
33
- margin-bottom: 20px;
34
- display: flex;
35
- align-items: center;
36
- border-bottom: 2px solid #f0f2f6;
37
- padding-bottom: 15px;
38
  }
39
-
40
- /* Clean Exercise Rows inside the Unified Box */
41
  .exercise-row {
42
- display: flex;
43
- align-items: center;
44
- justify-content: space-between;
45
- padding: 18px 0;
46
- border-bottom: 1px solid #f1f1f1;
47
  }
48
  .exercise-row:last-child { border-bottom: none; }
49
-
50
- .ex-name { flex: 2; font-weight: 600; color: #2d3436; font-size: 18px; display: flex; align-items: center; }
51
-
52
  .stat-group { display: flex; gap: 15px; flex: 1.5; justify-content: flex-end; }
53
-
54
- .stat-pill {
55
- text-align: center;
56
- min-width: 75px;
57
- background: #f8f9fa;
58
- padding: 6px;
59
- border-radius: 12px;
60
- }
61
-
62
  .stat-val { color: #004d57; font-weight: bold; font-size: 15px; display: block; }
63
- .stat-label { font-size: 10px; color: #636e72; text-transform: uppercase; display: block; margin-top: 2px; }
64
  </style>
65
  """, unsafe_allow_html=True)
66
 
67
- if 'page' not in st.session_state: st.session_state.page = 'input'
 
68
  if 'workout_plan' not in st.session_state: st.session_state.workout_plan = None
 
69
 
70
- # --- SIDEBAR ---
71
  with st.sidebar:
72
- st.markdown("# πŸ‘€ Personalised Fitness Plan")
73
- if st.session_state.page == 'result':
74
- if st.button("⬅️ Back to Profile"):
75
- st.session_state.page = 'input'
76
- st.rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
- # --- INPUT PAGE ---
79
- if st.session_state.page == 'input':
80
  st.title("πŸ‹οΈ Fitness Profile")
81
  col1, col2, col3 = st.columns([2, 1, 1])
82
  with col1: name = st.text_input("Name")
@@ -89,22 +103,20 @@ if st.session_state.page == 'input':
89
 
90
  goal = st.selectbox("Goal", ["Build Muscle", "Weight Loss", "Strength", "Flexibility"])
91
  level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
92
- equip = st.multiselect("Equipment", ["Dumbbells", "Kettlebells", "Pull-up Bar", "Resistance Bands", "Yoga Mat", "No Equipment"])
93
 
94
  if st.button("Generate Plan"):
95
  prompt, bmi, bmi_status, status_color = build_prompt(name, gender, age, height, weight, goal, level, equip)
96
- with st.spinner("Crafting your unified routine..."):
97
  raw_workout = query_model(prompt)
98
  st.session_state.workout_plan = raw_workout
99
- st.session_state.assessment_data = {"name": name, "bmi": bmi, "status": bmi_status, "color": status_color, "age": age, "gender": gender}
100
  st.session_state.page = 'result'
101
  st.rerun()
102
 
103
- # --- RESULT PAGE ---
104
  elif st.session_state.page == 'result':
105
- d = st.session_state.assessment_data
106
- st.markdown(f'<div class="assessment-card"><h2>Hello {d["name"]}</h2><p>{d["gender"]} | {d["age"]} Years Old</p><p>BMI: <strong>{d["bmi"]:.2f}</strong> | <span style="color:{d["color"]}">{d["status"]}</span></p></div>', unsafe_allow_html=True)
107
-
108
  raw_content = st.session_state.workout_plan
109
  days = ["Day 1:", "Day 2:", "Day 3:", "Day 4:", "Day 5:"]
110
 
@@ -114,29 +126,26 @@ elif st.session_state.page == 'result':
114
  end = raw_content.find(days[i+1]) if i+1 < len(days) else len(raw_content)
115
  day_text = raw_content[start:end].strip()
116
 
117
- # Open Single White Day Container
118
  st.markdown(f'<div class="day-container"><div class="day-header">πŸ”· {days[i][:-1]}</div>', unsafe_allow_html=True)
119
-
120
  lines = day_text.split("\n")
121
  for line in lines:
122
  if "|" in line:
123
  parts = [p.strip() for p in line.replace("- ", "").split("|")]
124
  if len(parts) == 4:
125
- ex_name, sets, reps, rest = parts
126
  st.markdown(f"""
127
  <div class="exercise-row">
128
- <div class="ex-name">πŸ”₯ {ex_name}</div>
129
  <div class="stat-group">
130
- <div class="stat-pill"><span class="stat-val">{sets}</span><span class="stat-label">Sets</span></div>
131
- <div class="stat-pill"><span class="stat-val">{reps}</span><span class="stat-label">Reps</span></div>
132
- <div class="stat-pill" style="background:#fff3e0;"><span class="stat-val" style="color:#e65100;">{rest}</span><span class="stat-label">Rest</span></div>
133
  </div>
134
  </div>
135
  """, unsafe_allow_html=True)
136
-
137
- if "Rest" in day_text or "Recovery" in day_text:
138
- st.markdown('<p style="color:#636e72; font-style:italic; padding-top:10px;">🧘 Recovery Day: Focused on flexibility and rest.</p>', unsafe_allow_html=True)
139
-
140
- st.markdown('</div>', unsafe_allow_html=True) # Close Day Container
141
 
142
- st.download_button("πŸ“₯ Download Full Plan", data=raw_content, file_name=f"{d['name']}_Workout.txt")
 
 
 
 
2
  from prompt_builder import build_prompt
3
  from model_api import query_model
4
 
5
+ st.set_page_config(page_title="FitPlan AI | Dashboard", layout="wide")
6
 
7
+ # Professional Dashboard & Card UI
8
  st.markdown("""
9
  <style>
10
+ header {visibility: hidden;}
11
  .stApp { background: linear-gradient(135deg, #f6d365 0%, #fda085 100%); background-attachment: fixed; }
12
  section[data-testid="stSidebar"] { background-color: #000000 !important; }
13
  section[data-testid="stSidebar"] h1, section[data-testid="stSidebar"] p { color: #FFFFFF !important; }
14
 
15
+ /* Dashboard Stat Cards */
16
+ .stat-card {
17
+ background: white;
18
+ padding: 20px;
19
+ border-radius: 15px;
20
+ box-shadow: 0 4px 15px rgba(0,0,0,0.05);
21
+ text-align: center;
22
+ border-top: 5px solid #004d57;
23
  }
24
+ .stat-value { font-size: 24px; font-weight: bold; color: #004d57; }
25
+ .stat-label { font-size: 14px; color: #636e72; text-transform: uppercase; }
26
 
27
+ /* Unified Day Box Per Day */
28
  .day-container {
29
+ background-color: white !important; padding: 30px; border-radius: 25px;
30
+ margin-bottom: 40px; box-shadow: 0 10px 30px rgba(0,0,0,0.1);
 
 
 
31
  }
 
32
  .day-header {
33
+ color: #004d57; font-size: 26px; font-weight: bold; margin-bottom: 20px;
34
+ display: flex; align-items: center; border-bottom: 2px solid #f0f2f6; padding-bottom: 15px;
 
 
 
 
 
 
35
  }
 
 
36
  .exercise-row {
37
+ display: flex; align-items: center; justify-content: space-between;
38
+ padding: 18px 0; border-bottom: 1px solid #f1f1f1;
 
 
 
39
  }
40
  .exercise-row:last-child { border-bottom: none; }
41
+ .ex-name { flex: 2; font-weight: 600; color: #2d3436; font-size: 18px; }
 
 
42
  .stat-group { display: flex; gap: 15px; flex: 1.5; justify-content: flex-end; }
43
+ .stat-pill { text-align: center; min-width: 75px; background: #f8f9fa; padding: 6px; border-radius: 12px; }
 
 
 
 
 
 
 
 
44
  .stat-val { color: #004d57; font-weight: bold; font-size: 15px; display: block; }
45
+ .stat-label-inner { font-size: 10px; color: #636e72; text-transform: uppercase; display: block; }
46
  </style>
47
  """, unsafe_allow_html=True)
48
 
49
+ # Initialize Session States
50
+ if 'page' not in st.session_state: st.session_state.page = 'dashboard'
51
  if 'workout_plan' not in st.session_state: st.session_state.workout_plan = None
52
+ if 'user_data' not in st.session_state: st.session_state.user_data = None
53
 
54
+ # --- SIDEBAR NAVIGATION ---
55
  with st.sidebar:
56
+ st.markdown("# πŸ›‘οΈ FitPlan AI")
57
+ st.write("---")
58
+ if st.button("πŸ“Š My Dashboard", use_container_width=True):
59
+ st.session_state.page = 'dashboard'
60
+ st.rerun()
61
+ if st.button("πŸ‹οΈ Plan Generator", use_container_width=True):
62
+ st.session_state.page = 'input'
63
+ st.rerun()
64
+ if st.button("πŸ₯— Dietary Plan", use_container_width=True):
65
+ st.session_state.page = 'diet'
66
+ st.rerun()
67
+
68
+ # --- PAGE: DASHBOARD ---
69
+ if st.session_state.page == 'dashboard':
70
+ st.title("πŸ“Š Welcome Back!")
71
+
72
+ if st.session_state.user_data:
73
+ d = st.session_state.user_data
74
+ col1, col2, col3, col4 = st.columns(4)
75
+ with col1:
76
+ st.markdown(f'<div class="stat-card"><div class="stat-value">{d["name"]}</div><div class="stat-label">User</div></div>', unsafe_allow_html=True)
77
+ with col2:
78
+ st.markdown(f'<div class="stat-card"><div class="stat-value">{d["bmi"]:.1f}</div><div class="stat-label">Current BMI</div></div>', unsafe_allow_html=True)
79
+ with col3:
80
+ st.markdown(f'<div class="stat-card"><div class="stat-value" style="color:{d["color"]}">{d["status"]}</div><div class="stat-label">Health Status</div></div>', unsafe_allow_html=True)
81
+ with col4:
82
+ st.markdown(f'<div class="stat-card"><div class="stat-value">5 Days</div><div class="stat-label">Active Plan</div></div>', unsafe_allow_html=True)
83
+
84
+ st.write("### πŸ“… Quick Access")
85
+ if st.session_state.workout_plan:
86
+ st.success("Your workout plan is ready! Go to 'Plan Generator' to view it.")
87
+ else:
88
+ st.info("No active plan found. Click 'Plan Generator' in the sidebar to start.")
89
+ else:
90
+ st.warning("Please go to 'Plan Generator' to set up your profile first!")
91
 
92
+ # --- PAGE: INPUT / GENERATOR ---
93
+ elif st.session_state.page == 'input':
94
  st.title("πŸ‹οΈ Fitness Profile")
95
  col1, col2, col3 = st.columns([2, 1, 1])
96
  with col1: name = st.text_input("Name")
 
103
 
104
  goal = st.selectbox("Goal", ["Build Muscle", "Weight Loss", "Strength", "Flexibility"])
105
  level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
106
+ equip = st.multiselect("Equipment", ["Dumbbells", "Kettlebells", "Pull-up Bar", "No Equipment"])
107
 
108
  if st.button("Generate Plan"):
109
  prompt, bmi, bmi_status, status_color = build_prompt(name, gender, age, height, weight, goal, level, equip)
110
+ with st.spinner("Analyzing your profile..."):
111
  raw_workout = query_model(prompt)
112
  st.session_state.workout_plan = raw_workout
113
+ st.session_state.user_data = {"name": name, "bmi": bmi, "status": bmi_status, "color": status_color, "age": age, "gender": gender}
114
  st.session_state.page = 'result'
115
  st.rerun()
116
 
117
+ # --- PAGE: RESULT VIEW ---
118
  elif st.session_state.page == 'result':
119
+ st.title("πŸ“‹ Your Personalized Routine")
 
 
120
  raw_content = st.session_state.workout_plan
121
  days = ["Day 1:", "Day 2:", "Day 3:", "Day 4:", "Day 5:"]
122
 
 
126
  end = raw_content.find(days[i+1]) if i+1 < len(days) else len(raw_content)
127
  day_text = raw_content[start:end].strip()
128
 
 
129
  st.markdown(f'<div class="day-container"><div class="day-header">πŸ”· {days[i][:-1]}</div>', unsafe_allow_html=True)
 
130
  lines = day_text.split("\n")
131
  for line in lines:
132
  if "|" in line:
133
  parts = [p.strip() for p in line.replace("- ", "").split("|")]
134
  if len(parts) == 4:
135
+ n, s, r, rs = parts
136
  st.markdown(f"""
137
  <div class="exercise-row">
138
+ <div class="ex-name">πŸ”₯ {n}</div>
139
  <div class="stat-group">
140
+ <div class="stat-pill"><span class="stat-val">{s}</span><span class="stat-label-inner">Sets</span></div>
141
+ <div class="stat-pill"><span class="stat-val">{r}</span><span class="stat-label-inner">Reps</span></div>
142
+ <div class="stat-pill" style="background:#fff3e0;"><span class="stat-val" style="color:#e65100;">{rs}</span><span class="stat-label-inner">Rest</span></div>
143
  </div>
144
  </div>
145
  """, unsafe_allow_html=True)
146
+ st.markdown('</div>', unsafe_allow_html=True)
 
 
 
 
147
 
148
+ # --- PAGE: DIET ---
149
+ elif st.session_state.page == 'diet':
150
+ st.title("πŸ₯— Personalized Dietary Plan")
151
+ st.info("Coming Soon: AI-generated meal plans based on your workout intensity!")