Update app.py
Browse files
app.py
CHANGED
|
@@ -1,150 +1,58 @@
|
|
| 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>
|
| 9 |
-
/* Full Page Background */
|
| 10 |
-
[data-testid="stAppViewContainer"] {
|
| 11 |
-
background: linear-gradient(rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.75)),
|
| 12 |
-
url("https://images.unsplash.com/photo-1517836357463-d25dfeac3438?q=80&w=2070&auto=format&fit=crop");
|
| 13 |
-
background-size: cover;
|
| 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;
|
| 26 |
-
padding: 3rem !important;
|
| 27 |
-
border-radius: 20px !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 {
|
| 35 |
-
color: #FFFFFF !important;
|
| 36 |
-
font-size: 60px !important;
|
| 37 |
-
font-weight: 850 !important;
|
| 38 |
-
text-align: center;
|
| 39 |
-
margin-bottom: 0px;
|
| 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;
|
| 47 |
-
font-size: 24px !important;
|
| 48 |
-
text-align: center;
|
| 49 |
-
margin-top: -10px;
|
| 50 |
-
margin-bottom: 40px;
|
| 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;
|
| 58 |
-
font-size: 22px !important;
|
| 59 |
-
font-weight: bold !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%;
|
| 74 |
-
background: linear-gradient(90deg, #f97316, #ea580c) !important;
|
| 75 |
-
color: white !important;
|
| 76 |
-
font-size: 20px !important;
|
| 77 |
-
font-weight: bold !important;
|
| 78 |
-
height: 3.5rem !important;
|
| 79 |
-
border-radius: 12px !important;
|
| 80 |
-
border: none !important;
|
| 81 |
-
margin-top: 20px;
|
| 82 |
-
}
|
| 83 |
-
</style>
|
| 84 |
-
""", unsafe_allow_html=True)
|
| 85 |
-
|
| 86 |
-
# --------------------------------------------------
|
| 87 |
-
# UI Header Section
|
| 88 |
-
# --------------------------------------------------
|
| 89 |
-
st.markdown('<p class="main-title">💪 FitPlan AI</p>', unsafe_allow_html=True)
|
| 90 |
-
st.markdown('<p class="sub-title">Your personalized gym companion</p>', unsafe_allow_html=True)
|
| 91 |
-
|
| 92 |
-
# --------------------------------------------------
|
| 93 |
-
# Fitness Profile Form
|
| 94 |
-
# --------------------------------------------------
|
| 95 |
-
with st.form("fitness_form", clear_on_submit=False):
|
| 96 |
-
st.markdown('<p class="form-header">🧍♂️ 1. PERSONAL INFORMATION</p>', unsafe_allow_html=True)
|
| 97 |
-
|
| 98 |
-
name = st.text_input("Full Name *", placeholder="Enter your full name")
|
| 99 |
-
|
| 100 |
-
col1, col2 = st.columns(2)
|
| 101 |
-
with col1:
|
| 102 |
-
height = st.number_input("Height (cm) *", min_value=0.0, step=1.0, value=0.0)
|
| 103 |
-
with col2:
|
| 104 |
-
weight = st.number_input("Weight (kg) *", min_value=0.0, step=0.1, value=0.0)
|
| 105 |
-
|
| 106 |
-
st.markdown("<br>", unsafe_allow_html=True)
|
| 107 |
-
st.markdown('<p class="form-header">🏋️ 2. FITNESS DETAILS</p>', unsafe_allow_html=True)
|
| 108 |
-
|
| 109 |
-
goal = st.selectbox("Fitness Goal", ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"])
|
| 110 |
-
|
| 111 |
-
equipment = st.multiselect("Available Equipment",
|
| 112 |
-
["Dumbbells", "Resistance Band", "Yoga Mat", "Kettlebell", "Pull-up Bar", "No Equipment"],
|
| 113 |
-
default=["No Equipment"])
|
| 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 |
-
|
| 128 |
-
|
| 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}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from model_api import query_model
|
| 3 |
+
from prompt_builder import build_prompt
|
| 4 |
+
|
| 5 |
+
st.set_page_config(page_title="FitPlan AI", layout="centered")
|
| 6 |
+
|
| 7 |
+
st.title("🏋️ FitPlan AI – Personalized Workout Generator")
|
| 8 |
+
|
| 9 |
+
# ---------------- INPUT ---------------- #
|
| 10 |
+
|
| 11 |
+
name = st.text_input("Enter Your Name")
|
| 12 |
+
|
| 13 |
+
gender = st.radio("Gender", ["Male", "Female"])
|
| 14 |
+
|
| 15 |
+
height = st.number_input("Height (cm)", min_value=100.0, max_value=250.0)
|
| 16 |
+
weight = st.number_input("Weight (kg)", min_value=30.0, max_value=200.0)
|
| 17 |
+
|
| 18 |
+
goal = st.selectbox(
|
| 19 |
+
"Fitness Goal",
|
| 20 |
+
["Build Muscle", "Lose Weight", "Improve Endurance", "General Fitness"]
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
fitness_level = st.radio(
|
| 24 |
+
"Fitness Level",
|
| 25 |
+
["Beginner", "Intermediate", "Advanced"]
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
equipment = st.multiselect(
|
| 29 |
+
"Available Equipment",
|
| 30 |
+
[
|
| 31 |
+
"No Equipment", "Dumbbells", "Barbell",
|
| 32 |
+
"Pull-up Bar", "Resistance Bands",
|
| 33 |
+
"Treadmill", "Kettlebells", "Full Gym"
|
| 34 |
+
]
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# ---------------- GENERATE ---------------- #
|
| 38 |
+
|
| 39 |
+
if st.button("Generate Workout Plan"):
|
| 40 |
+
|
| 41 |
+
if height > 0 and weight > 0:
|
| 42 |
+
|
| 43 |
+
prompt, bmi, bmi_status = build_prompt(
|
| 44 |
+
name, gender, height, weight,
|
| 45 |
+
goal, fitness_level, equipment
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
with st.spinner("Generating your personalized plan..."):
|
| 49 |
+
response = query_model(prompt)
|
| 50 |
+
|
| 51 |
+
st.subheader("📋 Your Personalized Workout Plan")
|
| 52 |
+
st.write(response)
|
| 53 |
+
|
| 54 |
+
st.info(f"Calculated BMI: {bmi:.2f} ({bmi_status})")
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
else:
|
| 57 |
+
st.warning("Please enter valid height and weight.")
|
| 58 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|