Amrutha04 commited on
Commit
ed87a59
ยท
verified ยท
1 Parent(s): 782fcdb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -69
app.py CHANGED
@@ -5,43 +5,31 @@ from model_api import query_model
5
  # 1. Page Configuration
6
  st.set_page_config(page_title="FitPlan AI", layout="wide")
7
 
8
- # 2. Custom Styling (Preserving Sidebar and Black Text)
9
  st.markdown("""
10
  <style>
11
- .stApp {
12
- background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
13
- background-attachment: fixed;
14
- }
15
- section[data-testid="stSidebar"] {
16
- background-color: #000000 !important;
17
- }
18
- section[data-testid="stSidebar"] h1, section[data-testid="stSidebar"] p {
19
- color: #FFFFFF !important;
20
- }
21
- h1, h2, h3, p, label {
22
- color: #2D3436 !important;
23
- font-weight: 600;
24
- }
25
  .result-card {
26
- background-color: white !important;
27
- padding: 25px;
28
- border-radius: 15px;
29
- border-left: 10px solid #004d57;
30
- color: #000000 !important;
31
- margin-bottom: 20px;
32
  }
33
  .day-card {
34
- background-color: #ffffff !important;
35
- padding: 20px;
36
- border-radius: 12px;
37
- margin-bottom: 15px;
38
- border-left: 8px solid #004d57;
39
- color: #000000 !important;
40
  white-space: pre-wrap !important;
41
  }
42
  </style>
43
  """, unsafe_allow_html=True)
44
 
 
 
 
 
 
 
45
  # --- SIDEBAR ---
46
  with st.sidebar:
47
  st.markdown("# ๐Ÿ‘ค Personalised Fitness Plan")
@@ -51,70 +39,63 @@ with st.sidebar:
51
  # --- MAIN CONTENT ---
52
  st.title("๐Ÿ‹๏ธ Create Your Fitness Profile")
53
 
54
- # Input Section
55
  col1, col2, col3 = st.columns([2, 1, 1])
56
- with col1:
57
- name = st.text_input("Name")
58
- with col2:
59
- gender = st.selectbox("Gender", ["Male", "Female", "Other"])
60
- with col3:
61
- age = st.number_input("Age", min_value=1, value=19)
62
 
63
  col_h, col_w = st.columns(2)
64
- with col_h:
65
- height = st.number_input("Height (cm)", min_value=1.0)
66
- with col_w:
67
- weight = st.number_input("Weight (kg)", min_value=1.0)
68
 
69
  goal = st.selectbox("Goal", ["Build Muscle", "Weight Loss", "Strength", "Flexibility"])
70
  level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
71
  equip = st.multiselect("Equipment", ["Dumbbells", "Kettlebells", "Pull-up Bar", "Resistance Bands", "Yoga Mat", "No Equipment"])
72
 
73
- # --- SUBMIT BUTTON LOGIC ---
74
  if st.button("Submit Profile"):
75
  if not name or height <= 0 or weight <= 0:
76
  st.error("Please fill in all details correctly.")
77
  else:
78
- # 1. Build the prompt (Expects 4 values from prompt_builder.py)
79
  prompt, bmi, bmi_status, status_color = build_prompt(name, gender, height, weight, goal, level, equip)
80
 
81
- # 2. Display BMI Assessment Card
82
- st.markdown(f"""
83
  <div class="result-card">
84
  <h2>Assessment for {name}</h2>
85
  <p>Gender: {gender} | Age: {age} Years</p>
86
  <p>Calculated BMI: <strong>{bmi:.2f}</strong> | Category: <span style="color:{status_color}">{bmi_status}</span></p>
87
  </div>
88
- """, unsafe_allow_html=True)
89
 
90
- # 3. Call Inference API
91
  with st.spinner("AI Trainer is thinking..."):
92
  raw_workout = query_model(prompt)
93
-
94
  if "Error" in raw_workout:
95
  st.error(f"API Error: {raw_workout}")
96
  else:
97
- st.markdown("### ๐Ÿ“‹ Your 5-Day Routine")
98
-
99
- # Split and Display Days
100
- days = ["Day 1:", "Day 2:", "Day 3:", "Day 4:", "Day 5:"]
101
-
102
- # We iterate through the days to create individual white cards
103
- for i in range(len(days)):
104
- start = raw_workout.find(days[i])
105
- if start != -1:
106
- # Find where the next day starts to slice the text
107
- end = raw_workout.find(days[i+1]) if i+1 < len(days) else len(raw_workout)
108
- day_content = raw_workout[start:end].strip()
109
-
110
- # Render the card with black text
111
- st.markdown(f'<div class="day-card">{day_content}</div>', unsafe_allow_html=True)
112
-
113
- # --- DOWNLOAD BUTTON (Correctly indented inside the block) ---
114
- st.write("---")
115
- st.download_button(
116
- label="๐Ÿ“ฅ Download Full Plan",
117
- data=raw_workout,
118
- file_name=f"{name}_Workout_Plan.txt",
119
- mime="text/plain"
120
- )
 
 
 
