srbhavya01 commited on
Commit
898f1c9
Β·
verified Β·
1 Parent(s): da103d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +125 -60
app.py CHANGED
@@ -1,118 +1,183 @@
1
  import streamlit as st
 
2
  from auth import generate_otp, create_jwt, verify_jwt
3
  from emails_utils import send_otp_email
4
- from dotenv import load_dotenv
5
  from model_api import query_model
6
  from prompt_builder import build_prompt
7
 
8
  load_dotenv()
9
 
10
- st.set_page_config(page_title="FitPlan AI", page_icon="πŸ‹οΈ", layout="centered")
11
-
12
- # ---------------- SESSION STATE ---------------- #
 
 
 
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  if "logged_in" not in st.session_state:
15
  st.session_state.logged_in = False
16
 
17
- if "otp_sent" not in st.session_state:
18
- st.session_state.otp_sent = False
19
-
20
  if "otp" not in st.session_state:
21
  st.session_state.otp = None
22
 
23
 
24
- # ---------------- LOGIN PAGE ---------------- #
 
 
25
 
26
  if not st.session_state.logged_in:
27
 
28
- st.title("πŸ” FitPlan AI - OTP Login")
29
 
30
- email = st.text_input("Enter your Email")
 
31
 
32
- if not st.session_state.otp_sent:
33
 
34
  if st.button("Send OTP"):
35
 
36
- otp = generate_otp()
 
 
37
 
38
- st.session_state.otp = otp
39
- st.session_state.email = email
40
- st.session_state.otp_sent = True
41
-
42
- send_otp_email(email, otp)
43
 
44
- st.success("OTP sent to your email")
45
 
46
- else:
 
47
 
48
- otp_input = st.text_input("Enter OTP")
49
 
50
  if st.button("Verify OTP"):
51
 
52
- if otp_input == st.session_state.otp:
53
 
54
- token = create_jwt(st.session_state.email)
55
 
56
- st.session_state.jwt = token
57
  st.session_state.logged_in = True
58
 
59
- st.success("Login Successful")
60
  st.rerun()
61
 
62
  else:
63
  st.error("Invalid OTP")
64
 
 
 
65
  st.stop()
66
 
67
 
68
- # ---------------- APP CONTENT ---------------- #
 
 
69
 
70
- st.title("πŸ‹οΈ AI Personalized 5-Day Workout Planner")
71
 
72
- name = st.text_input("Name")
73
 
74
- age = st.number_input("Age", 0, 100)
75
 
76
- gender = st.selectbox("Gender", ["Male", "Female", "Other"])
77
 
78
- height = st.number_input("Height (cm)", 0, 250)
79
 
80
- weight = st.number_input("Weight (kg)", 0, 200)
 
 
 
81
 
82
- goal = st.selectbox(
83
- "Fitness Goal",
84
- ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexibility"]
85
- )
86
 
87
- fitness_level = st.selectbox(
88
- "Fitness Level",
89
- ["Beginner", "Intermediate", "Advanced"]
90
- )
91
 
92
- equipment = st.multiselect(
93
- "Equipment",
94
- [
95
- "Dumbbells",
96
- "Resistance Band",
97
- "Yoga Mat",
98
- "Skipping Rope",
99
- "Pullups Bar",
100
- "Inclined Bench",
101
- "Weight Plates"
102
- ]
103
- )
104
 
105
- if st.button("Generate 5-Day Plan πŸ’ͺ"):
 
 
 
 
 
 
 
106
 
107
- prompt, bmi, bmi_status = build_prompt(
108
- name, age, gender, height, weight,
109
- goal, fitness_level, equipment
 
 
 
 
 
 
 
 
110
  )
111
 
112
- st.subheader(f"BMI: {bmi:.2f} ({bmi_status})")
 
 
 
 
 
 
 
 
 
113
 
114
- with st.spinner("Generating workout plan..."):
115
- result = query_model(prompt)
116
 
117
- st.markdown("## πŸ—“οΈ Your 5-Day Workout Plan")
118
- st.markdown(result)
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from dotenv import load_dotenv
3
  from auth import generate_otp, create_jwt, verify_jwt
4
  from emails_utils import send_otp_email
 
5
  from model_api import query_model
6
  from prompt_builder import build_prompt
7
 
8
  load_dotenv()
9
 
10
+ # ---------- PAGE CONFIG ----------
11
+ st.set_page_config(
12
+ page_title="AI Fitness Planner",
13
+ page_icon="πŸ’ͺ",
14
+ layout="centered"
15
+ )
16
 
