Update src/streamlit_app.py
Browse files- src/streamlit_app.py +34 -26
src/streamlit_app.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import
|
|
|
|
|
|
|
| 3 |
# 1. Basic Configuration
|
| 4 |
st.set_page_config(page_title="FitPlan AI", page_icon="πͺ", layout="centered")
|
|
|
|
| 5 |
def load_model():
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
|
| 7 |
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
|
|
@@ -115,10 +118,8 @@ with st.form("fitness_form", clear_on_submit=False):
|
|
| 115 |
|
| 116 |
level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"], horizontal=True)
|
| 117 |
|
| 118 |
-
#
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
if st.button("π Submit Profile"):
|
| 122 |
|
| 123 |
if not name:
|
| 124 |
st.error("Please enter your name.")
|
|
@@ -130,33 +131,40 @@ if st.button("π Submit Profile"):
|
|
| 130 |
st.error("Please select at least one equipment option.")
|
| 131 |
|
| 132 |
else:
|
| 133 |
-
st.success("
|
| 134 |
|
| 135 |
bmi_status = bmi_category(bmi)
|
| 136 |
equipment_list = ", ".join(equipment)
|
| 137 |
|
| 138 |
prompt = f"""
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
- Keep it structured day-wise
|
| 155 |
-
"""
|
| 156 |
|
| 157 |
with st.spinner("Generating your AI workout plan..."):
|
| 158 |
-
response = generator(prompt, max_new_tokens=400)
|
| 159 |
-
result = response[0]["generated_text"]
|
| 160 |
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
st.write(result)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
# 1. Basic Configuration
|
| 6 |
st.set_page_config(page_title="FitPlan AI", page_icon="πͺ", layout="centered")
|
| 7 |
+
|
| 8 |
def load_model():
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
|
| 10 |
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
|
|
|
|
| 118 |
|
| 119 |
level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"], horizontal=True)
|
| 120 |
|
| 121 |
+
# SUBMIT BUTTON
|
| 122 |
+
if st.button(" Submit Profile"):
|
|
|
|
|
|
|
| 123 |
|
| 124 |
if not name:
|
| 125 |
st.error("Please enter your name.")
|
|
|
|
| 131 |
st.error("Please select at least one equipment option.")
|
| 132 |
|
| 133 |
else:
|
| 134 |
+
st.success(" Profile Submitted Successfully!")
|
| 135 |
|
| 136 |
bmi_status = bmi_category(bmi)
|
| 137 |
equipment_list = ", ".join(equipment)
|
| 138 |
|
| 139 |
prompt = f"""
|
| 140 |
+
You are a certified professional fitness trainer.
|
| 141 |
+
|
| 142 |
+
Create a detailed 5-day workout plan.
|
| 143 |
+
|
| 144 |
+
User Information:
|
| 145 |
+
- Gender: {gender}
|
| 146 |
+
- BMI: {bmi:.2f} ({bmi_status})
|
| 147 |
+
- Goal: {goal}
|
| 148 |
+
- Fitness Level: {fitness_level}
|
| 149 |
+
- Equipment Available: {equipment_list}
|
| 150 |
+
|
| 151 |
+
Start directly with:
|
| 152 |
+
|
| 153 |
+
Day 1:
|
| 154 |
+
"""
|
|
|
|
|
|
|
| 155 |
|
| 156 |
with st.spinner("Generating your AI workout plan..."):
|
|
|
|
|
|
|
| 157 |
|
| 158 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
|
| 159 |
+
|
| 160 |
+
outputs = model.generate(
|
| 161 |
+
**inputs,
|
| 162 |
+
max_new_tokens=900,
|
| 163 |
+
temperature=0.7,
|
| 164 |
+
do_sample=True
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
|
| 168 |
+
|
| 169 |
+
st.subheader(" Your Personalized Workout Plan")
|
| 170 |
st.write(result)
|