Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ from diet_builder import build_diet_prompt
|
|
| 5 |
|
| 6 |
st.set_page_config(page_title="FitPlan AI", layout="wide")
|
| 7 |
|
| 8 |
-
# ---
|
| 9 |
st.markdown("""
|
| 10 |
<style>
|
| 11 |
header {visibility: hidden;}
|
|
@@ -13,146 +13,116 @@ st.markdown("""
|
|
| 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 |
-
.
|
| 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 |
-
.
|
| 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 |
-
.
|
| 44 |
-
.
|
| 45 |
</style>
|
| 46 |
""", unsafe_allow_html=True)
|
| 47 |
|
| 48 |
-
# --- STATE
|
| 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 |
-
# ---
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 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 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
| 75 |
st.write("---")
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 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 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 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 |
-
|
| 155 |
-
st.markdown(f'<div class="item-row"><div class="
|
| 156 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
st.set_page_config(page_title="FitPlan AI", layout="wide")
|
| 7 |
|
| 8 |
+
# --- UI STYLING (Preserving your exact original look) ---
|
| 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 |
.assessment-card {
|
| 17 |
background-color: white !important; padding: 25px; border-radius: 15px;
|
| 18 |
border-left: 10px solid #004d57; color: #000000 !important; margin-bottom: 30px;
|
| 19 |
}
|
|
|
|
|
|
|
| 20 |
.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); }
|
| 21 |
+
.day-container { background-color: white !important; padding: 30px; border-radius: 25px; margin-bottom: 40px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
.day-header { color: #004d57; font-size: 26px; font-weight: bold; margin-bottom: 20px; border-bottom: 2px solid #f0f2f6; padding-bottom: 15px; }
|
|
|
|
| 23 |
.item-row { display: flex; align-items: center; justify-content: space-between; padding: 18px 0; border-bottom: 1px solid #f1f1f1; }
|
| 24 |
.item-row:last-child { border-bottom: none; }
|
| 25 |
+
.ex-name { flex: 2; font-weight: 600; color: #2d3436; font-size: 18px; }
|
|
|
|
| 26 |
.stat-group { display: flex; gap: 15px; flex: 1.5; justify-content: flex-end; }
|
| 27 |
.stat-pill { text-align: center; min-width: 75px; background: #f8f9fa; padding: 6px; border-radius: 12px; }
|
| 28 |
+
.stat-val { color: #004d57; font-weight: bold; font-size: 15px; display: block; }
|
| 29 |
+
.stat-label { font-size: 10px; color: #636e72; text-transform: uppercase; display: block; }
|
| 30 |
</style>
|
| 31 |
""", unsafe_allow_html=True)
|
| 32 |
|
| 33 |
+
# --- NAVIGATION STATE ---
|
|
|
|
| 34 |
if 'page' not in st.session_state: st.session_state.page = 'dashboard'
|
| 35 |
if 'user_data' not in st.session_state: st.session_state.user_data = None
|
| 36 |
if 'workout_plan' not in st.session_state: st.session_state.workout_plan = None
|
| 37 |
if 'diet_plan' not in st.session_state: st.session_state.diet_plan = None
|
| 38 |
|
| 39 |
+
# --- SIDEBAR ---
|
| 40 |
+
with st.sidebar:
|
| 41 |
+
st.markdown("# π€ FitPlan AI")
|
| 42 |
+
if st.button("π Dashboard", use_container_width=True): st.session_state.page = 'dashboard'; st.rerun()
|
| 43 |
+
if st.button("ποΈ Workout Plan", use_container_width=True): st.session_state.page = 'input'; st.rerun()
|
| 44 |
+
if st.button("π₯ Dietary Plan", use_container_width=True): st.session_state.page = 'diet'; st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
# --- 1. DASHBOARD PAGE ---
|
| 47 |
+
if st.session_state.page == 'dashboard':
|
| 48 |
+
st.title("π Your Dashboard")
|
| 49 |
+
if st.session_state.user_data:
|
| 50 |
+
d = st.session_state.user_data
|
| 51 |
+
col1, col2, col3 = st.columns(3)
|
| 52 |
+
with col1: st.markdown(f'<div class="stat-card"><div style="font-size:24px; font-weight:bold;">{d["name"]}</div><div style="color:#636e72;">USER</div></div>', unsafe_allow_html=True)
|
| 53 |
+
with col2: st.markdown(f'<div class="stat-card"><div style="font-size:24px; font-weight:bold;">{d["bmi"]:.1f}</div><div style="color:#636e72;">BMI</div></div>', unsafe_allow_html=True)
|
| 54 |
+
with col3: st.markdown(f'<div class="stat-card"><div style="font-size:24px; font-weight:bold; color:{d["color"]}">{d["status"]}</div><div style="color:#636e72;">HEALTH STATUS</div></div>', unsafe_allow_html=True)
|
| 55 |
+
|
| 56 |
st.write("---")
|
| 57 |
+
st.subheader("Current Focus")
|
| 58 |
+
st.info(f"Targeting: **{d['goal']}** at **{d['level']}** intensity.")
|
| 59 |
+
else:
|
| 60 |
+
st.warning("No data found. Please go to 'Workout Plan' and generate your profile.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
# --- 2. INPUT PAGE (Your Original Logic) ---
|
| 63 |
+
elif st.session_state.page == 'input':
|
| 64 |
+
st.title("ποΈ Fitness Profile")
|
| 65 |
+
c1, c2, c3 = st.columns([2, 1, 1])
|
| 66 |
+
with c1: name = st.text_input("Name")
|
| 67 |
+
with c2: gender = st.selectbox("Gender", ["Male", "Female", "Other"])
|
| 68 |
+
with c3: age = st.number_input("Age", min_value=1, value=19)
|
| 69 |
+
h, w = st.columns(2)
|
| 70 |
+
with h: height = st.number_input("Height (cm)", min_value=1.0)
|
| 71 |
+
with w: weight = st.number_input("Weight (kg)", min_value=1.0)
|
| 72 |
+
goal = st.selectbox("Goal", ["Build Muscle", "Weight Loss", "Strength", "Flexibility"])
|
| 73 |
+
level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
|
| 74 |
+
equip = st.multiselect("Equipment", ["Dumbbells", "Kettlebells", "Pull-up Bar", "Resistance Bands", "Yoga Mat", "No Equipment"])
|
| 75 |
|
| 76 |
+
if st.button("Generate Complete Plan"):
|
| 77 |
+
prompt, bmi, status, color = build_prompt(name, gender, age, height, weight, goal, level, equip)
|
| 78 |
+
with st.spinner("AI is crafting your routine..."):
|
| 79 |
+
st.session_state.workout_plan = query_model(prompt)
|
| 80 |
+
st.session_state.user_data = {"name": name, "bmi": bmi, "status": status, "color": color, "age": age, "gender": gender, "goal": goal, "height": height, "weight": weight, "level": level}
|
| 81 |
+
st.session_state.diet_plan = None # Reset diet so it generates fresh for this user
|
| 82 |
+
st.session_state.page = 'result'
|
| 83 |
+
st.rerun()
|
| 84 |
|
| 85 |
+
# --- 3. WORKOUT RESULT (Preserving your exact Row/Pill layout) ---
|
| 86 |
+
elif st.session_state.page == 'result':
|
| 87 |
+
d = st.session_state.user_data
|
| 88 |
+
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)
|
| 89 |
+
|
| 90 |
+
raw = st.session_state.workout_plan
|
| 91 |
+
days = ["Day 1:", "Day 2:", "Day 3:", "Day 4:", "Day 5:"]
|
| 92 |
+
for i in range(len(days)):
|
| 93 |
+
start = raw.find(days[i])
|
| 94 |
+
if start != -1:
|
| 95 |
+
end = raw.find(days[i+1]) if i+1 < len(days) else len(raw)
|
| 96 |
+
day_text = raw[start:end].strip()
|
| 97 |
+
st.markdown(f'<div class="day-container"><div class="day-header">π· {days[i][:-1]}</div>', unsafe_allow_html=True)
|
| 98 |
+
for line in day_text.split("\n"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
if "|" in line:
|
| 100 |
parts = [p.strip() for p in line.replace("- ", "").split("|")]
|
| 101 |
if len(parts) == 4:
|
| 102 |
+
n, s, r, rs = parts
|
| 103 |
+
st.markdown(f'<div class="item-row"><div class="ex-name">π₯ {n}</div><div class="stat-group"><div class="stat-pill"><span class="stat-val">{s}</span><span class="stat-label">Sets</span></div><div class="stat-pill"><span class="stat-val">{r}</span><span class="stat-label">Reps</span></div><div class="stat-pill" style="background:#fff3e0;"><span class="stat-val" style="color:#e65100;">{rs}</span><span class="stat-label">Rest</span></div></div></div>', unsafe_allow_html=True)
|
| 104 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 105 |
+
st.download_button("π₯ Download Plan", data=raw, file_name=f"{d['name']}_Plan.txt")
|
| 106 |
+
|
| 107 |
+
# --- 4. DIETARY PAGE (Now Functional) ---
|
| 108 |
+
elif st.session_state.page == 'diet':
|
| 109 |
+
st.title("π₯ Dietary Plan")
|
| 110 |
+
if st.session_state.user_data:
|
| 111 |
+
d = st.session_state.user_data
|
| 112 |
+
if not st.session_state.diet_plan:
|
| 113 |
+
d_prompt = build_diet_prompt(d['name'], d['gender'], d['age'], d['height'], d['weight'], d['goal'])
|
| 114 |
+
with st.spinner("Generating unique meal plan..."):
|
| 115 |
+
st.session_state.diet_plan = query_model(d_prompt)
|
| 116 |
+
|
| 117 |
+
raw_diet = st.session_state.diet_plan
|
| 118 |
+
st.markdown('<div class="day-container"><div class="day-header">π Daily Nutrition</div>', unsafe_allow_html=True)
|
| 119 |
+
for line in raw_diet.split("\n"):
|
| 120 |
+
if "|" in line:
|
| 121 |
+
parts = [p.strip() for p in line.replace("- ", "").split("|")]
|
| 122 |
+
if len(parts) == 4:
|
| 123 |
+
m_n, m_t, m_i, m_c = parts
|
| 124 |
+
st.markdown(f'<div class="item-row"><div class="ex-name">π΄ {m_n}<br><small>{m_i}</small></div><div class="stat-group"><div class="stat-pill"><span class="stat-val">{m_t}</span><span class="stat-label">Time</span></div><div class="stat-pill" style="background:#e8f5e9;"><span class="stat-val" style="color:#2e7d32;">{m_c}</span><span class="stat-label">Energy</span></div></div></div>', unsafe_allow_html=True)
|
| 125 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 126 |
+
if st.button("Refresh Meals"): st.session_state.diet_plan = None; st.rerun()
|
| 127 |
+
else:
|
| 128 |
+
st.warning("Generate a profile in 'Workout Plan' first.")
|