Amrutha04 commited on
Commit
782fcdb
·
verified ·
1 Parent(s): 1cb60d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -27
app.py CHANGED
@@ -5,88 +5,116 @@ 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 your UI)
9
  st.markdown("""
10
  <style>
11
- .stApp { background: linear-gradient(135deg, #f6d365 0%, #fda085 100%); background-attachment: fixed; }
 
 
 
12
  section[data-testid="stSidebar"] {
13
  background-color: #000000 !important;
14
  }
15
  section[data-testid="stSidebar"] h1, section[data-testid="stSidebar"] p {
16
  color: #FFFFFF !important;
17
  }
18
- h1, h2, h3, p, label { color: #2D3436 !important; font-weight: 600; }
 
 
 
19
  .result-card {
20
- background-color: white !important; padding: 25px; border-radius: 15px;
21
- border-left: 10px solid #004d57; color: #000000 !important; margin-bottom: 20px;
 
 
 
 
22
  }
23
  .day-card {
24
- background-color: #ffffff !important; padding: 20px; border-radius: 12px;
25
- margin-bottom: 15px; border-left: 8px solid #004d57; color: #000000 !important;
 
 
 
 
26
  white-space: pre-wrap !important;
27
  }
28
  </style>
29
  """, unsafe_allow_html=True)
30
 
31
- # --- RESTORED SIDEBAR ---
32
  with st.sidebar:
33
  st.markdown("# 👤 Personalised Fitness Plan")
34
  st.write("---")
35
  st.write("Professional AI Fitness Coaching.")
36
- st.info("Your data is used to calculate BMI and customize exercise intensity.")
37
 
38
  # --- MAIN CONTENT ---
39
  st.title("🏋️ Create Your Fitness Profile")
40
 
41
  # Input Section
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
  if st.button("Submit Profile"):
56
  if not name or height <= 0 or weight <= 0:
57
- st.error("Please fill in all details.")
58
  else:
59
- # Calling the prompt builder with 4 return values
60
  prompt, bmi, bmi_status, status_color = build_prompt(name, gender, height, weight, goal, level, equip)
61
 
 
62
  st.markdown(f"""
63
  <div class="result-card">
64
  <h2>Assessment for {name}</h2>
65
- <p>BMI: <strong>{bmi:.2f}</strong> | Category: <span style="color:{status_color}">{bmi_status}</span></p>
 
66
  </div>
67
  """, unsafe_allow_html=True)
68
 
 
69
  with st.spinner("AI Trainer is thinking..."):
70
  raw_workout = query_model(prompt)
71
 
72
  if "Error" in raw_workout:
73
- st.error(raw_workout)
74
  else:
75
  st.markdown("### 📋 Your 5-Day Routine")
 
 
76
  days = ["Day 1:", "Day 2:", "Day 3:", "Day 4:", "Day 5:"]
77
 
 
78
  for i in range(len(days)):
79
  start = raw_workout.find(days[i])
80
  if start != -1:
 
81
  end = raw_workout.find(days[i+1]) if i+1 < len(days) else len(raw_workout)
82
  day_content = raw_workout[start:end].strip()
 
 
83
  st.markdown(f'<div class="day-card">{day_content}</div>', unsafe_allow_html=True)
84
- # In app.py - add this after the for loop that displays the day-cards
85
- if not "Error" in raw_workout:
86
- st.write("---")
87
- st.download_button(
88
- label="Download Full 5-Day Plan as Text",
89
- data=raw_workout,
90
- file_name=f"{name}_Fitness_Plan.txt",
91
- mime="text/plain"
92
- )
 
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")
48
  st.write("---")
49
  st.write("Professional AI Fitness Coaching.")
 
50
 
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
+ )