Sreehitha-V commited on
Commit
bc846e4
Β·
verified Β·
1 Parent(s): 98e5a05

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +221 -135
app.py CHANGED
@@ -1,12 +1,11 @@
1
  import streamlit as st
2
- import streamlit.components.v1 as components
3
  import json
4
  import hashlib
5
  import re
6
  from prompt_builder import build_prompt
7
  from model_api import query_model
8
 
9
- # ================= PAGE CONFIG =================
10
  st.set_page_config(page_title="FitPlan Pro", layout="wide", initial_sidebar_state="collapsed")
11
 
12
  # ================= USER DATABASE =================
@@ -29,169 +28,256 @@ def hash_password(password):
29
  # ================= SESSION STATE =================
30
  if "logged_in" not in st.session_state:
31
  st.session_state.logged_in = False
32
- if "auth_mode" not in st.session_state:
33
- st.session_state.auth_mode = "login"
34
 
35
- # ================= AUTHENTICATION UI =================
36
- def show_auth_page():
37
- # Hide Streamlit UI for full-screen professional look
38
  st.markdown("""
39
- <style>
40
- header, footer, [data-testid="stToolbar"] {visibility: hidden;}
41
- .block-container { padding: 0 !important; margin: 0 !important; max-width: 100% !important; }
42
- iframe { display: block; width: 100vw; height: 100vh; border: none; }
43
- </style>
44
- """, unsafe_allow_html=True)
45
-
46
- is_login = st.session_state.auth_mode == "login"
47
-
48
- # YOUR EXACT UI INTEGRATED WITH WORKING JS
49
- auth_html = f"""
50
- <!DOCTYPE html>
51
- <html lang="en">
52
- <head>
53
- <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
54
  <style>
55
- *{{ margin:0; padding:0; box-sizing:border-box; font-family:'Poppins',sans-serif; }}
56
- body{{ height:100vh; display:flex; justify-content:center; align-items:center; background:#e5e5e5; overflow:hidden; }}
57
- .container{{ width:1100px; height:650px; background:white; border-radius:25px; display:flex; overflow:hidden; box-shadow:0 25px 70px rgba(0,0,0,.25); }}
58
- .left{{ width:50%; padding:55px; color:white; display:flex; flex-direction:column; justify-content:space-between;
59
- background: linear-gradient(rgba(165,0,0,.75),rgba(120,0,0,.92)), url("https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?auto=format&fit=crop&w=1470&q=80");
60
- background-size:cover; background-position:center; }}
61
- .logo{{ display:flex; align-items:center; gap:12px; }}
62
- .logo-icon{{ width:40px; height:40px; border-radius:50%; background:rgba(255,255,255,.25); display:flex; align-items:center; justify-content:center; font-size:18px; }}
63
- .bigtext{{ margin-top:30px; font-size:42px; font-weight:800; line-height:1.1; }}
64
- .stats{{ margin-top:30px; display:flex; gap:15px; }}
65
- .card{{ background:rgba(255,255,255,.15); padding:15px; border-radius:15px; text-align:center; width:120px; }}
66
- .right{{ width:50%; padding:50px 60px; display:flex; flex-direction:column; justify-content:center; }}
67
- .right h1{{ color:#D2042D; font-size:38px; font-weight:800; }}
68
- label{{ font-size:13px; font-weight:700; color:#333; display:block; margin-top:15px; }}
69
- .inputbox input{{ width:100%; padding:12px 15px; border-radius:10px; border:1px solid #ddd; outline:none; font-size:14px; margin-top:6px; }}
70
- .buttons{{ display:flex; gap:12px; margin-top:30px; }}
71
- .btn{{ flex:1; padding:14px; border-radius:30px; font-size:14px; font-weight:700; cursor:pointer; border:none; transition:0.3s; }}
72
- .login-btn{{ background:#D2042D; color:white; }}
73
- .signup-btn{{ background:transparent; border:1.5px solid #D2042D; color:#D2042D; }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  </style>
75
- </head>
76
- <body>
77
- <div class="container">
78
- <div class="left">
79
- <div>
80
- <div class="logo">
81
- <div class="logo-icon">πŸ‹οΈ</div>
82
- <div style="font-weight:700; font-size:18px;">FitPlan Pro</div>
 
 
 
 
 
83
  </div>
84
- <div class="bigtext">YOUR PERSONALIZED<br>FITNESS JOURNEY<br>STARTS HERE.</div>
85
- <div class="stats">
86
- <div class="card"><h2>12K+</h2><p style="font-size:10px;">MEMBERS</p></div>
87
- <div class="card"><h2>94%</h2><p style="font-size:10px;">SUCCESS</p></div>
88
  </div>
89
  </div>
90
- </div>
91
- <div class="right">
92
- <h1>{'WELCOME BACK!' if is_login else 'GET STARTED'}</h1>
93
- <p style="font-weight:600; font-size:13px; color:#555;">{'LOGIN TO YOUR ACCOUNT.' if is_login else 'CREATE YOUR NEW ACCOUNT.'}</p>
94
-
95
- <label>Email Address</label>
96
- <div class="inputbox"><input type="email" id="email" placeholder="Enter your email"></div>
97
- <label>Password</label>
98
- <div class="inputbox"><input type="password" id="pass" placeholder="Enter your password"></div>
99
-
100
- <div class="buttons">
101
- <button class="btn login-btn" onclick="sendAction('submit')">{'LOGIN β†’' if is_login else 'REGISTER'}</button>
102
- <button class="btn signup-btn" onclick="sendAction('toggle')">{'SIGN UP' if is_login else 'BACK TO LOGIN'}</button>
103
- </div>
104
- </div>
105
- </div>
106
-
107
- <script>
108
- function sendAction(action) {{
109
- const email = document.getElementById('email').value;
110
- const pass = document.getElementById('pass').value;
111
- // The magic bridge: pushing data to parent URL
112
- const url = new URL(window.parent.location.href);
113
- url.searchParams.set('auth_action', action);
114
- url.searchParams.set('u', email);
115
- url.searchParams.set('p', pass);
116
- url.searchParams.set('ts', Date.now()); // forces detection
117
- window.parent.location.href = url.href;
118
- }}
119
- </script>
120
- </body>
121
- </html>
122
- """
123
-
124
- components.html(auth_html, height=720)
125
-
126
- # PROCESS THE PUSHED DATA FROM THE BUTTONS
127
- params = st.query_params
128
- if "auth_action" in params:
129
- action = params["auth_action"]
130
- email, password = params.get("u"), params.get("p")
131
-
132
- if action == "toggle":
133
- st.session_state.auth_mode = "signup" if is_login else "login"
134
- st.query_params.clear()
135
- st.rerun()
136
-
137
- elif action == "submit":
138
- users = load_users()
139
- if is_login:
140
  if email in users and users[email] == hash_password(password):
