Amrutha04 commited on
Commit
669337b
·
verified ·
1 Parent(s): dc59f38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -63
app.py CHANGED
@@ -4,83 +4,116 @@ from model_api import query_model
4
 
5
  st.set_page_config(page_title="FitPlan AI", layout="wide")
6
 
7
- # CSS to Hide Header and Center Login
8
  st.markdown("""
9
  <style>
10
- /* Hide the top Streamlit header and padding */
11
- header {visibility: hidden;}
12
- .main .block-container { padding-top: 0rem; }
13
 
14
- .stApp {
15
- background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
16
- background-attachment: fixed;
17
- }
18
-
19
- /* Perfect Centering for Login */
20
- .login-wrapper {
21
- display: flex;
22
- flex-direction: column;
23
- justify-content: center;
24
- align-items: center;
25
- height: 80vh; /* Centers vertically within view */
26
- }
27
-
28
- .login-box {
29
- background: white;
30
- padding: 50px;
31
- border-radius: 25px;
32
- box-shadow: 0 15px 35px rgba(0,0,0,0.15);
33
- width: 100%;
34
- max-width: 500px;
35
- text-align: center;
36
- }
37
-
38
- /* Unified Day Card Style */
39
- .day-container {
40
  background-color: white !important;
41
  padding: 30px;
42
- border-radius: 25px;
43
- margin-bottom: 35px;
44
- box-shadow: 0 10px 30px rgba(0,0,0,0.08);
45
  border-left: 12px solid #004d57;
46
  }
47
- .day-header { color: #004d57; font-size: 26px; font-weight: bold; border-bottom: 2px solid #f0f2f6; padding-bottom: 15px; margin-bottom: 20px; }
48
- .exercise-row { display: flex; justify-content: space-between; align-items: center; padding: 15px 0; border-bottom: 1px solid #f1f1f1; }
49
- .stat-pill { background: #f8f9fa; padding: 6px 12px; border-radius: 12px; text-align: center; min-width: 80px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  </style>
51
  """, unsafe_allow_html=True)
52
 
53
- if 'logged_in' not in st.session_state: st.session_state.logged_in = False
54
  if 'page' not in st.session_state: st.session_state.page = 'input'
 
55
 
56
- # --- LOGIN PAGE ---
57
- if not st.session_state.logged_in:
58
- # Use a div wrapper to apply the flexbox centering
59
- st.markdown('<div class="login-wrapper">', unsafe_allow_html=True)
60
- st.markdown('<div class="login-box">', unsafe_allow_html=True)
61
- st.title("🏋️ FitPlan AI Login")
62
- email_input = st.text_input("Email Address", placeholder="example@email.com")
63
-
64
- if st.button("Login", use_container_width=True):
65
- if "@" in email_input and "." in email_input:
66
- st.session_state.logged_in = True
67
  st.rerun()
68
- else:
69
- st.error("Please enter a valid email.")
70
- st.markdown('</div></div>', unsafe_allow_html=True)
71
 
72
- # --- PROTECTED GENERATOR PAGE ---
73
- else:
74
- if st.session_state.page == 'input':
75
- st.title("🚀 Fitness Plan Generator")
76
- # Your Profile Input Form here...
77
- # [Profile inputs like Name, Age, Height, etc.]
78
- if st.button("Generate Plan"):
79
- # build_prompt and query_model logic here
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  st.session_state.page = 'result'
81
  st.rerun()
82
 
83
- elif st.session_state.page == 'result':
84
- # Result Page with Unified Day Cards
85
- st.title("📋 Your Personalized Routine")
86
- # Loop through workout_plan and display using .day-container
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  st.set_page_config(page_title="FitPlan AI", layout="wide")
6
 
7
+ # Updated CSS for Single Box Per Day
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
+ /* Main Card for the Day */
15
+ .day-card {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  background-color: white !important;
17
  padding: 30px;
18
+ border-radius: 20px;
19
+ margin-bottom: 40px;
20
+ box-shadow: 0 8px 24px rgba(0,0,0,0.1);
21
  border-left: 12px solid #004d57;
22
  }
