Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +51 -45
src/streamlit_app.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
def calculate_bmi(weight, height_cm):
|
| 5 |
-
# Convert height from cm to meters
|
| 6 |
height_m = height_cm / 100
|
| 7 |
-
# BMI formula: weight (kg) / (height in meters)^2
|
| 8 |
bmi = weight / (height_m ** 2)
|
| 9 |
return round(bmi, 2)
|
| 10 |
|
|
@@ -18,19 +19,27 @@ def get_category(bmi):
|
|
| 18 |
else:
|
| 19 |
return "Obese"
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
def load_model():
|
| 25 |
return pipeline(
|
| 26 |
"text-generation",
|
| 27 |
model="google/flan-t5-base"
|
| 28 |
)
|
| 29 |
-
|
| 30 |
generator = load_model()
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
with st.form("fitness_form"):
|
| 33 |
st.header("Personal Information")
|
|
|
|
| 34 |
name = st.text_input("Full Name*", placeholder="Enter your name")
|
| 35 |
|
| 36 |
col1, col2 = st.columns(2)
|
|
@@ -40,59 +49,56 @@ with st.form("fitness_form"):
|
|
| 40 |
weight = st.number_input("Weight (kg)*", min_value=1.0, step=0.1)
|
| 41 |
|
| 42 |
st.header("Fitness Details")
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
submit = st.form_submit_button("Generate
|
| 48 |
|
|
|
|
|
|
|
|
|
|
| 49 |
if submit:
|
| 50 |
-
|
| 51 |
if not name.strip():
|
| 52 |
st.error("Please enter your name.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
elif height <= 0 or weight <= 0:
|
| 54 |
st.error("Height and Weight must be positive values.")
|
|
|
|
| 55 |
else:
|
| 56 |
-
#
|
| 57 |
user_bmi = calculate_bmi(weight, height)
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
st.
|
| 62 |
-
st.
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
# Summary
|
| 66 |
-
st.write(f"**Goal:** {goal} | **Level:** {level}")
|
| 67 |
-
st.write(f"**Equipment:** {', '.join(equipment) if equipment else 'None selected'}")
|
| 68 |
-
if st.button("Submit Profile"):
|
| 69 |
-
|
| 70 |
-
if not name:
|
| 71 |
-
st.error("Please enter your name.")
|
| 72 |
-
|
| 73 |
-
elif not equipment:
|
| 74 |
-
st.error("Please select at least one equipment option.")
|
| 75 |
-
|
| 76 |
-
elif bmi is None:
|
| 77 |
-
st.error("Please enter valid height and weight.")
|
| 78 |
-
|
| 79 |
-
else:
|
| 80 |
-
st.success("✅ Profile Submitted Successfully!")
|
| 81 |
-
|
| 82 |
-
bmi_status = bmi_category(bmi)
|
| 83 |
equipment_list = ", ".join(equipment)
|
| 84 |
-
|
| 85 |
prompt = f"""
|
| 86 |
Generate a 5-day structured workout plan.
|
| 87 |
-
|
| 88 |
User Details:
|
| 89 |
Name: {name}
|
| 90 |
-
|
| 91 |
-
BMI: {bmi:.2f} ({bmi_status})
|
| 92 |
Goal: {goal}
|
| 93 |
-
Fitness Level: {
|
| 94 |
Available Equipment: {equipment_list}
|
| 95 |
-
|
| 96 |
Requirements:
|
| 97 |
- Include warmup
|
| 98 |
- Include exercises with sets and reps
|
|
@@ -100,9 +106,9 @@ if st.button("Submit Profile"):
|
|
| 100 |
- Adjust intensity based on BMI and fitness level
|
| 101 |
- Keep it structured day-wise
|
| 102 |
"""
|
| 103 |
-
|
| 104 |
with st.spinner("Generating your AI workout plan..."):
|
| 105 |
result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
|
| 106 |
-
|
| 107 |
st.subheader("🏋️ Your Personalized Workout Plan")
|
| 108 |
-
st.write(result)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# -----------------------------
|
| 5 |
+
# BMI Functions
|
| 6 |
+
# -----------------------------
|
| 7 |
def calculate_bmi(weight, height_cm):
|
|
|
|
| 8 |
height_m = height_cm / 100
|
|
|
|
| 9 |
bmi = weight / (height_m ** 2)
|
| 10 |
return round(bmi, 2)
|
| 11 |
|
|
|
|
| 19 |
else:
|
| 20 |
return "Obese"
|
| 21 |
|
| 22 |
+
# -----------------------------
|
| 23 |
+
# Load AI Model
|
| 24 |
+
# -----------------------------
|
| 25 |
+
@st.cache_resource
|
| 26 |
def load_model():
|
| 27 |
return pipeline(
|
| 28 |
"text-generation",
|
| 29 |
model="google/flan-t5-base"
|
| 30 |
)
|
| 31 |
+
|
| 32 |
generator = load_model()
|
| 33 |
|
| 34 |
+
# -----------------------------
|
| 35 |
+
# UI
|
| 36 |
+
# -----------------------------
|
| 37 |
+
st.set_page_config(page_title="FitPlan-AI", page_icon="💪")
|
| 38 |
+
st.title("💪 FitPlan-AI: Personalized Fitness Profile")
|
| 39 |
+
|
| 40 |
with st.form("fitness_form"):
|
| 41 |
st.header("Personal Information")
|
| 42 |
+
|
| 43 |
name = st.text_input("Full Name*", placeholder="Enter your name")
|
| 44 |
|
| 45 |
col1, col2 = st.columns(2)
|
|
|
|
| 49 |
weight = st.number_input("Weight (kg)*", min_value=1.0, step=0.1)
|
| 50 |
|
| 51 |
st.header("Fitness Details")
|
| 52 |
+
|
| 53 |
+
goal = st.selectbox(
|
| 54 |
+
"Fitness Goal",
|
| 55 |
+
["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
|
| 59 |
+
|
| 60 |
+
equipment = st.multiselect(
|
| 61 |
+
"Available Equipment",
|
| 62 |
+
["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment", "Kettlebell", "Pull-up Bar"]
|
| 63 |
+
)
|
| 64 |
|
| 65 |
+
submit = st.form_submit_button("Generate Workout Plan")
|
| 66 |
|
| 67 |
+
# -----------------------------
|
| 68 |
+
# When Form is Submitted
|
| 69 |
+
# -----------------------------
|
| 70 |
if submit:
|
| 71 |
+
|
| 72 |
if not name.strip():
|
| 73 |
st.error("Please enter your name.")
|
| 74 |
+
|
| 75 |
+
elif not equipment:
|
| 76 |
+
st.error("Please select at least one equipment option.")
|
| 77 |
+
|
| 78 |
elif height <= 0 or weight <= 0:
|
| 79 |
st.error("Height and Weight must be positive values.")
|
| 80 |
+
|
| 81 |
else:
|
| 82 |
+
# Calculate BMI
|
| 83 |
user_bmi = calculate_bmi(weight, height)
|
| 84 |
+
bmi_status = get_category(user_bmi)
|
| 85 |
+
|
| 86 |
+
st.success(f"✅ Profile Created Successfully for {name}!")
|
| 87 |
+
st.metric("Your BMI", user_bmi)
|
| 88 |
+
st.info(f"Health Category: **{bmi_status}**")
|
| 89 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
equipment_list = ", ".join(equipment)
|
| 91 |
+
|
| 92 |
prompt = f"""
|
| 93 |
Generate a 5-day structured workout plan.
|
| 94 |
+
|
| 95 |
User Details:
|
| 96 |
Name: {name}
|
| 97 |
+
BMI: {user_bmi} ({bmi_status})
|
|
|
|
| 98 |
Goal: {goal}
|
| 99 |
+
Fitness Level: {level}
|
| 100 |
Available Equipment: {equipment_list}
|
| 101 |
+
|
| 102 |
Requirements:
|
| 103 |
- Include warmup
|
| 104 |
- Include exercises with sets and reps
|
|
|
|
| 106 |
- Adjust intensity based on BMI and fitness level
|
| 107 |
- Keep it structured day-wise
|
| 108 |
"""
|
| 109 |
+
|
| 110 |
with st.spinner("Generating your AI workout plan..."):
|
| 111 |
result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
|
| 112 |
+
|
| 113 |
st.subheader("🏋️ Your Personalized Workout Plan")
|
| 114 |
+
st.write(result)
|