141
  st.session_state.logged_in = True
142
- st.query_params.clear()
143
  st.rerun()
144
  else:
145
- st.error("Invalid Credentials! Please Sign Up if you are new.")
146
- st.query_params.clear()
147
- else:
148
- if email and password:
149
- users[email] = hash_password(password)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  save_users(users)
151
- st.success("Account Created! You can now log in.")
152
- st.session_state.auth_mode = "login"
153
- st.query_params.clear()
154
  st.rerun()
155
 
156
- # ================= DASHBOARD (EXACTLY YOUR CODE) =================
 
 
 
 
 
 
157
  def dashboard():
 
158
  st.markdown("""
159
  <style>
160
  .stApp {
161
  background: linear-gradient(rgba(0,0,0,0.9), rgba(0,0,0,0.9)),
162
  url("https://images.unsplash.com/photo-1534438327276-14e5300c3a48?q=80&w=2070");
163
- background-size: cover; background-position: center; background-attachment: fixed;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  }
165
- h1, h2, h3, label, p, span { color: #FFFFFF !important; font-weight: 700 !important; text-transform: uppercase; }
166
- div.stButton > button { width: 100% !important; background-color: #e60000 !important; color: white !important; font-weight: 900 !important; height: 50px !important; border-radius: 10px !important; }
167
- .workout-container { background: rgba(255, 255, 255, 0.05); padding: 20px; border-radius: 10px; border-left: 5px solid #FFFFFF; color: #FFFFFF; }
168
  </style>
169
  """, unsafe_allow_html=True)
170
 
171
- st.title("πŸ‹οΈ YOUR FITNESS DASHBOARD")
172
- if st.sidebar.button("LOGOUT"):
173
- st.session_state.logged_in = False
174
- st.rerun()
 
 
 
 
 
 
175
 
