Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# 1. Page Configuration
|
| 6 |
+
st.set_page_config(page_title="Fitness Profile Generator", layout="wide")
|
| 7 |
+
|
| 8 |
+
# 2. Load AI Model (Large Version)
|
| 9 |
+
@st.cache_resource
|
| 10 |
+
def load_model():
|
| 11 |
+
# Note: flan-t5-large is ~3GB. Ensure your Hugging Face Space has enough RAM.
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-large")
|
| 13 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large")
|
| 14 |
+
return tokenizer, model
|
| 15 |
+
|
| 16 |
+
tokenizer, model = load_model()
|
| 17 |
+
|
| 18 |
+
# 3. Custom Styling (Gradient and Black Sidebar)
|
| 19 |
+
st.markdown("""
|
| 20 |
+
<style>
|
| 21 |
+
.stApp {
|
| 22 |
+
background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
|
| 23 |
+
background-attachment: fixed;
|
| 24 |
+
}
|
| 25 |
+
section[data-testid="stSidebar"] {
|
| 26 |
+
background-color: #000000 !important;
|
| 27 |
+
}
|
| 28 |
+
section[data-testid="stSidebar"] h1, section[data-testid="stSidebar"] p {
|
| 29 |
+
color: #FFFFFF !important;
|
| 30 |
+
}
|
| 31 |
+
h1, h2, h3, p, label {
|
| 32 |
+
color: #2D3436 !important;
|
| 33 |
+
font-weight: 600;
|
| 34 |
+
}
|
| 35 |
+
div[data-baseweb="input"], div[data-baseweb="select"] {
|
| 36 |
+
background-color: rgba(255, 255, 255, 0.9) !important;
|
| 37 |
+
border-radius: 8px !important;
|
| 38 |
+
}
|
| 39 |
+
.stButton > button {
|
| 40 |
+
background-color: #004d57 !important;
|
| 41 |
+
color: white !important;
|
| 42 |
+
border-radius: 8px !important;
|
| 43 |
+
padding: 10px 24px !important;
|
| 44 |
+
font-weight: bold !important;
|
| 45 |
+
width: 100% !important;
|
| 46 |
+
border: none !important;
|
| 47 |
+
}
|
| 48 |
+
.result-card {
|
| 49 |
+
background-color: white;
|
| 50 |
+
padding: 25px;
|
| 51 |
+
border-radius: 15px;
|
| 52 |
+
box-shadow: 0 10px 25px rgba(0,0,0,0.1);
|
| 53 |
+
margin-top: 25px;
|
| 54 |
+
border-left: 10px solid #004d57;
|
| 55 |
+
}
|
| 56 |
+
</style>
|
| 57 |
+
""", unsafe_allow_html=True)
|
| 58 |
+
|
| 59 |
+
# --- SIDEBAR ---
|
| 60 |
+
with st.sidebar:
|
| 61 |
+
st.markdown("# 👤 Personalised Fitness Plan Generator")
|
| 62 |
+
st.write("---")
|
| 63 |
+
st.write("Your digital coach for a healthier lifestyle.")
|
| 64 |
+
|
| 65 |
+
# --- MAIN CONTENT ---
|
| 66 |
+
st.title("🏋️ Create Your Fitness Profile")
|
| 67 |
+
|
| 68 |
+
# SECTION 1: PERSONAL INFORMATION
|
| 69 |
+
st.markdown("### 1️⃣ Personal Information")
|
| 70 |
+
col_name, col_gender, col_age = st.columns([2, 1, 1])
|
| 71 |
+
with col_name:
|
| 72 |
+
name = st.text_input("Full Name *", placeholder="e.g. John Doe")
|
| 73 |
+
with col_gender:
|
| 74 |
+
gender = st.selectbox("Gender *", ["Male", "Female", "Other"])
|
| 75 |
+
with col_age:
|
| 76 |
+
age = st.number_input("Age *", min_value=1, max_value=120, value=25)
|
| 77 |
+
|
| 78 |
+
col_h, col_w = st.columns(2)
|
| 79 |
+
with col_h:
|
| 80 |
+
height_cm = st.number_input("Height in centimeters *", min_value=0.0, step=0.1)
|
| 81 |
+
with col_w:
|
| 82 |
+
weight_kg = st.number_input("Weight in kilograms *", min_value=0.0, step=0.1)
|
| 83 |
+
|
| 84 |
+
st.write("---")
|
| 85 |
+
|
| 86 |
+
# SECTION 2: FITNESS DETAILS
|
| 87 |
+
st.markdown("### 2️⃣ Fitness Details")
|
| 88 |
+
col_goal, col_level = st.columns(2)
|
| 89 |
+
with col_goal:
|
| 90 |
+
goal = st.selectbox("Fitness Goal", ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"])
|
| 91 |
+
with col_level:
|
| 92 |
+
fitness_level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
|
| 93 |
+
|
| 94 |
+
equipment = st.multiselect(
|
| 95 |
+
"Available Equipment *",
|
| 96 |
+
["Dumbbells", "Resistance Band", "Yoga Mat", "Kettlebells", "Pull-up Bar", "No Equipment"],
|
| 97 |
+
default=["No Equipment"]
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
st.write("---")
|
| 101 |
+
|
| 102 |
+
# --- SUBMIT BUTTON & LOGIC ---
|
| 103 |
+
if st.button("Submit Profile"):
|
| 104 |
+
if not name:
|
| 105 |
+
st.error("Please enter your name.")
|
| 106 |
+
elif height_cm <= 0 or weight_kg <= 0:
|
| 107 |
+
st.error("Please enter valid height and weight.")
|
| 108 |
+
elif not equipment:
|
| 109 |
+
st.error("Please select at least one equipment option.")
|
| 110 |
+
else:
|
| 111 |
+
height_m = height_cm / 100
|
| 112 |
+
bmi = weight_kg / (height_m ** 2)
|
| 113 |
+
bmi_rounded = round(bmi, 2)
|
| 114 |
+
|
| 115 |
+
if bmi_rounded < 18.5:
|
| 116 |
+
bmi_status, status_color = "Underweight", "#3498db"
|
| 117 |
+
elif 18.5 <= bmi_rounded < 25:
|
| 118 |
+
bmi_status, status_color = "Normal", "#2ecc71"
|
| 119 |
+
elif 25 <= bmi_rounded < 30:
|
| 120 |
+
bmi_status, status_color = "Overweight", "#f1c40f"
|
| 121 |
+
else:
|
| 122 |
+
bmi_status, status_color = "Obese", "#e74c3c"
|
| 123 |
+
|
| 124 |
+
st.success("Profile Submitted Successfully!")
|
| 125 |
+
|
| 126 |
+
st.markdown(f"""
|
| 127 |
+
<div class="result-card">
|
| 128 |
+
<h2 style="color: #004d57; margin-top:0;">Assessment for {name}</h2>
|
| 129 |
+
<p>{gender} | {age} Years Old</p>
|
| 130 |
+
<p>Calculated BMI: <strong>{bmi_rounded}</strong> | Category: <span style="color: {status_color}; font-weight: bold;">{bmi_status}</span></p>
|
| 131 |
+
</div>
|
| 132 |
+
""", unsafe_allow_html=True)
|