Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,40 +4,63 @@ from model_api import query_model
|
|
| 4 |
|
| 5 |
st.set_page_config(page_title="FitPlan AI", layout="wide")
|
| 6 |
|
| 7 |
-
#
|
| 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 |
-
/*
|
| 15 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
background-color: white !important;
|
| 17 |
padding: 30px;
|
| 18 |
-
border-radius:
|
| 19 |
margin-bottom: 40px;
|
| 20 |
-
box-shadow: 0
|
| 21 |
-
border-left: 12px solid #004d57;
|
| 22 |
}
|
| 23 |
|
| 24 |
-
.day-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
/* Exercise
|
| 27 |
.exercise-row {
|
| 28 |
display: flex;
|
| 29 |
align-items: center;
|
| 30 |
justify-content: space-between;
|
| 31 |
-
padding:
|
| 32 |
-
border-bottom: 1px solid #
|
| 33 |
}
|
| 34 |
.exercise-row:last-child { border-bottom: none; }
|
| 35 |
|
| 36 |
-
.ex-name { flex: 2; font-weight: 600; color: #2d3436; font-size: 18px; }
|
| 37 |
-
|
| 38 |
-
.stat-
|
| 39 |
-
|
| 40 |
-
.stat-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
</style>
|
| 42 |
""", unsafe_allow_html=True)
|
| 43 |
|
|
@@ -48,13 +71,13 @@ if 'workout_plan' not in st.session_state: st.session_state.workout_plan = None
|
|
| 48 |
with st.sidebar:
|
| 49 |
st.markdown("# 👤 Personalised Fitness Plan")
|
| 50 |
if st.session_state.page == 'result':
|
| 51 |
-
if st.button("⬅️
|
| 52 |
st.session_state.page = 'input'
|
| 53 |
st.rerun()
|
| 54 |
|
| 55 |
-
# ---
|
| 56 |
if st.session_state.page == 'input':
|
| 57 |
-
st.title("🏋️
|
| 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"])
|
|
@@ -68,19 +91,19 @@ if st.session_state.page == 'input':
|
|
| 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("
|
| 72 |
prompt, bmi, bmi_status, status_color = build_prompt(name, gender, age, height, weight, goal, level, equip)
|
| 73 |
-
with st.spinner("
|
| 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
|
| 81 |
elif st.session_state.page == 'result':
|
| 82 |
d = st.session_state.assessment_data
|
| 83 |
-
st.markdown(f'<div class="
|
| 84 |
|
| 85 |
raw_content = st.session_state.workout_plan
|
| 86 |
days = ["Day 1:", "Day 2:", "Day 3:", "Day 4:", "Day 5:"]
|
|
@@ -89,12 +112,12 @@ elif st.session_state.page == 'result':
|
|
| 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 |
-
|
| 93 |
|
| 94 |
-
#
|
| 95 |
-
st.markdown(f'<div class="day-
|
| 96 |
|
| 97 |
-
lines =
|
| 98 |
for line in lines:
|
| 99 |
if "|" in line:
|
| 100 |
parts = [p.strip() for p in line.replace("- ", "").split("|")]
|
|
@@ -103,17 +126,17 @@ elif st.session_state.page == 'result':
|
|
| 103 |
st.markdown(f"""
|
| 104 |
<div class="exercise-row">
|
| 105 |
<div class="ex-name">🔥 {ex_name}</div>
|
| 106 |
-
<div class="stat-
|
| 107 |
-
<div class="stat-
|
| 108 |
-
<div class="stat-
|
| 109 |
-
<div class="stat-
|
| 110 |
</div>
|
| 111 |
</div>
|
| 112 |
""", unsafe_allow_html=True)
|
| 113 |
|
| 114 |
-
if "Rest
|
| 115 |
-
st.
|
| 116 |
|
| 117 |
-
st.markdown('</div>', unsafe_allow_html=True) #
|
| 118 |
|
| 119 |
-
st.download_button("📥 Download Full Plan", data=raw_content, file_name=f"{d['name']}
|
|
|
|
| 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 |
|
|
|
|
| 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")
|
| 83 |
with col2: gender = st.selectbox("Gender", ["Male", "Female", "Other"])
|
|
|
|
| 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:"]
|
|
|
|
| 112 |
start = raw_content.find(days[i])
|
| 113 |
if start != -1:
|
| 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("|")]
|
|
|
|
| 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")
|