23
+
24
+ .day-title { color: #004d57; font-size: 28px; font-weight: bold; margin-bottom: 25px; border-bottom: 2px solid #f0f0f0; padding-bottom: 10px; }
25
+
26
+ /* Exercise Row - No border/shadow to keep it inside the single box */
27
+ .exercise-row {
28
+ display: flex;
29
+ align-items: center;
30
+ justify-content: space-between;
31
+ padding: 15px 0;
32
+ border-bottom: 1px solid #eee;
33
+ }
34
+ .exercise-row:last-child { border-bottom: none; }
35
+
36
+ .ex-name { flex: 2; font-weight: 600; color: #2d3436; font-size: 18px; }
37
+ .stat-container { display: flex; gap: 20px; flex: 1.5; justify-content: flex-end; }
38
+ .stat-box { text-align: center; min-width: 70px; }
39
+ .stat-val { background: #e0f2f1; color: #004d57; padding: 4px 12px; border-radius: 12px; font-weight: bold; display: block; }
40
+ .stat-label { font-size: 10px; color: #636e72; text-transform: uppercase; margin-top: 4px; display: block; }
41
  </style>
42
  """, unsafe_allow_html=True)
43
 
 
44
  if 'page' not in st.session_state: st.session_state.page = 'input'
45
+ if 'workout_plan' not in st.session_state: st.session_state.workout_plan = None
46
 
47
+ # --- SIDEBAR ---
48
+ with st.sidebar:
49
+ st.markdown("# 👤 Personalised Fitness Plan")
50
+ if st.session_state.page == 'result':
51
+ if st.button("⬅️ New Profile"):
52
+ st.session_state.page = 'input'
 
 
 
 
 
53
  st.rerun()
 
 
 
54
 
55
+ # --- PAGE 1: INPUT ---
56
+ if st.session_state.page == 'input':
57
+ st.title("🏋️ Create Your Fitness Profile")
58
+ col1, col2, col3 = st.columns([2, 1, 1])
59
+ with col1: name = st.text_input("Name")
60
+ with col2: gender = st.selectbox("Gender", ["Male", "Female", "Other"])
61
+ with col3: age = st.number_input("Age", min_value=1, value=19)
62
+
63
+ h, w = st.columns(2)
64
+ with h: height = st.number_input("Height (cm)", min_value=1.0)
65
+ with w: weight = st.number_input("Weight (kg)", min_value=1.0)
66
+
67
+ goal = st.selectbox("Goal", ["Build Muscle", "Weight Loss", "Strength", "Flexibility"])
68
+ level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
69
+ equip = st.multiselect("Equipment", ["Dumbbells", "Kettlebells", "Pull-up Bar", "Resistance Bands", "Yoga Mat", "No Equipment"])
70
+
71
+ if st.button("Submit Profile"):
72
+ prompt, bmi, bmi_status, status_color = build_prompt(name, gender, age, height, weight, goal, level, equip)
73
+ with st.spinner("Building your single-box workout plan..."):
74
+ raw_workout = query_model(prompt)
75
+ st.session_state.workout_plan = raw_workout
76
+ st.session_state.assessment_data = {"name": name, "bmi": bmi, "status": bmi_status, "color": status_color, "age": age, "gender": gender}
77
  st.session_state.page = 'result'
78
  st.rerun()
79
 
80
+ # --- PAGE 2: RESULTS ---
81
+ elif st.session_state.page == 'result':
82
+ d = st.session_state.assessment_data
83
+ st.markdown(f'<div class="result-card"><h2>Assessment for {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)
84
+
85
+ raw_content = st.session_state.workout_plan
86
+ days = ["Day 1:", "Day 2:", "Day 3:", "Day 4:", "Day 5:"]
87
+
88
+ for i in range(len(days)):
89
+ start = raw_content.find(days[i])
90
+ if start != -1:
91
+ end = raw_content.find(days[i+1]) if i+1 < len(days) else len(raw_content)
92
+ day_block = raw_content[start:end].strip()
93
+
94
+ # Start of Single White Box for the Day
95
+ st.markdown(f'<div class="day-card"><div class="day-title">💠 {days[i][:-1]}</div>', unsafe_allow_html=True)
96
+
97
+ lines = day_block.split("\n")
98
+ for line in lines:
99
+ if "|" in line:
100
+ parts = [p.strip() for p in line.replace("- ", "").split("|")]
101
+ if len(parts) == 4:
102
+ ex_name, sets, reps, rest = parts
103
+ st.markdown(f"""
104
+ <div class="exercise-row">
105
+ <div class="ex-name">🔥 {ex_name}</div>
106
+ <div class="stat-container">
107
+ <div class="stat-box"><span class="stat-val">{sets}</span><span class="stat-label">Sets</span></div>
108
+ <div class="stat-box"><span class="stat-val">{reps}</span><span class="stat-label">Reps</span></div>
109
+ <div class="stat-box"><span class="stat-val" style="background:#fff3e0;">{rest}</span><span class="stat-label">Rest</span></div>
110
+ </div>
111
+ </div>
112
+ """, unsafe_allow_html=True)
113
+
114
+ if "Rest Day" in day_block or "Recovery" in day_block:
115
+ st.info("🧘 Day 3: Active recovery and stretching.")
116
+
117
+ st.markdown('</div>', unsafe_allow_html=True) # End of Day Card
118
+
119
+ st.download_button("📥 Download Full Plan", data=raw_content, file_name=f"{d['name']}_Plan.txt")