176
- tab1, tab2 = st.tabs(["πŸ“ PROFILE", "πŸ† WORKOUT"])
177
  with tab1:
178
- name = st.text_input("NAME")
179
  col1, col2 = st.columns(2)
180
- with col1: height = st.number_input("HEIGHT (CM)", value=170.0)
181
- with col2: weight = st.number_input("WEIGHT (KG)", value=70.0)
182
-
183
- if st.button("GENERATE PLAN"):
184
- with st.spinner("AI is thinking..."):
185
- prompt, bmi, status = build_prompt(name, "Male", height, weight, "Build Muscle", "Beginner", [], 25)
186
- raw_res = query_model(prompt)
187
- st.session_state.workout_plan = re.sub(r'\*', '', raw_res).strip()
188
- st.session_state.bmi_info = f"BMI: {bmi:.2f} | {status}"
189
- st.rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
 
191
  with tab2:
192
- if "workout_plan" in st.session_state:
193
- st.info(st.session_state.bmi_info)
 
 
194
  st.markdown(f'<div class="workout-container">{st.session_state.workout_plan}</div>', unsafe_allow_html=True)
 
 
195
 
196
  # ================= ROUTER =================
197
  if st.session_state.logged_in:
 
1
  import streamlit as st
 
2
  import json
3
  import hashlib
4
  import re
5
  from prompt_builder import build_prompt
6
  from model_api import query_model
7
 
8
+ # ================= PAGE CONFIG (ONLY ONCE) =================
9
  st.set_page_config(page_title="FitPlan Pro", layout="wide", initial_sidebar_state="collapsed")
10
 
11
  # ================= USER DATABASE =================
 
28
  # ================= SESSION STATE =================
29
  if "logged_in" not in st.session_state:
30
  st.session_state.logged_in = False
31
+ if "mode" not in st.session_state:
32
+ st.session_state.mode = "login"
33
 
34
+ # ================= LOGIN PAGE (UNCHANGED UI) =================
35
+ def apply_pro_styles():
 
36
  st.markdown("""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  <style>
38
+ header, footer, [data-testid="stToolbar"] {visibility: hidden;}
39
+ .block-container { padding: 0 !important; margin: 0 !important; max-width: 100% !important; }
40
+ section.main { padding: 0 !important; }
41
+ .stApp { background-color: white !important; height: 100vh !important; width: 100vw; overflow-y: auto; }
42
+
43
+ .left-panel {
44
+ flex: 1.2;
45
+ background: linear-gradient(rgba(139, 0, 0, 0.75), rgba(139, 0, 0, 0.85)),
46
+ url("https://images.unsplash.com/photo-1534438327276-14e5300c3a48?q=80&w=2070");
47
+ background-size: cover;
48
+ background-position: center;
49
+ display: flex;
50
+ flex-direction: column;
51
+ justify-content: space-between;
52
+ padding: 5% 5%;
53
+ color: white;
54
+ height: 100vh;
55
+ }
56
+
57
+ .hero-text {
58
+ font-size: 3.5rem;
59
+ font-weight: 800;
60
+ line-height: 1.1;
61
+ text-transform: uppercase;
62
+ margin: 30px 0;
63
+ }
64
+
65
+ .stat-row { display: flex; gap: 15px; }
66
+
67
+ .stat-card {
68
+ background: rgba(255, 255, 255, 0.1);
69
+ backdrop-filter: blur(10px);
70
+ padding: 15px;
71
+ border-radius: 10px;
72
+ flex: 1;
73
+ text-align: center;
74
+ }
75
+
76
+ .form-content { width: 100%; max-width: 400px; }
77
+
78
+ h1 { color: #D2042D !important; font-weight: 800 !important; font-size: 2.8rem !important; margin:0 !important;}
79
+ p.sub { color: #333 !important; margin-bottom: 20px; font-weight: 700; font-size: 1rem;}
80
+ label { color: black !important; font-weight: 700 !important; font-size: 0.85rem !important; }
81
+
82
+ div[data-baseweb="input"] {
83
+ border-radius: 8px !important;
84
+ border: 1.5px solid #eee !important;
85
+ }
86
+
87
+ div[data-baseweb="input"] input {
88
+ background-color: #2b2d3a !important;
89
+ color: white !important;
90
+ }
91
+
92
+ div[data-baseweb="input"] input::placeholder {
93
+ color: #cccccc !important;
94
+ }
95
+
96
+ div[data-testid="stCheckbox"] label,
97
+ div[data-testid="stCheckbox"] label p {
98
+ color: black !important;
99
+ font-weight: 700 !important;
100
+ }
101
+
102
+ div.stButton > button {
103
+ background: #D2042D !important;
104
+ color: white !important;
105
+ border-radius: 50px !important;
106
+ height: 48px !important;
107
+ width: 100%;
108
+ font-weight: 700 !important;
109
+ border: none !important;
110
+ }
111
  </style>
112
+ """, unsafe_allow_html=True)
113
+
114
+ def show_auth_page():
115
+ apply_pro_styles()
116
+ l_col, r_col = st.columns([1.2, 1])
117
+
118
+ with l_col:
119
+ st.markdown("""
120
+ <div class="left-panel">
121
+ <div>
122
+ <h3>πŸ‹οΈ FitPlan Pro</h3>
123
+ <p>PERSONALIZED FITNESS</p>
124
+ <div class="hero-text">Your Personalized<br>Fitness Journey<br>Starts Here.</div>
125
  </div>
126
+ <div class="stat-row">
127
+ <div class="stat-card"><b>12K+</b><br><small>ACTIVE MEMBERS</small></div>
128
+ <div class="stat-card"><b>5K+</b><br><small>CUSTOM PLANS</small></div>
129
+ <div class="stat-card"><b>94%</b><br><small>SUCCESS RATE</small></div>
130
  </div>
131
  </div>
132
+ """, unsafe_allow_html=True)
133
+
134
+ with r_col:
135
+ st.markdown('<div class="form-content">', unsafe_allow_html=True)
136
+
137
+ if st.session_state.mode == "login":
138
+ st.markdown('<h1>WELCOME BACK!</h1>', unsafe_allow_html=True)
139
+ st.markdown('<p class="sub">LOGIN TO YOUR ACCOUNT.</p>', unsafe_allow_html=True)
140
+
141
+ email = st.text_input("EMAIL ADDRESS", key="l_email", placeholder="Enter your email")
142
+ password = st.text_input("PASSWORD", type="password", key="l_pass", placeholder="Enter your password")
143
+ st.checkbox("Remember me", value=True)
144
+
145
+ if st.button("LOGIN β†’"):
146
+ users = load_users()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  if email in users and users[email] == hash_password(password):
148
  st.session_state.logged_in = True
 
