Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +71 -51
src/streamlit_app.py
CHANGED
|
@@ -1,81 +1,101 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import
|
| 3 |
-
import torch
|
| 4 |
-
# -------------------------
|
| 5 |
-
# 1. Function to Craft Prompt
|
| 6 |
-
# -------------------------
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
Generate a {days}-day workout plan.
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
- Include warm-up
|
| 20 |
-
- Include exercises with sets and reps
|
| 21 |
-
- Include rest time
|
| 22 |
-
- Keep it structured day-wise
|
| 23 |
-
"""
|
| 24 |
|
| 25 |
-
|
| 26 |
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# -------------------------
|
| 29 |
-
# 2.
|
| 30 |
# -------------------------
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# -------------------------
|
| 42 |
-
#
|
| 43 |
# -------------------------
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# -------------------------
|
| 53 |
-
#
|
| 54 |
# -------------------------
|
| 55 |
|
| 56 |
-
if st.button("
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
else:
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
st.write("###
|
| 64 |
-
st.code(prompt)
|
| 65 |
|
| 66 |
-
|
| 67 |
-
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
max_new_tokens=300,
|
| 72 |
-
temperature=0.7,
|
| 73 |
-
do_sample=True
|
| 74 |
-
)
|
| 75 |
|
| 76 |
-
|
|
|
|
| 77 |
|
| 78 |
-
st.
|
|
|
|
| 79 |
|
| 80 |
-
st.subheader("🏋️ Your Workout Plan")
|
| 81 |
st.write(result)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Load model only once
|
| 5 |
+
@st.cache_resource
|
| 6 |
+
def load_model():
|
| 7 |
+
return pipeline("text-generation", model="google/flan-t5-base")
|
| 8 |
|
| 9 |
+
generator = load_model()
|
|
|
|
| 10 |
|
| 11 |
+
st.set_page_config(page_title="FitPlan AI - BMI Calculator", page_icon="💪")
|
| 12 |
+
st.title("💪 FitPlan AI - Fitness Profile & BMI Calculator")
|
| 13 |
+
|
| 14 |
+
st.write("Fill in your details to calculate your BMI and get AI workout plan.")
|
| 15 |
+
|
| 16 |
+
# -------------------------
|
| 17 |
+
# 1. Personal Information
|
| 18 |
+
# -------------------------
|
| 19 |
|
| 20 |
+
name = st.text_input("Enter Your Name *")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
gender = st.selectbox("Select Gender", ["Male", "Female", "Other"])
|
| 23 |
|
| 24 |
+
height_cm = st.number_input("Enter Height (in centimeters) *", min_value=0.0, format="%.2f")
|
| 25 |
+
weight_kg = st.number_input("Enter Weight (in kilograms) *", min_value=0.0, format="%.2f")
|
| 26 |
|
| 27 |
# -------------------------
|
| 28 |
+
# 2. Fitness Details
|
| 29 |
# -------------------------
|
| 30 |
|
| 31 |
+
st.subheader("Fitness Details")
|
| 32 |
+
|
| 33 |
+
goal = st.selectbox(
|
| 34 |
+
"Select Your Fitness Goal",
|
| 35 |
+
["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
|
| 36 |
+
)
|
| 37 |
|
| 38 |
+
equipment = st.multiselect(
|
| 39 |
+
"Available Equipment",
|
| 40 |
+
["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment"]
|
| 41 |
+
)
|
| 42 |
|
| 43 |
+
fitness_level = st.radio(
|
| 44 |
+
"Fitness Level",
|
| 45 |
+
["Beginner", "Intermediate", "Advanced"]
|
| 46 |
+
)
|
| 47 |
|
| 48 |
# -------------------------
|
| 49 |
+
# BMI Functions
|
| 50 |
# -------------------------
|
| 51 |
|
| 52 |
+
def calculate_bmi(weight, height_cm):
|
| 53 |
+
height_m = height_cm / 100
|
| 54 |
+
bmi = weight / (height_m ** 2)
|
| 55 |
+
return round(bmi, 2)
|
| 56 |
+
|
| 57 |
+
def bmi_category(bmi):
|
| 58 |
+
if bmi < 18.5:
|
| 59 |
+
return "Underweight"
|
| 60 |
+
elif bmi < 24.9:
|
| 61 |
+
return "Normal"
|
| 62 |
+
elif bmi < 29.9:
|
| 63 |
+
return "Overweight"
|
| 64 |
+
else:
|
| 65 |
+
return "Obese"
|
| 66 |
|
| 67 |
# -------------------------
|
| 68 |
+
# Submit Button
|
| 69 |
# -------------------------
|
| 70 |
|
| 71 |
+
if st.button("Submit Profile"):
|
| 72 |
|
| 73 |
+
# Validation
|
| 74 |
+
if not name:
|
| 75 |
+
st.error("Please enter your name.")
|
| 76 |
+
elif height_cm <= 0 or weight_kg <= 0:
|
| 77 |
+
st.error("Enter valid height and weight.")
|
| 78 |
+
elif not equipment:
|
| 79 |
+
st.error("Select at least one equipment option.")
|
| 80 |
else:
|
| 81 |
+
st.success("✅ Profile Submitted Successfully!")
|
| 82 |
+
|
| 83 |
+
# Calculate BMI
|
| 84 |
+
bmi = calculate_bmi(weight_kg, height_cm)
|
| 85 |
+
bmi_status = bmi_category(bmi)
|
| 86 |
|
| 87 |
+
st.write(f"### 📊 BMI: {bmi} ({bmi_status})")
|
|
|
|
| 88 |
|
| 89 |
+
equipment_list = ", ".join(equipment)
|
|
|
|
| 90 |
|
| 91 |
+
prompt = f"""
|
| 92 |
+
Generate a 5-day structured workout plan.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
+
Include warmup, exercises with sets & reps, rest time.
|
| 95 |
+
"""
|
| 96 |
|
| 97 |
+
with st.spinner("Generating your AI workout plan..."):
|
| 98 |
+
result = generator(prompt, max_new_tokens=400)[0]["generated_text"]
|
| 99 |
|
| 100 |
+
st.subheader("🏋️ Your Personalized Workout Plan")
|
| 101 |
st.write(result)
|