Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
from prompt_builder import build_prompt
|
| 3 |
from model_api import query_model
|
| 4 |
from diet_builder import build_diet_prompt
|
|
@@ -39,9 +39,28 @@ if 'diet_plan' not in st.session_state: st.session_state.diet_plan = None
|
|
| 39 |
# --- SIDEBAR ---
|
| 40 |
with st.sidebar:
|
| 41 |
st.markdown("# π€ FitPlan AI")
|
| 42 |
-
if st.button("π Dashboard", use_container_width=True):
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# --- 1. DASHBOARD PAGE ---
|
| 47 |
if st.session_state.page == 'dashboard':
|
|
@@ -52,14 +71,12 @@ if st.session_state.page == 'dashboard':
|
|
| 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.
|
| 58 |
-
st.info(f"Targeting: **{d['goal']}** at **{d['level']}** intensity.")
|
| 59 |
else:
|
| 60 |
-
st.warning("
|
| 61 |
|
| 62 |
-
# --- 2. INPUT PAGE
|
| 63 |
elif st.session_state.page == 'input':
|
| 64 |
st.title("ποΈ Fitness Profile")
|
| 65 |
c1, c2, c3 = st.columns([2, 1, 1])
|
|
@@ -78,11 +95,11 @@ elif st.session_state.page == 'input':
|
|
| 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
|
| 82 |
st.session_state.page = 'result'
|
| 83 |
st.rerun()
|
| 84 |
|
| 85 |
-
# --- 3. WORKOUT RESULT (
|
| 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)
|
|
@@ -104,11 +121,12 @@ elif st.session_state.page == 'result':
|
|
| 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 (
|
| 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..."):
|
|
@@ -123,6 +141,5 @@ elif st.session_state.page == 'diet':
|
|
| 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.")
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
from prompt_builder import build_prompt
|
| 3 |
from model_api import query_model
|
| 4 |
from diet_builder import build_diet_prompt
|
|
|
|
| 39 |
# --- SIDEBAR ---
|
| 40 |
with st.sidebar:
|
| 41 |
st.markdown("# π€ FitPlan AI")
|
| 42 |
+
if st.button("π Dashboard", use_container_width=True):
|
| 43 |
+
st.session_state.page = 'dashboard'
|
| 44 |
+
st.rerun()
|
| 45 |
+
if st.button("ποΈ Workout Plan", use_container_width=True):
|
| 46 |
+
# If a plan exists, show the result, otherwise show input
|
| 47 |
+
if st.session_state.workout_plan:
|
| 48 |
+
st.session_state.page = 'result'
|
| 49 |
+
else:
|
| 50 |
+
st.session_state.page = 'input'
|
| 51 |
+
st.rerun()
|
| 52 |
+
if st.button("π₯ Dietary Plan", use_container_width=True):
|
| 53 |
+
st.session_state.page = 'diet'
|
| 54 |
+
st.rerun()
|
| 55 |
+
|
| 56 |
+
if st.session_state.workout_plan:
|
| 57 |
+
st.write("---")
|
| 58 |
+
if st.button("π Create New Profile"):
|
| 59 |
+
st.session_state.workout_plan = None
|
| 60 |
+
st.session_state.diet_plan = None
|
| 61 |
+
st.session_state.user_data = None
|
| 62 |
+
st.session_state.page = 'input'
|
| 63 |
+
st.rerun()
|
| 64 |
|
| 65 |
# --- 1. DASHBOARD PAGE ---
|
| 66 |
if st.session_state.page == 'dashboard':
|
|
|
|
| 71 |
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)
|
| 72 |
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)
|
| 73 |
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)
|
|
|
|
| 74 |
st.write("---")
|
| 75 |
+
st.success(f"Current Goal: **{d['goal']}**")
|
|
|
|
| 76 |
else:
|
| 77 |
+
st.warning("Go to 'Workout Plan' to generate your profile.")
|
| 78 |
|
| 79 |
+
# --- 2. INPUT PAGE ---
|
| 80 |
elif st.session_state.page == 'input':
|
| 81 |
st.title("ποΈ Fitness Profile")
|
| 82 |
c1, c2, c3 = st.columns([2, 1, 1])
|
|
|
|
| 95 |
with st.spinner("AI is crafting your routine..."):
|
| 96 |
st.session_state.workout_plan = query_model(prompt)
|
| 97 |
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}
|
| 98 |
+
st.session_state.diet_plan = None
|
| 99 |
st.session_state.page = 'result'
|
| 100 |
st.rerun()
|
| 101 |
|
| 102 |
+
# --- 3. WORKOUT RESULT (Stored Memory) ---
|
| 103 |
elif st.session_state.page == 'result':
|
| 104 |
d = st.session_state.user_data
|
| 105 |
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)
|
|
|
|
| 121 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 122 |
st.download_button("π₯ Download Plan", data=raw, file_name=f"{d['name']}_Plan.txt")
|
| 123 |
|
| 124 |
+
# --- 4. DIETARY PAGE (Stored Memory) ---
|
| 125 |
elif st.session_state.page == 'diet':
|
| 126 |
st.title("π₯ Dietary Plan")
|
| 127 |
if st.session_state.user_data:
|
| 128 |
d = st.session_state.user_data
|
| 129 |
+
# Only query the model if the diet doesn't exist yet
|
| 130 |
if not st.session_state.diet_plan:
|
| 131 |
d_prompt = build_diet_prompt(d['name'], d['gender'], d['age'], d['height'], d['weight'], d['goal'])
|
| 132 |
with st.spinner("Generating unique meal plan..."):
|
|
|
|
| 141 |
m_n, m_t, m_i, m_c = parts
|
| 142 |
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)
|
| 143 |
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
| 144 |
else:
|
| 145 |
st.warning("Generate a profile in 'Workout Plan' first.")
|