Update src/streamlit_app.py
Browse files- src/streamlit_app.py +150 -88
src/streamlit_app.py
CHANGED
|
@@ -1,117 +1,179 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
-
# --- Page
|
| 4 |
st.set_page_config(
|
| 5 |
-
page_title="FitPulse
|
| 6 |
-
page_icon="
|
| 7 |
-
layout="
|
|
|
|
| 8 |
)
|
| 9 |
|
| 10 |
-
# --- Custom CSS for
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
}
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
color: white;
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
}
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
background-color: white;
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
}
|
| 30 |
</style>
|
| 31 |
""", unsafe_allow_html=True)
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
def get_bmi_category(bmi):
|
| 39 |
-
if bmi < 18.5:
|
| 40 |
-
return "Underweight", "blue"
|
| 41 |
-
elif 18.5 <= bmi < 24.9:
|
| 42 |
-
return "Normal", "green"
|
| 43 |
-
elif 25 <= bmi < 29.9:
|
| 44 |
-
return "Overweight", "orange"
|
| 45 |
-
else:
|
| 46 |
-
return "Obese", "red"
|
| 47 |
|
| 48 |
-
# ---
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
col1, col2 = st.columns(2)
|
| 59 |
-
with col1:
|
| 60 |
-
height = st.number_input("Height (cm)", min_value=0.0, step=0.1, help="Enter your height in centimeters")
|
| 61 |
-
with col2:
|
| 62 |
-
weight = st.number_input("Weight (kg)", min_value=0.0, step=0.1, help="Enter your weight in kilograms")
|
| 63 |
|
|
|
|
|
|
|
|
|
|
| 64 |
st.markdown("---")
|
| 65 |
-
st.
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
["Dumbbells", "Resistance Band", "Yoga Mat", "Barbell", "Kettlebell", "No Equipment"],
|
| 75 |
-
default=["No Equipment"])
|
| 76 |
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
|
| 80 |
-
if
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
st.error("Please enter your name.")
|
| 84 |
-
elif height <= 0 or weight <= 0:
|
| 85 |
-
st.error("Height and Weight must be greater than zero.")
|
| 86 |
else:
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
category, color = get_bmi_category(bmi_val)
|
| 90 |
|
| 91 |
-
#
|
| 92 |
-
|
|
|
|
| 93 |
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
|
| 97 |
-
st.metric(label="Calculated BMI", value=f"{bmi_val}")
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
"Value": [goal, level, ", ".join(equipment)]
|
| 113 |
-
}
|
| 114 |
-
st.table(data)
|
| 115 |
|
| 116 |
# --- Footer ---
|
| 117 |
-
st.
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
|
| 4 |
+
# --- Page Config ---
|
| 5 |
st.set_page_config(
|
| 6 |
+
page_title="FitPulse Pro | Dashboard",
|
| 7 |
+
page_icon="β‘",
|
| 8 |
+
layout="wide",
|
| 9 |
+
initial_sidebar_state="expanded",
|
| 10 |
)
|
| 11 |
|
| 12 |
+
# --- Custom CSS for Modern UI ---
|
| 13 |
st.markdown("""
|
| 14 |
<style>
|
| 15 |
+
/* Main Background */
|
| 16 |
+
.stApp {
|
| 17 |
+
background-color: #f4f7f6;
|
| 18 |
}
|
| 19 |
+
|
| 20 |
+
/* Sidebar Styling */
|
| 21 |
+
section[data-testid="stSidebar"] {
|
| 22 |
+
background-color: #1E1E2F !important;
|
| 23 |
+
color: white;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/* Card Styling */
|
| 27 |
+
div.stButton > button:first-child {
|
| 28 |
+
background-color: #624BFF;
|
| 29 |
color: white;
|
| 30 |
+
border-radius: 8px;
|
| 31 |
+
border: none;
|
| 32 |
+
padding: 0.6rem 2rem;
|
| 33 |
+
transition: all 0.3s ease;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
div.stButton > button:hover {
|
| 37 |
+
background-color: #4B39C1;
|
| 38 |
+
transform: translateY(-2px);
|
| 39 |
}
|
| 40 |
+
|
| 41 |
+
/* Custom Metric Box */
|
| 42 |
+
.metric-card {
|
| 43 |
background-color: white;
|
| 44 |
+
padding: 20px;
|
| 45 |
+
border-radius: 12px;
|
| 46 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
|
| 47 |
+
border-left: 5px solid #624BFF;
|
| 48 |
}
|
| 49 |
</style>
|
| 50 |
""", unsafe_allow_html=True)
|
| 51 |
|
| 52 |
+
# --- Session State Initialization ---
|
| 53 |
+
if 'profile_created' not in st.session_state:
|
| 54 |
+
st.session_state.profile_created = False
|
| 55 |
+
st.session_state.user_data = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
+
# --- Helper Functions ---
|
| 58 |
+
def calculate_bmi(w, h_cm):
|
| 59 |
+
h_m = h_cm / 100
|
| 60 |
+
return round(w / (h_m ** 2), 2)
|
| 61 |
|
| 62 |
+
def get_bmi_status(bmi):
|
| 63 |
+
if bmi < 18.5: return "Underweight", "π΅", "Consider a nutrient-rich diet."
|
| 64 |
+
if bmi < 25: return "Normal", "π’", "Great job! Maintain your current lifestyle."
|
| 65 |
+
if bmi < 30: return "Overweight", "π ", "Incorporate more cardio and portion control."
|
| 66 |
+
return "Obese", "π΄", "Consult with a healthcare provider for a plan."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
# --- Sidebar Navigation ---
|
| 69 |
+
with st.sidebar:
|
| 70 |
+
st.markdown("<h1 style='color: white;'>β‘ FitPulse Pro</h1>", unsafe_allow_html=True)
|
| 71 |
st.markdown("---")
|
| 72 |
+
menu = st.radio(
|
| 73 |
+
"NAVIGATION",
|
| 74 |
+
["π Dashboard", "π€ User Profile", "π Health Metrics", "π₯ Meal Plan (Beta)"],
|
| 75 |
+
index=0 if not st.session_state.profile_created else 0
|
| 76 |
+
)
|
| 77 |
+
st.markdown("---")
|
| 78 |
+
st.info("System Status: Online")
|
| 79 |
+
|
| 80 |
+
# --- Page Logic ---
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
if menu == "π€ User Profile":
|
| 83 |
+
st.header("π€ Personal Information")
|
| 84 |
+
st.write("Complete your profile to sync your health data.")
|
| 85 |
+
|
| 86 |
+
with st.container():
|
| 87 |
+
col1, col2 = st.columns(2)
|
| 88 |
+
with col1:
|
| 89 |
+
name = st.text_input("Full Name", value=st.session_state.user_data.get('name', ""))
|
| 90 |
+
height = st.number_input("Height (cm)", min_value=0.0, max_value=250.0, value=float(st.session_state.user_data.get('height', 170.0)))
|
| 91 |
+
with col2:
|
| 92 |
+
weight = st.number_input("Weight (kg)", min_value=0.0, max_value=300.0, value=float(st.session_state.user_data.get('weight', 70.0)))
|
| 93 |
+
level = st.select_slider("Fitness Level", options=["Beginner", "Intermediate", "Advanced"])
|
| 94 |
+
|
| 95 |
+
goal = st.selectbox("Primary Fitness Goal", ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"])
|
| 96 |
+
equip = st.multiselect("Available Equipment", ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment", "Full Gym"], default=["No Equipment"])
|
| 97 |
+
|
| 98 |
+
if st.button("Save & Update Profile"):
|
| 99 |
+
if name and height > 0 and weight > 0:
|
| 100 |
+
st.session_state.user_data = {
|
| 101 |
+
"name": name, "height": height, "weight": weight,
|
| 102 |
+
"goal": goal, "level": level, "equip": equip,
|
| 103 |
+
"bmi": calculate_bmi(weight, height)
|
| 104 |
+
}
|
| 105 |
+
st.session_state.profile_created = True
|
| 106 |
+
st.success("Profile Updated!")
|
| 107 |
+
st.balloons()
|
| 108 |
+
else:
|
| 109 |
+
st.error("Please fill in all required fields accurately.")
|
| 110 |
|
| 111 |
+
elif menu == "π Dashboard":
|
| 112 |
+
if not st.session_state.profile_created:
|
| 113 |
+
st.warning("β οΈ Please complete your **User Profile** section first.")
|
| 114 |
+
st.image("https://illustrations.popsy.co/gray/fitness-stats.svg", width=400)
|
|
|
|
|
|
|
|
|
|
| 115 |
else:
|
| 116 |
+
ud = st.session_state.user_data
|
| 117 |
+
st.title(f"Welcome back, {ud['name']}! π")
|
|
|
|
| 118 |
|
| 119 |
+
# Dashboard Row 1: Key Metrics
|
| 120 |
+
m1, m2, m3, m4 = st.columns(4)
|
| 121 |
+
status, icon, advice = get_bmi_status(ud['bmi'])
|
| 122 |
|
| 123 |
+
m1.metric("Current BMI", f"{ud['bmi']}")
|
| 124 |
+
m2.metric("Status", status)
|
| 125 |
+
m3.metric("Goal", ud['goal'])
|
| 126 |
+
m4.metric("Level", ud['level'])
|
| 127 |
|
| 128 |
+
st.markdown("---")
|
|
|
|
| 129 |
|
| 130 |
+
# Dashboard Row 2: Visual Insights
|
| 131 |
+
c1, c2 = st.columns([2, 1])
|
| 132 |
+
with c1:
|
| 133 |
+
st.subheader("π Activity Overview")
|
| 134 |
+
st.info(f"**Recommended focus:** Based on your goal of **{ud['goal']}**, you should prioritize protein intake and consistent training.")
|
| 135 |
+
|
| 136 |
+
# Simulated Chart
|
| 137 |
+
chart_data = pd.DataFrame({
|
| 138 |
+
'Week': ['W1', 'W2', 'W3', 'W4'],
|
| 139 |
+
'Consistency': [70, 85, 80, 95]
|
| 140 |
+
})
|
| 141 |
+
st.line_chart(chart_data.set_index('Week'))
|
| 142 |
+
|
| 143 |
+
with c2:
|
| 144 |
+
st.subheader("π οΈ Setup")
|
| 145 |
+
st.write("**Equipment:**")
|
| 146 |
+
for item in ud['equip']:
|
| 147 |
+
st.write(f"β
{item}")
|
| 148 |
+
|
| 149 |
+
st.markdown(f"""
|
| 150 |
+
<div class="metric-card">
|
| 151 |
+
<h4>Health Advice</h4>
|
| 152 |
+
<p>{icon} {advice}</p>
|
| 153 |
+
</div>
|
| 154 |
+
""", unsafe_allow_html=True)
|
| 155 |
+
|
| 156 |
+
elif menu == "π Health Metrics":
|
| 157 |
+
if not st.session_state.profile_created:
|
| 158 |
+
st.error("No data found. Please enter details in Profile.")
|
| 159 |
+
else:
|
| 160 |
+
st.header("π Deep Dive Metrics")
|
| 161 |
+
ud = st.session_state.user_data
|
| 162 |
+
|
| 163 |
+
# Detailed BMI Breakdown
|
| 164 |
+
st.subheader("BMI Analysis")
|
| 165 |
+
st.progress(min(ud['bmi']/40, 1.0))
|
| 166 |
+
st.write(f"Your BMI is **{ud['bmi']}**. Ideal range is 18.5 - 24.9.")
|
| 167 |
+
|
| 168 |
+
# Calculations for calories (Simplified BMR)
|
| 169 |
+
bmr = 10 * ud['weight'] + 6.25 * ud['height'] - 5 * 25 + 5 # Simplified Male BMR for logic demo
|
| 170 |
+
st.write(f"**Estimated Daily Maintenance Calories:** {int(bmr)} kcal")
|
| 171 |
|
| 172 |
+
else: # Meal Plan Beta
|
| 173 |
+
st.header("π₯ Personalized Meal Plan")
|
| 174 |
+
st.info("This feature is currently in Beta. Based on your goal, we recommend a 40/30/30 Macro split.")
|
| 175 |
+
st.image("https://illustrations.popsy.co/gray/healthy-food.svg", width=300)
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
# --- Footer ---
|
| 178 |
+
st.sidebar.markdown("---")
|
| 179 |
+
st.sidebar.caption("FitPulse v2.1.0-Stable")
|