Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +46 -38
src/streamlit_app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
def calculate_bmi(weight, height_cm):
|
| 4 |
# Convert height from cm to meters
|
|
@@ -20,6 +21,50 @@ def get_category(bmi):
|
|
| 20 |
# App UI
|
| 21 |
st.set_page_config(page_title="FitPlan-AI", page_icon="💪")
|
| 22 |
st.title("💪 FitPlan-AI: Personalized Fitness Profile")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
if st.button("Submit Profile"):
|
| 24 |
|
| 25 |
if not name:
|
|
@@ -60,41 +105,4 @@ if st.button("Submit Profile"):
|
|
| 60 |
result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
|
| 61 |
|
| 62 |
st.subheader("🏋️ Your Personalized Workout Plan")
|
| 63 |
-
st.write(result)
|
| 64 |
-
|
| 65 |
-
with st.form("fitness_form"):
|
| 66 |
-
st.header("Personal Information")
|
| 67 |
-
name = st.text_input("Full Name*", placeholder="Enter your name")
|
| 68 |
-
|
| 69 |
-
col1, col2 = st.columns(2)
|
| 70 |
-
with col1:
|
| 71 |
-
height = st.number_input("Height (cm)*", min_value=1.0, step=0.1)
|
| 72 |
-
with col2:
|
| 73 |
-
weight = st.number_input("Weight (kg)*", min_value=1.0, step=0.1)
|
| 74 |
-
|
| 75 |
-
st.header("Fitness Details")
|
| 76 |
-
goal = st.selectbox("Fitness Goal", ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"])
|
| 77 |
-
level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
|
| 78 |
-
equipment = st.multiselect("Available Equipment", ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment", "Kettlebell", "Pull-up Bar"])
|
| 79 |
-
|
| 80 |
-
submit = st.form_submit_button("Generate Profile")
|
| 81 |
-
|
| 82 |
-
if submit:
|
| 83 |
-
# Validation: Ensure name is not empty
|
| 84 |
-
if not name.strip():
|
| 85 |
-
st.error("Please enter your name.")
|
| 86 |
-
elif height <= 0 or weight <= 0:
|
| 87 |
-
st.error("Height and Weight must be positive values.")
|
| 88 |
-
else:
|
| 89 |
-
# BMI Logic
|
| 90 |
-
user_bmi = calculate_bmi(weight, height)
|
| 91 |
-
category = get_category(user_bmi)
|
| 92 |
-
|
| 93 |
-
# Display Results
|
| 94 |
-
st.success(f"Profile Created Successfully for {name}!")
|
| 95 |
-
st.metric(label="Your Calculated BMI", value=user_bmi)
|
| 96 |
-
st.info(f"Health Category: **{category}**")
|
| 97 |
-
|
| 98 |
-
# Summary
|
| 99 |
-
st.write(f"**Goal:** {goal} | **Level:** {level}")
|
| 100 |
-
st.write(f"**Equipment:** {', '.join(equipment) if equipment else 'None selected'}")
|
|
|
|
| 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
|
|
|
|
| 21 |
# App UI
|
| 22 |
st.set_page_config(page_title="FitPlan-AI", page_icon="💪")
|
| 23 |
st.title("💪 FitPlan-AI: Personalized Fitness Profile")
|
| 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)
|
| 37 |
+
with col1:
|
| 38 |
+
height = st.number_input("Height (cm)*", min_value=1.0, step=0.1)
|
| 39 |
+
with col2:
|
| 40 |
+
weight = st.number_input("Weight (kg)*", min_value=1.0, step=0.1)
|
| 41 |
+
|
| 42 |
+
st.header("Fitness Details")
|
| 43 |
+
goal = st.selectbox("Fitness Goal", ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"])
|
| 44 |
+
level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
|
| 45 |
+
equipment = st.multiselect("Available Equipment", ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment", "Kettlebell", "Pull-up Bar"])
|
| 46 |
+
|
| 47 |
+
submit = st.form_submit_button("Generate Profile")
|
| 48 |
+
|
| 49 |
+
if submit:
|
| 50 |
+
# Validation: Ensure name is not empty
|
| 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 |
+
# BMI Logic
|
| 57 |
+
user_bmi = calculate_bmi(weight, height)
|
| 58 |
+
category = get_category(user_bmi)
|
| 59 |
+
|
| 60 |
+
# Display Results
|
| 61 |
+
st.success(f"Profile Created Successfully for {name}!")
|
| 62 |
+
st.metric(label="Your Calculated BMI", value=user_bmi)
|
| 63 |
+
st.info(f"Health Category: **{category}**")
|
| 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:
|
|
|
|
| 105 |
result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
|
| 106 |
|
| 107 |
st.subheader("🏋️ Your Personalized Workout Plan")
|
| 108 |
+
st.write(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|