149
  st.rerun()
150
  else:
151
+ st.error("Invalid Details")
152
+
153
+ st.markdown("<div style='margin-top:30px;'></div>", unsafe_allow_html=True)
154
+
155
+ st.markdown("<div style='color:black; font-weight:700; font-size:14px; margin-bottom:15px;'>Don't have an account?</div>", unsafe_allow_html=True)
156
+
157
+ if st.button("SIGN UP FREE"):
158
+ st.session_state.mode = "signup"
159
+ st.rerun()
160
+
161
+ else:
162
+ st.markdown('<h1>GET STARTED</h1>', unsafe_allow_html=True)
163
+ st.markdown('<p class="sub">CREATE YOUR NEW ACCOUNT.</p>', unsafe_allow_html=True)
164
+
165
+ new_email = st.text_input("EMAIL", key="s_email")
166
+ new_pass = st.text_input("PASSWORD", type="password", key="s_pass")
167
+
168
+ if st.button("REGISTER"):
169
+ users = load_users()
170
+ if new_email and new_pass:
171
+ users[new_email] = hash_password(new_pass)
172
  save_users(users)
173
+ st.success("Account Created!")
174
+ st.session_state.mode = "login"
 
175
  st.rerun()
176
 
177
+ if st.button("BACK TO LOGIN"):
178
+ st.session_state.mode = "login"
179
+ st.rerun()
180
+
181
+ st.markdown('</div>', unsafe_allow_html=True)
182
+
183
+ # ================= DASHBOARD (EXACTLY YOUR ORIGINAL CODE) =================
184
  def dashboard():
