Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +29 -18
src/streamlit_app.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
import torch
|
|
|
|
| 4 |
# -------------------------
|
| 5 |
# PAGE CONFIG
|
| 6 |
-
|
| 7 |
# -------------------------
|
| 8 |
st.set_page_config(page_title="FitPlan-AI", page_icon="💪")
|
|
|
|
| 9 |
# -------------------------
|
| 10 |
# BMI FUNCTIONS
|
| 11 |
# -------------------------
|
|
@@ -31,7 +32,7 @@ def load_model():
|
|
| 31 |
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
|
| 32 |
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
|
| 33 |
return tokenizer, model
|
| 34 |
-
|
| 35 |
tokenizer, model = load_model()
|
| 36 |
|
| 37 |
# -------------------------
|
|
@@ -42,6 +43,7 @@ st.title("💪 FitPlan-AI: Personalized Fitness Profile")
|
|
| 42 |
with st.form("fitness_form"):
|
| 43 |
|
| 44 |
st.subheader("Personal Information")
|
|
|
|
| 45 |
name = st.text_input("Full Name*", placeholder="Enter your name")
|
| 46 |
|
| 47 |
col1, col2 = st.columns(2)
|
|
@@ -68,15 +70,10 @@ with st.form("fitness_form"):
|
|
| 68 |
)
|
| 69 |
|
| 70 |
submit = st.form_submit_button("Submit Profile")
|
| 71 |
-
# -------------------------
|
| 72 |
-
# HANDLE SUBMISSION
|
| 73 |
-
# -------------------------
|
| 74 |
-
# SUBMIT BUTTON
|
| 75 |
|
| 76 |
# -------------------------
|
| 77 |
# HANDLE SUBMISSION
|
| 78 |
# -------------------------
|
| 79 |
-
|
| 80 |
if submit:
|
| 81 |
|
| 82 |
if not name:
|
|
@@ -91,23 +88,36 @@ if submit:
|
|
| 91 |
else:
|
| 92 |
st.success("Profile Submitted Successfully!")
|
| 93 |
|
| 94 |
-
#
|
| 95 |
bmi = calculate_bmi(weight, height)
|
| 96 |
bmi_status = get_category(bmi)
|
| 97 |
|
|
|
|
|
|
|
| 98 |
equipment_list = ", ".join(equipment)
|
| 99 |
|
|
|
|
| 100 |
prompt = f"""
|
| 101 |
You are a certified professional fitness trainer.
|
| 102 |
|
| 103 |
-
Create a detailed 5-day workout plan.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
User Information:
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
|
| 112 |
Start directly with:
|
| 113 |
|
|
@@ -120,12 +130,13 @@ Day 1:
|
|
| 120 |
|
| 121 |
outputs = model.generate(
|
| 122 |
**inputs,
|
| 123 |
-
max_new_tokens=
|
| 124 |
-
temperature=0.
|
| 125 |
-
do_sample=True
|
|
|
|
| 126 |
)
|
| 127 |
|
| 128 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
|
| 129 |
|
| 130 |
-
st.subheader("Your Personalized Workout Plan")
|
| 131 |
st.write(result)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
import torch
|
| 4 |
+
|
| 5 |
# -------------------------
|
| 6 |
# PAGE CONFIG
|
|
|
|
| 7 |
# -------------------------
|
| 8 |
st.set_page_config(page_title="FitPlan-AI", page_icon="💪")
|
| 9 |
+
|
| 10 |
# -------------------------
|
| 11 |
# BMI FUNCTIONS
|
| 12 |
# -------------------------
|
|
|
|
| 32 |
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
|
| 33 |
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
|
| 34 |
return tokenizer, model
|
| 35 |
+
|
| 36 |
tokenizer, model = load_model()
|
| 37 |
|
| 38 |
# -------------------------
|
|
|
|
| 43 |
with st.form("fitness_form"):
|
| 44 |
|
| 45 |
st.subheader("Personal Information")
|
| 46 |
+
|
| 47 |
name = st.text_input("Full Name*", placeholder="Enter your name")
|
| 48 |
|
| 49 |
col1, col2 = st.columns(2)
|
|
|
|
| 70 |
)
|
| 71 |
|
| 72 |
submit = st.form_submit_button("Submit Profile")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
# -------------------------
|
| 75 |
# HANDLE SUBMISSION
|
| 76 |
# -------------------------
|
|
|
|
| 77 |
if submit:
|
| 78 |
|
| 79 |
if not name:
|
|
|
|
| 88 |
else:
|
| 89 |
st.success("Profile Submitted Successfully!")
|
| 90 |
|
| 91 |
+
# Calculate BMI
|
| 92 |
bmi = calculate_bmi(weight, height)
|
| 93 |
bmi_status = get_category(bmi)
|
| 94 |
|
| 95 |
+
st.write(f"**Your BMI:** {bmi} ({bmi_status})")
|
| 96 |
+
|
| 97 |
equipment_list = ", ".join(equipment)
|
| 98 |
|
| 99 |
+
# Strong structured prompt
|
| 100 |
prompt = f"""
|
| 101 |
You are a certified professional fitness trainer.
|
| 102 |
|
| 103 |
+
Create a COMPLETE detailed 5-day workout plan.
|
| 104 |
+
|
| 105 |
+
IMPORTANT:
|
| 106 |
+
- You MUST generate Day 1, Day 2, Day 3, Day 4, and Day 5.
|
| 107 |
+
- Each day must include:
|
| 108 |
+
- Warm-up
|
| 109 |
+
- 4-6 exercises
|
| 110 |
+
- Sets and reps
|
| 111 |
+
- Cool down
|
| 112 |
+
- Do NOT stop after Day 1.
|
| 113 |
+
- Write all 5 days clearly.
|
| 114 |
|
| 115 |
User Information:
|
| 116 |
+
Name: {name}
|
| 117 |
+
BMI: {bmi} ({bmi_status})
|
| 118 |
+
Goal: {goal}
|
| 119 |
+
Fitness Level: {level}
|
| 120 |
+
Equipment Available: {equipment_list}
|
| 121 |
|
| 122 |
Start directly with:
|
| 123 |
|
|
|
|
| 130 |
|
| 131 |
outputs = model.generate(
|
| 132 |
**inputs,
|
| 133 |
+
max_new_tokens=1200,
|
| 134 |
+
temperature=0.8,
|
| 135 |
+
do_sample=True,
|
| 136 |
+
repetition_penalty=1.1
|
| 137 |
)
|
| 138 |
|
| 139 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
|
| 140 |
|
| 141 |
+
st.subheader("🏋️ Your Personalized 5-Day Workout Plan")
|
| 142 |
st.write(result)
|