Shrey0405 commited on
Commit
7eda077
Β·
verified Β·
1 Parent(s): 75cb91d

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +150 -88
src/streamlit_app.py CHANGED
@@ -1,117 +1,179 @@
1
  import streamlit as st
 
2
 
3
- # --- Page Configuration ---
4
  st.set_page_config(
5
- page_title="FitPulse Profile Builder",
6
- page_icon="πŸ’ͺ",
7
- layout="centered"
 
8
  )
9
 
10
- # --- Custom CSS for "App-like" Feel ---
11
  st.markdown("""
12
  <style>
13
- .main {
14
- background-color: #f8f9fa;
 
15
  }
16
- .stButton>button {
17
- width: 100%;
18
- border-radius: 10px;
19
- height: 3em;
20
- background-color: #FF4B4B;
 
 
 
 
 
21
  color: white;
22
- font-weight: bold;
 
 
 
 
 
 
 
 
23
  }
24
- .css-1544g2n {
25
- padding: 2rem 1rem;
26
- border-radius: 15px;
27
  background-color: white;
28
- box-shadow: 0 4px 6px rgba(0,0,0,0.1);
 
 
 
29
  }
30
  </style>
31
  """, unsafe_allow_html=True)
32
 
33
- def calculate_bmi(weight, height_cm):
34
- height_m = height_cm / 100
35
- bmi = weight / (height_m ** 2)
36
- return round(bmi, 2)
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
- # --- Header ---
49
- st.title("πŸ’ͺ FitPulse")
50
- st.subheader("Create Your Fitness Profile")
51
- st.write("Complete the details below to unlock your personalized health metrics.")
52
 
53
- # --- Form Section ---
54
- with st.form("fitness_form"):
55
- st.markdown("### πŸ‘€ Personal Information")
56
- name = st.text_input("Full Name", placeholder="e.g. John Doe")
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.markdown("### 🎯 Fitness Details")
66
-
67
- goal = st.selectbox("Fitness Goal",
68
- ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"])
69
-
70
- level = st.select_slider("Fitness Level",
71
- options=["Beginner", "Intermediate", "Advanced"])
72
-
73
- equipment = st.multiselect("Available Equipment",
74
- ["Dumbbells", "Resistance Band", "Yoga Mat", "Barbell", "Kettlebell", "No Equipment"],
75
- default=["No Equipment"])
76
 
77
- submitted = st.form_submit_button("Generate My Profile")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
- # --- Logic & Output ---
80
- if submitted:
81
- # Validation
82
- if not name:
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
- # Calculations
88
- bmi_val = calculate_bmi(weight, height)
89
- category, color = get_bmi_category(bmi_val)
90
 
91
- # Results Display
92
- st.success(f"Profile Created Successfully for **{name}**!")
 
93
 
94
- res_col1, res_col2 = st.columns(2)
 
 
 
95
 
96
- with res_col1:
97
- st.metric(label="Calculated BMI", value=f"{bmi_val}")
98
 
99
- with res_col2:
100
- st.markdown(f"**Category:**")
101
- if category == "Normal":
102
- st.info(f"✨ {category}")
103
- elif category == "Underweight":
104
- st.warning(f"⚠️ {category}")
105
- else:
106
- st.error(f"🚨 {category}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
- # Summary Table
109
- st.markdown("### πŸ“‹ Profile Summary")
110
- data = {
111
- "Detail": ["Goal", "Level", "Equipment"],
112
- "Value": [goal, level, ", ".join(equipment)]
113
- }
114
- st.table(data)
115
 
116
  # --- Footer ---
117
- st.caption("Data is processed locally and not stored. Stay healthy!")
 
 
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")