Amrutha04 commited on
Commit
cdaba65
·
verified ·
1 Parent(s): ce01eb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -73
app.py CHANGED
@@ -2,97 +2,68 @@ import streamlit as st
2
  from prompt_builder import build_prompt
3
  from model_api import query_model
4
 
5
- # 1. Page Configuration
6
  st.set_page_config(page_title="FitPlan AI", layout="wide")
7
 
8
- # 2. Custom Styling (Preserving your exact UI style)
9
  st.markdown("""
10
  <style>
11
  .stApp { background: linear-gradient(135deg, #f6d365 0%, #fda085 100%); background-attachment: fixed; }
12
  section[data-testid="stSidebar"] { background-color: #000000 !important; }
13
  section[data-testid="stSidebar"] h1, section[data-testid="stSidebar"] p { color: #FFFFFF !important; }
14
- h1, h2, h3, p, label { color: #2D3436 !important; font-weight: 600; }
15
- .result-card {
16
- background-color: white !important; padding: 25px; border-radius: 15px;
17
- border-left: 10px solid #004d57; color: #000000 !important; margin-bottom: 20px;
18
- }
19
- .day-card {
20
- background-color: #ffffff !important; padding: 20px 30px !important;
21
- border-radius: 15px; margin-bottom: 20px; border-left: 10px solid #004d57;
22
- color: #000000 !important; white-space: pre-line !important;
23
- line-height: 1.4 !important; box-shadow: 0 4px 12px rgba(0,0,0,0.08);
24
- }
25
- .day-card p, .day-card ul, .day-card li { margin: 2px 0 !important; text-align: left !important; }
26
  </style>
27
  """, unsafe_allow_html=True)
28
 
29
- # 3. Initialize Session State for Page Navigation
30
- if 'page' not in st.session_state:
31
- st.session_state.page = 'input'
32
- if 'workout_plan' not in st.session_state:
33
- st.session_state.workout_plan = None
34
- if 'user_data' not in st.session_state:
35
- st.session_state.user_data = {}
36
 
37
  # --- SIDEBAR ---
38
  with st.sidebar:
39
  st.markdown("# 👤 Personalised Fitness Plan")
40
- st.write("---")
41
  if st.session_state.page == 'result':
42
- if st.button("⬅️ New Profile / Back"):
43
  st.session_state.page = 'input'
44
  st.rerun()
45
 
46
- # --- PAGE 1: INPUT FORM ---
47
  if st.session_state.page == 'input':
48
  st.title("🏋️ Create Your Fitness Profile")
49
-
50
  col1, col2, col3 = st.columns([2, 1, 1])
51
- with col1: name = st.text_input("Name", value=st.session_state.user_data.get('name', ''))
52
  with col2: gender = st.selectbox("Gender", ["Male", "Female", "Other"])
53
- with col3: age = st.number_input("Age", min_value=1, value=st.session_state.user_data.get('age', 19))
54
-
55
  col_h, col_w = st.columns(2)
56
- with col_h: height = st.number_input("Height (cm)", min_value=1.0, value=st.session_state.user_data.get('height', 170.0))
57
- with col_w: weight = st.number_input("Weight (kg)", min_value=1.0, value=st.session_state.user_data.get('weight', 65.0))
58
-
59
  goal = st.selectbox("Goal", ["Build Muscle", "Weight Loss", "Strength", "Flexibility"])
60
  level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
61
  equip = st.multiselect("Equipment", ["Dumbbells", "Kettlebells", "Pull-up Bar", "Resistance Bands", "Yoga Mat", "No Equipment"])
62
 
63
  if st.button("Submit Profile"):
64
- if not name or height <= 50.0 or weight <= 10.0:
65
- st.error("Please fill in valid details.")
66
- else:
67
- with st.spinner("Analyzing profile and generating routine..."):
68
- prompt, bmi, bmi_status, status_color = build_prompt(name, gender, age, height, weight, goal, level, equip)
69
- raw_workout = query_model(prompt)
70
-
71
- if "Error" in raw_workout:
72
- st.error("API Error. Please check your HF Token.")
73
- else:
74
- st.session_state.workout_plan = raw_workout
75
- st.session_state.assessment_data = {
76
- "name": name, "bmi": bmi, "status": bmi_status, "color": status_color, "age": age, "gender": gender
77
- }
78
- st.session_state.user_data = {"name": name, "age": age, "height": height, "weight": weight}
79
- st.session_state.page = 'result'
80
- st.rerun()
81
 
82
- # --- PAGE 2: RESULTS PAGE ---
83
  elif st.session_state.page == 'result':
84
- data = st.session_state.assessment_data
85
- st.title("📋 Your Personalized Routine")
86
-
87
- st.markdown(f"""
88
- <div class="result-card">
89
- <h2>Hello {data['name']}</h2>
90
- <p>{data['gender']} | {data['age']} Years Old</p>
91
- <p>BMI: <strong>{data['bmi']:.2f}</strong> | Category: <span style="color:{data['color']}">{data['status']}</span></p>
92
- </div>
93
- """, unsafe_allow_html=True)
94
-
95
-
96
 
97
  raw_content = st.session_state.workout_plan
98
  days = ["Day 1:", "Day 2:", "Day 3:", "Day 4:", "Day 5:"]
@@ -101,15 +72,27 @@ elif st.session_state.page == 'result':
101
  start = raw_content.find(days[i])
102
  if start != -1:
103
  end = raw_content.find(days[i+1]) if i+1 < len(days) else len(raw_content)
