js02vel commited on
Commit
e9f68f6
·
verified ·
1 Parent(s): b8d6e98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -59
app.py CHANGED
@@ -1,18 +1,8 @@
1
  import streamlit as st
2
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
- import torch
4
 
5
  # 1. Basic Configuration
6
  st.set_page_config(page_title="FitPlan AI", page_icon="💪", layout="centered")
7
 
8
- def load_model():
9
- tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
10
- model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
11
- return tokenizer, model
12
-
13
- tokenizer, model = load_model()
14
-
15
- generator = load_model()
16
  # 2. Enhanced CSS
17
  st.markdown("""
18
  <style>
@@ -24,10 +14,12 @@ st.markdown("""
24
  background-position: center;
25
  background-attachment: fixed;
26
  }
 
27
  /* Hide the "Press Enter to submit form" hint globally */
28
  [data-testid="InputInstructions"] {
29
  display: none !important;
30
  }
 
31
  /* Form Container Polish */
32
  div[data-testid="stForm"] {
33
  background-color: rgba(255, 255, 255, 0.98) !important;
@@ -36,6 +28,7 @@ st.markdown("""
36
  border: none !important;
37
  box-shadow: 0 15px 35px rgba(0,0,0,0.5);
38
  }
 
39
  /* --- FONT SIZE UPDATES --- */
40
  /* Main Title (FitPlan AI) */
41
  .main-title {
@@ -47,6 +40,7 @@ st.markdown("""
47
  text-shadow: 3px 3px 6px rgba(0,0,0,0.9);
48
  font-family: 'Helvetica Neue', sans-serif;
49
  }
 
50
  /* Subtitle (Your personalized gym companion) */
51
  .sub-title {
52
  color: #E0E0E0 !important;
@@ -57,6 +51,7 @@ st.markdown("""
57
  font-style: italic;
58
  text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
59
  }
 
60
  /* Form Section Headers (Orange) */
61
  .form-header {
62
  color: #f97316 !important;
@@ -65,12 +60,14 @@ st.markdown("""
65
  text-transform: uppercase;
66
  letter-spacing: 1px;
67
  }
 
68
  /* Labels for inputs */
69
  label p {
70
  font-size: 18px !important;
71
  color: #1e293b !important;
72
  font-weight: 600 !important;
73
  }
 
74
  /* Button Styling */
75
  .stButton > button {
76
  width: 100%;
@@ -117,53 +114,37 @@ with st.form("fitness_form", clear_on_submit=False):
117
 
118
  level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"], horizontal=True)
119
 
120
- # SUBMIT BUTTON
121
- if st.button(" Submit Profile"):
122
-
123
- if not name:
124
- st.error("Please enter your name.")
125
-
126
- elif height <= 0 or weight <= 0:
127
- st.error("Please enter valid height and weight.")
128
-
129
- elif not equipment:
130
- st.error("Please select at least one equipment option.")
131
-
132
  else:
133
- st.success(" Profile Submitted Successfully!")
134
-
135
- bmi_status = bmi_category(bmi)
136
- equipment_list = ", ".join(equipment)
137
-
138
- prompt = f"""
139
- You are a certified professional fitness trainer.
140
-
141
- Create a detailed 5-day workout plan.
142
-
143
- User Information:
144
- - Gender: {gender}
145
- - BMI: {bmi:.2f} ({bmi_status})
146
- - Goal: {goal}
147
- - Fitness Level: {fitness_level}
148
- - Equipment Available: {equipment_list}
149
-
150
- Start directly with:
151
-
152
- Day 1:
153
- """
154
-
155
- with st.spinner("Generating your AI workout plan..."):
156
-
157
- inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
158
-
159
- outputs = model.generate(
160
- **inputs,
161
- max_new_tokens=900,
162
- temperature=0.7,
163
- do_sample=True
164
- )
165
-
166
- result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
167
-
168
- st.subheader(" Your Personalized Workout Plan")
169
- st.write(result)
 
1
  import streamlit as st
 
 
2
 
3
  # 1. Basic Configuration
4
  st.set_page_config(page_title="FitPlan AI", page_icon="💪", layout="centered")
5
 
 
 
 
 
 
 
 
 
6
  # 2. Enhanced CSS
7
  st.markdown("""
8
  <style>
 
14
  background-position: center;
15
  background-attachment: fixed;
16
  }
17
+
18
  /* Hide the "Press Enter to submit form" hint globally */
19
  [data-testid="InputInstructions"] {
20
  display: none !important;
21
  }
22
+
23
  /* Form Container Polish */
24
  div[data-testid="stForm"] {
25
  background-color: rgba(255, 255, 255, 0.98) !important;
 
28
  border: none !important;
29
  box-shadow: 0 15px 35px rgba(0,0,0,0.5);
30
  }
31
+
32
  /* --- FONT SIZE UPDATES --- */
33
  /* Main Title (FitPlan AI) */
34
  .main-title {
 
40
  text-shadow: 3px 3px 6px rgba(0,0,0,0.9);
41
  font-family: 'Helvetica Neue', sans-serif;
42
  }
43
+
44
  /* Subtitle (Your personalized gym companion) */
45
  .sub-title {
46
  color: #E0E0E0 !important;
 
51
  font-style: italic;
52
  text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
53
  }
54
+
55
  /* Form Section Headers (Orange) */
56
  .form-header {
57
  color: #f97316 !important;
 
60
  text-transform: uppercase;
61
  letter-spacing: 1px;
62
  }
63
+
64
  /* Labels for inputs */
65
  label p {
66
  font-size: 18px !important;
67
  color: #1e293b !important;
68
  font-weight: 600 !important;
69
  }
70
+
71
  /* Button Styling */
72
  .stButton > button {
73
  width: 100%;
 
114
 
115
  level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"], horizontal=True)
116
 
117
+ # Submission Button
118
+ submit = st.form_submit_button("GENERATE MY PLAN")
119
+
120
+ # --------------------------------------------------
121
+ # Logic & Calculation
122
+ # --------------------------------------------------
123
+ if submit:
124
+ if not name.strip() or height <= 50 or weight <= 10:
125
+ st.error("🚨 Please provide a valid name, height, and weight.")
 
 
 
126
  else:
127
+ # BMI Calculation
128
+ height_m = height / 100
129
+ bmi = round(weight / (height_m ** 2), 2)
130
+
131
+ if bmi < 18.5:
132
+ cat, color = "Underweight", "blue"
133
+ elif 18.5 <= bmi < 25:
134
+ cat, color = "Normal", "green"
135
+ elif 25 <= bmi < 30:
136
+ cat, color = "Overweight", "orange"
137
+ else:
138
+ cat, color = "Obese", "red"
139
+
140
+ # Results Display
141
+ st.balloons()
142
+ st.success(f"✅ Profile created for {name}")
143
+
144
+ c1, c2 = st.columns(2)
145
+ with c1:
146
+ st.metric("Calculated BMI", bmi)
147
+ with c2:
148
+ st.markdown(f"### Status: :{color}[{cat}]")
149
+
150
+ st.info(f"**Goal:** {goal} | **Experience:** {level}")