Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 8 |
st.markdown("""
|
| 9 |
<style>
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 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:
|
| 43 |
-
margin-bottom:
|
| 44 |
-
box-shadow: 0
|
| 45 |
border-left: 12px solid #004d57;
|
| 46 |
}
|
| 47 |
-
|
| 48 |
-
.
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
# ---
|
| 57 |
-
|
| 58 |
-
#
|
| 59 |
-
st.
|
| 60 |
-
|
| 61 |
-
|
| 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 |
-
# ---
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
st.session_state.page = 'result'
|
| 81 |
st.rerun()
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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")
|