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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +122 -115
app.py CHANGED
@@ -1,10 +1,11 @@
1
  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 | Dashboard", layout="wide")
6
 
7
- # Professional Dashboard & Card UI
8
  st.markdown("""
9
  <style>
10
  header {visibility: hidden;}
@@ -12,140 +13,146 @@ st.markdown("""
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")
97
- with col2: gender = st.selectbox("Gender", ["Male", "Female", "Other"])
98
- with col3: age = st.number_input("Age", min_value=1, value=19)
99
-
100
- h, w = st.columns(2)
101
- with h: height = st.number_input("Height (cm)", min_value=1.0)
102
- with w: weight = st.number_input("Weight (kg)", min_value=1.0)
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
-
123
- for i in range(len(days)):
124
- start = raw_content.find(days[i])
125
- if start != -1:
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!")
 
1
  import streamlit as st
2
  from prompt_builder import build_prompt
3
  from model_api import query_model
4
+ 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
  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.")