Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +63 -34
src/streamlit_app.py
CHANGED
|
@@ -1,29 +1,16 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
import torch
|
|
|
|
| 4 |
|
| 5 |
# -------------------------
|
| 6 |
-
# Page Config
|
| 7 |
# -------------------------
|
| 8 |
|
| 9 |
st.set_page_config(page_title="FitPlan AI", page_icon="πͺ")
|
| 10 |
|
| 11 |
-
# π¨ Background Style
|
| 12 |
-
|
| 13 |
-
st.markdown(
|
| 14 |
-
"""
|
| 15 |
-
<style>
|
| 16 |
-
.stApp {
|
| 17 |
-
background-image: url("https://images.unsplash.com/photo-1554284126-aa88f22d8b74");
|
| 18 |
-
background-size: cover;
|
| 19 |
-
}
|
| 20 |
-
</style>
|
| 21 |
-
""",
|
| 22 |
-
unsafe_allow_html=True
|
| 23 |
-
)
|
| 24 |
-
|
| 25 |
# -------------------------
|
| 26 |
-
# Load Model
|
| 27 |
# -------------------------
|
| 28 |
|
| 29 |
@st.cache_resource
|
|
@@ -35,11 +22,10 @@ def load_model():
|
|
| 35 |
tokenizer, model = load_model()
|
| 36 |
|
| 37 |
# -------------------------
|
| 38 |
-
#
|
| 39 |
# -------------------------
|
| 40 |
|
| 41 |
st.title("πͺ FitPlan AI - BMI Calculator & Workout Planner")
|
| 42 |
-
st.write("Enter your details to get AI workout plan.")
|
| 43 |
|
| 44 |
# -------------------------
|
| 45 |
# Personal Info
|
|
@@ -94,6 +80,7 @@ def bmi_category(bmi):
|
|
| 94 |
|
| 95 |
if st.button("Generate Workout Plan"):
|
| 96 |
|
|
|
|
| 97 |
if not name:
|
| 98 |
st.error("Enter your name")
|
| 99 |
elif height_cm <= 0 or weight_kg <= 0:
|
|
@@ -101,31 +88,64 @@ if st.button("Generate Workout Plan"):
|
|
| 101 |
elif not equipment:
|
| 102 |
st.error("Select equipment")
|
| 103 |
else:
|
|
|
|
|
|
|
| 104 |
bmi = calculate_bmi(weight_kg, height_cm)
|
| 105 |
bmi_status = bmi_category(bmi)
|
| 106 |
|
| 107 |
-
st.success(f"BMI: {bmi} ({bmi_status})")
|
| 108 |
|
| 109 |
-
|
|
|
|
|
|
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
Day 1 β Chest & Triceps: Bench Press 4Γ8β10, Incline Press 3Γ10, Dips 3Γ12, Tricep Extensions 3Γ12.
|
| 117 |
|
| 118 |
-
|
|
|
|
| 119 |
|
| 120 |
-
|
|
|
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
"""
|
| 127 |
|
| 128 |
-
with st.spinner("
|
| 129 |
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
| 130 |
outputs = model.generate(
|
| 131 |
**inputs,
|
|
@@ -135,5 +155,14 @@ Day 5 β Cardio & Conditioning: 25-min Run, Skipping 3Γ2min, Burpees 3Γ12, Mo
|
|
| 135 |
)
|
| 136 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
import torch
|
| 4 |
+
import time
|
| 5 |
|
| 6 |
# -------------------------
|
| 7 |
+
# Page Config
|
| 8 |
# -------------------------
|
| 9 |
|
| 10 |
st.set_page_config(page_title="FitPlan AI", page_icon="πͺ")
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
# -------------------------
|
| 13 |
+
# Load Model
|
| 14 |
# -------------------------
|
| 15 |
|
| 16 |
@st.cache_resource
|
|
|
|
| 22 |
tokenizer, model = load_model()
|
| 23 |
|
| 24 |
# -------------------------
|
| 25 |
+
# Title
|
| 26 |
# -------------------------
|
| 27 |
|
| 28 |
st.title("πͺ FitPlan AI - BMI Calculator & Workout Planner")
|
|
|
|
| 29 |
|
| 30 |
# -------------------------
|
| 31 |
# Personal Info
|
|
|
|
| 80 |
|
| 81 |
if st.button("Generate Workout Plan"):
|
| 82 |
|
| 83 |
+
# Validation
|
| 84 |
if not name:
|
| 85 |
st.error("Enter your name")
|
| 86 |
elif height_cm <= 0 or weight_kg <= 0:
|
|
|
|
| 88 |
elif not equipment:
|
| 89 |
st.error("Select equipment")
|
| 90 |
else:
|
| 91 |
+
|
| 92 |
+
# BMI
|
| 93 |
bmi = calculate_bmi(weight_kg, height_cm)
|
| 94 |
bmi_status = bmi_category(bmi)
|
| 95 |
|
| 96 |
+
st.success(f"β
Welcome {name}! BMI: {bmi} ({bmi_status})")
|
| 97 |
|
| 98 |
+
# -------------------------
|
| 99 |
+
# Progress Bar Animation
|
| 100 |
+
# -------------------------
|
| 101 |
|
| 102 |
+
progress = st.progress(0)
|
| 103 |
+
status = st.empty()
|
| 104 |
+
|
| 105 |
+
for i in range(100):
|
| 106 |
+
time.sleep(0.01)
|
| 107 |
+
progress.progress(i + 1)
|
| 108 |
+
status.text("Generating personalized fitness plan...")
|
| 109 |
+
|
| 110 |
+
st.divider()
|
| 111 |
+
|
| 112 |
+
# -------------------------
|
| 113 |
+
# Core AI Module Layout
|
| 114 |
+
# -------------------------
|
| 115 |
+
|
| 116 |
+
st.subheader("π§ Core AI Inference Module")
|
| 117 |
+
|
| 118 |
+
col1, col2, col3 = st.columns(3)
|
| 119 |
|
| 120 |
+
with col1:
|
| 121 |
+
st.info("π½ Input Layer\nUser goals, equipment, fitness level")
|
|
|
|
| 122 |
|
| 123 |
+
with col2:
|
| 124 |
+
st.info("β Processing\nAI model analysis")
|
| 125 |
|
| 126 |
+
with col3:
|
| 127 |
+
st.info("π€ Output Layer\nWorkout plan")
|
| 128 |
|
| 129 |
+
st.divider()
|
| 130 |
+
|
| 131 |
+
# -------------------------
|
| 132 |
+
# Model Input & Output
|
| 133 |
+
# -------------------------
|
| 134 |
+
|
| 135 |
+
equipment_list = ", ".join(equipment)
|
| 136 |
+
|
| 137 |
+
prompt = f"""
|
| 138 |
+
Create a structured 5-day workout plan.
|
| 139 |
+
|
| 140 |
+
User:
|
| 141 |
+
Goal: {goal}
|
| 142 |
+
Fitness Level: {fitness_level}
|
| 143 |
+
Equipment: {equipment_list}
|
| 144 |
+
|
| 145 |
+
Include exercises with sets, reps, and rest time.
|
| 146 |
"""
|
| 147 |
|
| 148 |
+
with st.spinner("AI is creating your plan..."):
|
| 149 |
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
| 150 |
outputs = model.generate(
|
| 151 |
**inputs,
|
|
|
|
| 155 |
)
|
| 156 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 157 |
|
| 158 |
+
col4, col5 = st.columns(2)
|
| 159 |
+
|
| 160 |
+
with col4:
|
| 161 |
+
st.subheader("π₯ Model Input")
|
| 162 |
+
st.write(prompt)
|
| 163 |
+
|
| 164 |
+
with col5:
|
| 165 |
+
st.subheader("π€ Model Output")
|
| 166 |
+
st.write(result)
|
| 167 |
+
|
| 168 |
+
st.success("ποΈ Your Personalized Workout Plan Ready!")
|