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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -131
app.py CHANGED
@@ -1,183 +1,114 @@
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()
 
1
  import streamlit as st
2
+ from auth import generate_otp, create_jwt
 
3
  from emails_utils import send_otp_email
 
 
4
 
5
+ st.set_page_config(page_title="FitPlan AI", layout="centered")
6
 
7
+ # ------------------ CUSTOM CSS ------------------
 
 
 
 
 
8
 
 
9
  st.markdown("""
10
  <style>
11
 
12
  .stApp{
13
+ background: linear-gradient(135deg,#0f172a,#020617);
14
+ color:white;
15
+ }
16
+
17
+ .login-card{
18
+ background: rgba(0,0,0,0.65);
19
+ padding:40px;
20
+ border-radius:20px;
21
+ width:400px;
22
+ margin:auto;
23
+ box-shadow:0 10px 30px rgba(0,0,0,0.6);
24
  }
25
 
26
  .title{
27
  text-align:center;
28
+ font-size:34px;
29
+ font-weight:700;
30
+ margin-bottom:25px;
31
  }
32
 
33
+ .stTextInput input{
34
+ background:#111827;
35
+ color:white;
36
+ border-radius:10px;
37
  }
38
 
39
+ .stButton>button{
40
+ width:100%;
41
+ background:linear-gradient(90deg,#2563eb,#6366f1);
42
+ color:white;
43
+ border-radius:12px;
44
  font-weight:bold;
45
+ height:45px;
46
+ }
47
+
48
+ .otp-box{
49
+ text-align:center;
50
+ letter-spacing:10px;
51
+ font-size:20px;
52
  }
53
 
54
  </style>
55
  """, unsafe_allow_html=True)
56
 
57
+ # ------------------ SESSION ------------------
58
+
59
  if "logged_in" not in st.session_state:
60
  st.session_state.logged_in = False
61
 
62
  if "otp" not in st.session_state:
63
  st.session_state.otp = None
64
 
65
+ # ------------------ LOGIN SCREEN ------------------
 
 
 
66
 
67
  if not st.session_state.logged_in:
68
 
69
+ st.markdown('<div class="login-card">', unsafe_allow_html=True)
 
 
 
70
 
71
+ st.markdown('<div class="title">🔐 Login To Your Account</div>', unsafe_allow_html=True)
72
 
73
+ email = st.text_input("Email")
74
 
75
+ if st.button("Send OTP"):
 
 
76
 
77
+ if email:
78
 
79
+ otp = generate_otp()
80
+ st.session_state.otp = otp
81
 
82
+ send_otp_email(email, otp)
 
83
 
84
+ st.success("OTP sent to your email")
85
 
86
+ else:
87
+ st.warning("Enter email first")
88
 
89
+ user_otp = st.text_input("Enter OTP", max_chars=6)
90
 
91
+ if st.button("Verify OTP"):
92
 
93
+ if user_otp == st.session_state.otp:
 
94
 
95
+ token = create_jwt(email)
 
 
 
 
 
 
 
 
96
 
97
+ st.session_state.logged_in = True
98
+ st.session_state.token = token
99
 
100
+ st.success("Login Successful")
101
+ st.rerun()
 
102
 
103
+ else:
104
+ st.error("Invalid OTP")
105
 
106
+ st.markdown('</div>', unsafe_allow_html=True)
107
 
108
+ st.stop()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
+ # ------------------ AFTER LOGIN ------------------
111
 
112
+ st.title("🏋️ AI Personalized 5-Day Workout Planner")
113
 
114
+ st.success("Login successful! Now generate your workout plan.")