Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
-
#
|
|
|
|
|
|
|
| 25 |
|
| 26 |
if not st.session_state.logged_in:
|
| 27 |
|
| 28 |
-
st.
|
| 29 |
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
|
| 34 |
if st.button("Send OTP"):
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
st.session_state.email = email
|
| 40 |
-
st.session_state.otp_sent = True
|
| 41 |
-
|
| 42 |
-
send_otp_email(email, otp)
|
| 43 |
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
|
| 50 |
if st.button("Verify OTP"):
|
| 51 |
|
| 52 |
-
if
|
| 53 |
|
| 54 |
-
token = create_jwt(
|
| 55 |
|
| 56 |
-
st.session_state.
|
| 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 |
-
#
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
st.
|
| 71 |
|
| 72 |
-
|
| 73 |
|
| 74 |
-
|
| 75 |
|
| 76 |
-
|
| 77 |
|
| 78 |
-
|
| 79 |
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
-
"Fitness Goal",
|
| 84 |
-
["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexibility"]
|
| 85 |
-
)
|
| 86 |
|
| 87 |
-
|
| 88 |
-
"Fitness Level",
|
| 89 |
-
["Beginner", "Intermediate", "Advanced"]
|
| 90 |
-
)
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
]
|
| 103 |
-
)
|
| 104 |
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
)
|
| 111 |
|
| 112 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
-
|
| 115 |
-
result = query_model(prompt)
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|