5
  # 1. Page Configuration
6
  st.set_page_config(page_title="FitPlan AI", layout="wide")
7
 
8
+ # 2. Custom Styling
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; border-radius: 12px;
21
+ margin-bottom: 15px; border-left: 8px solid #004d57; color: #000000 !important;
 
 
 
 
22
  white-space: pre-wrap !important;
23
  }
24
  </style>
25
  """, unsafe_allow_html=True)
26
 
27
+ # Initialize Session State variables if they don't exist
28
+ if 'workout_plan' not in st.session_state:
29
+ st.session_state.workout_plan = None
30
+ if 'assessment_html' not in st.session_state:
31
+ st.session_state.assessment_html = None
32
+
33
  # --- SIDEBAR ---
34
  with st.sidebar:
35
  st.markdown("# ๐Ÿ‘ค Personalised Fitness Plan")
 
39
  # --- MAIN CONTENT ---
40
  st.title("๐Ÿ‹๏ธ Create Your Fitness Profile")
41
 
 
42
  col1, col2, col3 = st.columns([2, 1, 1])
43
+ with col1: name = st.text_input("Name")
44
+ with col2: gender = st.selectbox("Gender", ["Male", "Female", "Other"])
45
+ with col3: age = st.number_input("Age", min_value=1, value=19)
 
 
 
46
 
47
  col_h, col_w = st.columns(2)
48
+ with col_h: height = st.number_input("Height (cm)", min_value=1.0)
49
+ with col_w: weight = st.number_input("Weight (kg)", min_value=1.0)
 
 
50
 
51
  goal = st.selectbox("Goal", ["Build Muscle", "Weight Loss", "Strength", "Flexibility"])
52
  level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
53
  equip = st.multiselect("Equipment", ["Dumbbells", "Kettlebells", "Pull-up Bar", "Resistance Bands", "Yoga Mat", "No Equipment"])
54
 
55
+ # --- SUBMIT BUTTON ---
56
  if st.button("Submit Profile"):
57
  if not name or height <= 0 or weight <= 0:
58
  st.error("Please fill in all details correctly.")
59
  else:
 
60
  prompt, bmi, bmi_status, status_color = build_prompt(name, gender, height, weight, goal, level, equip)
61
 
62
+ # Save assessment to session state
63
+ st.session_state.assessment_html = f"""
64
  <div class="result-card">
65
  <h2>Assessment for {name}</h2>
66
  <p>Gender: {gender} | Age: {age} Years</p>
67
  <p>Calculated BMI: <strong>{bmi:.2f}</strong> | Category: <span style="color:{status_color}">{bmi_status}</span></p>
68
  </div>
69
+ """
70
 
 
71
  with st.spinner("AI Trainer is thinking..."):
72
  raw_workout = query_model(prompt)
 
73
  if "Error" in raw_workout:
74
  st.error(f"API Error: {raw_workout}")
75
  else:
76
+ # Save workout to session state so it persists during reload
77
+ st.session_state.workout_plan = raw_workout
78
+
79
+ # --- DISPLAY SECTION (Outside the button to handle reloads) ---
80
+ if st.session_state.assessment_html:
81
+ st.markdown(st.session_state.assessment_html, unsafe_allow_html=True)
82
+
83
+ if st.session_state.workout_plan:
84
+ st.markdown("### ๐Ÿ“‹ Your 5-Day Routine")
85
+ raw_workout = st.session_state.workout_plan
86
+ days = ["Day 1:", "Day 2:", "Day 3:", "Day 4:", "Day 5:"]
87
+
88
+ for i in range(len(days)):
89
+ start = raw_workout.find(days[i])
90
+ if start != -1:
91
+ end = raw_workout.find(days[i+1]) if i+1 < len(days) else len(raw_workout)
92
+ day_content = raw_workout[start:end].strip()
93
+ st.markdown(f'<div class="day-card">{day_content}</div>', unsafe_allow_html=True)
94
+
95
+ st.write("---")
96
+ st.download_button(
97
+ label="๐Ÿ“ฅ Download Full Plan",
98
+ data=st.session_state.workout_plan,
99
+ file_name=f"{name}_Workout_Plan.txt",
100
+ mime="text/plain"
101
+ )