17
+ # ---------- CUSTOM CSS ----------
18
+ st.markdown("""
19
+ <style>
20
+
21
+ .stApp{
22
+ background-image: url("https://images.unsplash.com/photo-1571019613914-85f342c55f2b");
23
+ background-size: cover;
24
+ }
25
+
26
+ .title{
27
+ text-align:center;
28
+ font-size:40px;
29
+ font-weight:bold;
30
+ color:white;
31
+ }
32
+
33
+ .card{
34
+ background: rgba(0,0,0,0.6);
35
+ padding:30px;
36
+ border-radius:15px;
37
+ }
38
+
39
+ label{
40
+ color:white !important;
41
+ font-weight:bold;
42
+ }
43
+
44
+ </style>
45
+ """, unsafe_allow_html=True)
46
+
47
+ # ---------- SESSION ----------
48
  if "logged_in" not in st.session_state:
49
  st.session_state.logged_in = False
50
 
 
 
 
51
  if "otp" not in st.session_state:
52
  st.session_state.otp = None
53
 
54
 
55
+ # =====================================================
56
+ # πŸ” LOGIN PAGE
57
+ # =====================================================
58
 
59
  if not st.session_state.logged_in:
60
 
61
+ st.markdown('<div class="title">πŸ‹οΈ FitPlan AI Login</div>', unsafe_allow_html=True)
62
 
63
+ with st.container():
64
+ st.markdown('<div class="card">', unsafe_allow_html=True)
65
 
66
+ email = st.text_input("πŸ“§ Enter Email")
67
 
68
  if st.button("Send OTP"):
69
 
70
+ if email:
71
+ otp = generate_otp()
72
+ st.session_state.otp = otp
73
 
74
+ send_otp_email(email, otp)
 
 
 
 
75
 
76
+ st.success("OTP sent to your email")
77
 
78
+ else:
79
+ st.warning("Please enter email")
80
 
81
+ user_otp = st.text_input("πŸ”‘ Enter OTP")
82
 
83
  if st.button("Verify OTP"):
84
 
85
+ if user_otp == st.session_state.otp:
86
 
87
+ token = create_jwt(email)
88
 
89
+ st.session_state.token = token
90
  st.session_state.logged_in = True
91
 
92
+ st.success("Login Successful πŸŽ‰")
93
  st.rerun()
94
 
95
  else:
96
  st.error("Invalid OTP")
97
 
98
+ st.markdown("</div>", unsafe_allow_html=True)
99
+
100
  st.stop()
101
 
102
 
103
+ # =====================================================
104
+ # πŸ’ͺ WORKOUT GENERATOR PAGE
105
+ # =====================================================
106
 
107
+ st.markdown('<div class="title">πŸ’ͺ AI Personalized 5-Day Workout Planner</div>', unsafe_allow_html=True)
108
 
109
+ with st.container():
110
 
111
+ st.markdown('<div class="card">', unsafe_allow_html=True)
112
 
113
+ name = st.text_input("Name")
114
 
115
+ age = st.number_input("Age", 10, 80)
116
 
117
+ gender = st.selectbox(
118
+ "Gender",
119
+ ["Male", "Female", "Other"]
120
+ )
121
 
122
+ height = st.number_input("Height (cm)", 100, 250)
 
 
 
123
 
124
+ weight = st.number_input("Weight (kg)", 30, 200)
 
 
 
125
 
126
+ goal = st.selectbox(
127
+ "Fitness Goal",
128
+ [
129
+ "Build Muscle",
130
+ "Weight Loss",
131
+ "Strength Gain",
132
+ "Abs Building",
133
+ "Flexibility"
134
+ ]
135
+ )
 
 
136
 
137
+ fitness_level = st.selectbox(
138
+ "Fitness Level",
139
+ [
140
+ "Beginner",
141
+ "Intermediate",
142
+ "Advanced"
143
+ ]
144
+ )
145
 
146
+ equipment = st.multiselect(
147
+ "Available Equipment",
148
+ [
149
+ "Dumbbells",
150
+ "Resistance Band",
151
+ "Yoga Mat",
152
+ "Skipping Rope",
153
+ "Pullups Bar",
154
+ "Inclined Bench",
155
+ "Weight Plates"
156
+ ]
157
  )
158
 
159
+ if st.button("Generate 5-Day Plan πŸ’ͺ"):
160
+
161
+ prompt, bmi, bmi_status = build_prompt(
162
+ name, age, gender,
163
+ height, weight,
164
+ goal, fitness_level,
165
+ equipment
166
+ )
167
+
168
+ st.subheader(f"πŸ“Š BMI: {bmi:.2f} ({bmi_status})")
169
 
170
+ with st.spinner("Generating your AI workout plan..."):
 
171
 
172
+ result = query_model(prompt)
173
+
174
+ st.markdown("## πŸ—“οΈ Your Workout Plan")
175
+ st.markdown(result)
176
+
177
+ st.markdown("</div>", unsafe_allow_html=True)
178
+
179
+
180
+ # ---------- LOGOUT ----------
181
+ if st.button("Logout"):
182
+ st.session_state.logged_in = False
183
+ st.rerun()