Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +43 -85
src/streamlit_app.py
CHANGED
|
@@ -1,36 +1,25 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import torch
|
| 3 |
-
import random
|
| 4 |
-
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 5 |
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
# Page Config
|
| 9 |
-
# -------------------------
|
| 10 |
-
|
| 11 |
-
st.set_page_config(page_title="FitPlan AI", page_icon="πͺ")
|
| 12 |
|
| 13 |
-
st.
|
| 14 |
-
|
| 15 |
-
st.write("Fill your details to generate AI workout plan.")
|
| 16 |
|
| 17 |
# -------------------------
|
| 18 |
-
#
|
| 19 |
# -------------------------
|
| 20 |
|
| 21 |
-
|
| 22 |
-
def load_model():
|
| 23 |
-
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-large")
|
| 24 |
-
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large")
|
| 25 |
-
return tokenizer, model
|
| 26 |
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
# -------------------------
|
| 30 |
-
#
|
| 31 |
# -------------------------
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
goal = st.selectbox(
|
| 36 |
"Select Your Fitness Goal",
|
|
@@ -38,87 +27,56 @@ goal = st.selectbox(
|
|
| 38 |
)
|
| 39 |
|
| 40 |
equipment = st.multiselect(
|
| 41 |
-
"Available Equipment",
|
| 42 |
["Dumbbells", "Resistance Band", "Yoga Mat", "Skipping Rope",
|
| 43 |
"Weight Plates", "Cycling", "Inclined Bench", "Pullups Bar", "No Equipment"]
|
| 44 |
)
|
| 45 |
|
| 46 |
fitness_level = st.radio(
|
| 47 |
-
"Fitness Level",
|
| 48 |
["Beginner", "Intermediate", "Advanced"]
|
| 49 |
)
|
| 50 |
|
| 51 |
# -------------------------
|
| 52 |
-
#
|
| 53 |
# -------------------------
|
| 54 |
|
| 55 |
-
def
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
level_map = {
|
| 70 |
-
"Beginner": "Use simple low intensity exercises.",
|
| 71 |
-
"Intermediate": "Use moderate intensity exercises.",
|
| 72 |
-
"Advanced": "Use high intensity advanced exercises."
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
prompt = f"""
|
| 76 |
-
Generate a 5-day workout plan.
|
| 77 |
-
|
| 78 |
-
Goal: {goal}
|
| 79 |
-
Fitness Level: {fitness_level}
|
| 80 |
-
Equipment: {equipment_list}
|
| 81 |
-
|
| 82 |
-
Goal Instruction:
|
| 83 |
-
{goal_map[goal]}
|
| 84 |
-
|
| 85 |
-
Level Instruction:
|
| 86 |
-
{level_map[fitness_level]}
|
| 87 |
-
|
| 88 |
-
Requirements:
|
| 89 |
-
- Include warm-up
|
| 90 |
-
- Exercises with sets and reps
|
| 91 |
-
- Rest time
|
| 92 |
-
- Day-wise structure
|
| 93 |
-
"""
|
| 94 |
-
|
| 95 |
-
return prompt
|
| 96 |
|
| 97 |
# -------------------------
|
| 98 |
-
#
|
| 99 |
# -------------------------
|
| 100 |
|
| 101 |
-
if st.button("
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
st.error("Select at least one equipment")
|
| 107 |
else:
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
with st.spinner("Generating your AI workout plan..."):
|
| 111 |
-
|
| 112 |
-
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
| 113 |
|
| 114 |
-
|
| 115 |
-
**inputs,
|
| 116 |
-
max_new_tokens=400,
|
| 117 |
-
temperature=0.9,
|
| 118 |
-
do_sample=True
|
| 119 |
-
)
|
| 120 |
|
| 121 |
-
|
|
|
|
|
|
|
| 122 |
|
| 123 |
-
st.
|
| 124 |
-
st.write(
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
st.set_page_config(page_title="FitPlan AI - BMI Calculator", page_icon="πͺ")
|
| 4 |
|
| 5 |
+
st.title("πͺ FitPlan AI - Fitness Profile & BMI Calculator")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
st.write("Fill in your details to calculate your BMI and fitness category.")
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# -------------------------
|
| 10 |
+
# 1. Personal Information
|
| 11 |
# -------------------------
|
| 12 |
|
| 13 |
+
name = st.text_input("Enter Your Name *")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
height_cm = st.number_input("Enter Height (in centimeters) *", min_value=0.0, format="%.2f")
|
| 16 |
+
weight_kg = st.number_input("Enter Weight (in kilograms) *", min_value=0.0, format="%.2f")
|
| 17 |
|
| 18 |
# -------------------------
|
| 19 |
+
# 2. Fitness Details
|
| 20 |
# -------------------------
|
| 21 |
|
| 22 |
+
st.subheader("Fitness Details")
|
| 23 |
|
| 24 |
goal = st.selectbox(
|
| 25 |
"Select Your Fitness Goal",
|
|
|
|
| 27 |
)
|
| 28 |
|
| 29 |
equipment = st.multiselect(
|
| 30 |
+
"Available Equipment (Select multiple if available)",
|
| 31 |
["Dumbbells", "Resistance Band", "Yoga Mat", "Skipping Rope",
|
| 32 |
"Weight Plates", "Cycling", "Inclined Bench", "Pullups Bar", "No Equipment"]
|
| 33 |
)
|
| 34 |
|
| 35 |
fitness_level = st.radio(
|
| 36 |
+
"Select Your Fitness Level",
|
| 37 |
["Beginner", "Intermediate", "Advanced"]
|
| 38 |
)
|
| 39 |
|
| 40 |
# -------------------------
|
| 41 |
+
# BMI Calculation Function
|
| 42 |
# -------------------------
|
| 43 |
|
| 44 |
+
def calculate_bmi(weight, height_cm):
|
| 45 |
+
height_m = height_cm / 100 # Convert cm to meters
|
| 46 |
+
bmi = weight / (height_m ** 2)
|
| 47 |
+
return round(bmi, 2)
|
| 48 |
+
|
| 49 |
+
def bmi_category(bmi):
|
| 50 |
+
if bmi < 18.5:
|
| 51 |
+
return "Underweight"
|
| 52 |
+
elif 18.5 <= bmi < 24.9:
|
| 53 |
+
return "Normal"
|
| 54 |
+
elif 25 <= bmi < 29.9:
|
| 55 |
+
return "Overweight"
|
| 56 |
+
else:
|
| 57 |
+
return "Obese"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
# -------------------------
|
| 60 |
+
# Submit Button
|
| 61 |
# -------------------------
|
| 62 |
|
| 63 |
+
if st.button("Calculate BMI"):
|
| 64 |
+
|
| 65 |
+
# Validation
|
| 66 |
+
if not name or height_cm <= 0 or weight_kg <= 0:
|
| 67 |
+
st.error("β Please fill all required fields with valid values!")
|
|
|
|
| 68 |
else:
|
| 69 |
+
bmi = calculate_bmi(weight_kg, height_cm)
|
| 70 |
+
category = bmi_category(bmi)
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
+
st.success("β
Calculation Successful!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
+
st.write(f"### π€ Name: {name}")
|
| 75 |
+
st.write(f"### π Your BMI: {bmi}")
|
| 76 |
+
st.write(f"### π· BMI Category: {category}")
|
| 77 |
|
| 78 |
+
st.write("---")
|
| 79 |
+
st.write("### π Fitness Summary")
|
| 80 |
+
st.write(f"**Goal:** {goal}")
|
| 81 |
+
st.write(f"**Fitness Level:** {fitness_level}")
|
| 82 |
+
st.write(f"**Equipment Available:** {', '.join(equipment) if equipment else 'None selected'}")
|