104
- day_text = raw_content[start:end].strip()
105
- # Clean empty spaces logic
106
- clean_text = "\n".join([line for line in day_text.splitlines() if line.strip()])
107
- st.markdown(f'<div class="day-card">{clean_text}</div>', unsafe_allow_html=True)
108
-
109
- st.write("---")
110
- st.download_button(
111
- label="📥 Download Full Plan",
112
- data=st.session_state.workout_plan,
113
- file_name=f"{data['name']}_Workout_Plan.txt",
114
- mime="text/plain"
115
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from prompt_builder import build_prompt
3
  from model_api import query_model
4
 
 
5
  st.set_page_config(page_title="FitPlan AI", layout="wide")
6
 
7
+ # Enhanced CSS for the Icon-Table Grid UI
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
+ .result-card { background-color: white !important; padding: 25px; border-radius: 15px; border-left: 10px solid #004d57; color: #000000 !important; margin-bottom: 20px; }
15
+
16
+ .day-container { background-color: #f8f9fa; border-radius: 20px; padding: 25px; margin-bottom: 30px; border: 1px solid #e0e0e0; }
17
+ .day-header { color: #004d57; font-size: 24px; font-weight: bold; margin-bottom: 20px; display: flex; align-items: center; }
18
+
19
+ .exercise-row { background: white; border-radius: 12px; padding: 15px; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
20
+ .ex-name { flex: 2; font-weight: 600; color: #2d3436; font-size: 16px; }
21
+ .stat-box { flex: 1; text-align: center; display: flex; flex-direction: column; align-items: center; }
22
+ .stat-val { background: #e0f2f1; color: #004d57; padding: 5px 15px; border-radius: 20px; font-weight: bold; font-size: 14px; min-width: 60px; }
23
+ .stat-label { font-size: 11px; color: #636e72; text-transform: uppercase; margin-top: 4px; }
 
24
  </style>
25
  """, unsafe_allow_html=True)
26
 
27
+ if 'page' not in st.session_state: st.session_state.page = 'input'
28
+ if 'workout_plan' not in st.session_state: st.session_state.workout_plan = None
 
 
 
 
 
29
 
30
  # --- SIDEBAR ---
31
  with st.sidebar:
32
  st.markdown("# 👤 Personalised Fitness Plan")
 
33
  if st.session_state.page == 'result':
34
+ if st.button("⬅️ New Profile"):
35
  st.session_state.page = 'input'
36
  st.rerun()
37
 
38
+ # --- INPUT PAGE ---
39
  if st.session_state.page == 'input':
40
  st.title("🏋️ Create Your Fitness Profile")
 
41
  col1, col2, col3 = st.columns([2, 1, 1])
42
+ with col1: name = st.text_input("Name")
43
  with col2: gender = st.selectbox("Gender", ["Male", "Female", "Other"])
44
+ with col3: age = st.number_input("Age", min_value=1, value=19)
45
+
46
  col_h, col_w = st.columns(2)
47
+ with col_h: height = st.number_input("Height (cm)", min_value=1.0)
48
+ with col_w: weight = st.number_input("Weight (kg)", min_value=1.0)
49
+
50
  goal = st.selectbox("Goal", ["Build Muscle", "Weight Loss", "Strength", "Flexibility"])
51
  level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
52
  equip = st.multiselect("Equipment", ["Dumbbells", "Kettlebells", "Pull-up Bar", "Resistance Bands", "Yoga Mat", "No Equipment"])
53
 
54
  if st.button("Submit Profile"):
55
+ prompt, bmi, bmi_status, status_color = build_prompt(name, gender, age, height, weight, goal, level, equip)
56
+ with st.spinner("Generating Professional UI..."):
57
+ raw_workout = query_model(prompt)
58
+ st.session_state.workout_plan = raw_workout
59
+ st.session_state.assessment_data = {"name": name, "bmi": bmi, "status": bmi_status, "color": status_color, "age": age, "gender": gender}
60
+ st.session_state.page = 'result'
61
+ st.rerun()
 
 
 
 
 
 
 
 
 
 
62
 
63
+ # --- RESULT PAGE ---
64
  elif st.session_state.page == 'result':
65
+ d = st.session_state.assessment_data
66
+ st.markdown(f'<div class="result-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)
 
 
 
 
 
 
 
 
 
 
67
 
68
  raw_content = st.session_state.workout_plan
69
  days = ["Day 1:", "Day 2:", "Day 3:", "Day 4:", "Day 5:"]
 
72
  start = raw_content.find(days[i])
73
  if start != -1:
74
  end = raw_content.find(days[i+1]) if i+1 < len(days) else len(raw_content)
75
+ day_block = raw_content[start:end].strip()
76
+
77
+ st.markdown(f'<div class="day-container"><div class="day-header">🔹 {days[i][:-1]}</div>', unsafe_allow_html=True)
78
+
79
+ # Parse individual exercises
80
+ lines = day_block.split("\n")
81
+ for line in lines:
82
+ if "|" in line:
83
+ parts = [p.strip() for p in line.replace("- ", "").split("|")]
84
+ if len(parts) == 4:
85
+ name, sets, reps, rest = parts
86
+ st.markdown(f"""
87
+ <div class="exercise-row">
88
+ <div class="ex-name">🏋️ {name}</div>
89
+ <div class="stat-box"><span class="stat-val">{sets}</span><span class="stat-label">Sets</span></div>
90
+ <div class="stat-box"><span class="stat-val">{reps}</span><span class="stat-label">Reps</span></div>
91
+ <div class="stat-box"><span class="stat-val" style="background:#fff3e0; color:#e65100;">{rest}</span><span class="stat-label">Rest</span></div>
92
+ </div>
93
+ """, unsafe_allow_html=True)
94
+ elif "Rest" in line:
95
+ st.info("🧘 Enjoy your Rest Day! Recovery is part of progress.")
96
+ st.markdown('</div>', unsafe_allow_html=True)
97
+
98
+ st.download_button("📥 Download Plan", data=raw_content, file_name="Workout.txt")