185
+
186
  st.markdown("""
187
  <style>
188
  .stApp {
189
  background: linear-gradient(rgba(0,0,0,0.9), rgba(0,0,0,0.9)),
190
  url("https://images.unsplash.com/photo-1534438327276-14e5300c3a48?q=80&w=2070");
191
+ background-size: cover;
192
+ background-position: center;
193
+ background-attachment: fixed;
194
+ }
195
+
196
+ h1, h2, h3, label, p, span {
197
+ color: #FFFFFF !important;
198
+ font-weight: 700 !important;
199
+ text-transform: uppercase;
200
+ }
201
+
202
+ div.stButton > button:first-child {
203
+ width: 100% !important;
204
+ background-color: #000000 !important;
205
+ color: #FFFFFF !important;
206
+ font-weight: 900 !important;
207
+ font-size: 1.2rem !important;
208
+ height: 60px !important;
209
+ border: 2px solid #FFFFFF !important;
210
+ border-radius: 10px !important;
211
+ }
212
+
213
+ .stTabs [aria-selected="true"] { background-color: #FFFFFF !important; }
214
+ .stTabs [aria-selected="true"] p { color: #000000 !important; }
215
+
216
+ .workout-container {
217
+ background: rgba(255, 255, 255, 0.05);
218
+ padding: 20px;
219
+ border-radius: 10px;
220
+ border-left: 5px solid #FFFFFF;
221
+ color: #FFFFFF;
222
+ line-height: 1.3 !important;
223
+ font-size: 1rem;
224
  }
 
 
 
225
  </style>
226
  """, unsafe_allow_html=True)
227
 
228
+ if 'workout_plan' not in st.session_state:
229
+ st.session_state.workout_plan = ""
230
+ if 'bmi_info' not in st.session_state:
231
+ st.session_state.bmi_info = ""
232
+ if 'user_name' not in st.session_state:
233
+ st.session_state.user_name = ""
234
+
235
+ st.title("πŸ‹οΈ PERSONALIZED FITPLAN")
236
+
237
+ tab1, tab2 = st.tabs(["πŸ“ ATHLETE PROFILE", "πŸ† YOUR WORKOUT PLAN"])
238
 
 
239
  with tab1:
240
+ st.header("Build Your Profile")
241
  col1, col2 = st.columns(2)
242
+
243
+ with col1:
244
+ name = st.text_input("NAME (Required)")
245
+ gender = st.selectbox("GENDER", ["Male", "Female", "Other"])
246
+ height_cm = st.number_input("HEIGHT (CM)", min_value=1.0)
247
+
248
+ with col2:
249
+ age = st.number_input("AGE (Required)", min_value=1)
250
+ weight_kg = st.number_input("WEIGHT (KG)", min_value=1.0)
251
+ goal = st.selectbox("GOAL", ["Build Muscle", "Weight Loss", "Strength", "Abs", "Flexible"])
252
+
253
+ level = st.selectbox("LEVEL", ["Beginner", "Intermediate", "Advanced"])
254
+ equipment = st.multiselect("EQUIPMENT", ["Dumbbells", "Barbell", "Kettlebells", "Yoga Mat", "Pull-up Bar", "No Equipment"])
255
+
256
+ if st.button("SUBMIT PROFILE"):
257
+ if not name or height_cm <= 1 or weight_kg <= 1:
258
+ st.error("🚨 PLEASE FILL IN ALL FIELDS.")
259
+ else:
260
+ with st.spinner("GENERATING..."):
261
+ prompt, bmi, bmi_status = build_prompt(name, gender, height_cm, weight_kg, goal, level, equipment, age)
262
+ raw_output = query_model(prompt)
263
+
264
+ clean_text = re.sub(r'\*', '', raw_output)
265
+ clean_text = re.sub(r'\n{3,}', '\n\n', clean_text)
266
+ clean_text = clean_text.strip()
267
+
268
+ st.session_state.workout_plan = clean_text
269
+ st.session_state.bmi_info = f"BMI: {bmi:.2f} | {bmi_status.upper()}"
270
+ st.session_state.user_name = name.upper()
271
+ st.success("PROFILE SUBMITTED!")
272
 
273
  with tab2:
274
+ if st.session_state.workout_plan:
275
+ st.header(f"πŸ”₯ HELLO {st.session_state.user_name}!")
276
+ st.info(f"πŸ“Š {st.session_state.bmi_info}")
277
+ st.markdown("---")
278
  st.markdown(f'<div class="workout-container">{st.session_state.workout_plan}</div>', unsafe_allow_html=True)
279
+ else:
280
+ st.warning("PLEASE SUBMIT YOUR PROFILE FIRST.")
281
 
282
  # ================= ROUTER =================
283
  if st.session_state.logged_in: