Update src/streamlit_app.py
Browse files- src/streamlit_app.py +13 -29
src/streamlit_app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
# --- Page Config ---
|
| 5 |
st.set_page_config(page_title="FitPlan AI", page_icon="π", layout="wide")
|
|
@@ -35,12 +35,13 @@ def bmi_category(bmi):
|
|
| 35 |
if bmi < 30: return "Overweight"
|
| 36 |
return "Obese"
|
| 37 |
|
| 38 |
-
# --- AI Model Loading
|
| 39 |
@st.cache_resource
|
| 40 |
def load_model():
|
| 41 |
-
|
|
|
|
| 42 |
|
| 43 |
-
generator = load_model()
|
| 44 |
|
| 45 |
# --- Sidebar Navigation ---
|
| 46 |
with st.sidebar:
|
|
@@ -50,9 +51,8 @@ with st.sidebar:
|
|
| 50 |
# --- NAVIGATION LOGIC ---
|
| 51 |
|
| 52 |
if menu == "π€ Profile":
|
| 53 |
-
st.title("π€ Profile")
|
| 54 |
|
| 55 |
-
# Input fields
|
| 56 |
name = st.text_input("Name", value=st.session_state.user_data['name'])
|
| 57 |
gender = st.selectbox("Gender", ["Male", "Female", "Other"])
|
| 58 |
col1, col2 = st.columns(2)
|
|
@@ -65,22 +65,18 @@ if menu == "π€ Profile":
|
|
| 65 |
|
| 66 |
bmi = calculate_bmi(u_weight, u_height)
|
| 67 |
|
| 68 |
-
# --- MAM'S SUBMIT LOGIC
|
| 69 |
if st.button("Submit Profile"):
|
| 70 |
|
| 71 |
if not name:
|
| 72 |
st.error("Please enter your name.")
|
| 73 |
-
|
| 74 |
elif not equipment:
|
| 75 |
st.error("Please select at least one equipment option.")
|
| 76 |
-
|
| 77 |
elif bmi is None:
|
| 78 |
st.error("Please enter valid height and weight.")
|
| 79 |
-
|
| 80 |
else:
|
| 81 |
st.success("β
Profile Submitted Successfully!")
|
| 82 |
|
| 83 |
-
# Save to session state
|
| 84 |
st.session_state.user_data.update({
|
| 85 |
'name': name, 'height': u_height, 'weight': u_weight,
|
| 86 |
'goal': goal, 'equip': equipment, 'level': fitness_level, 'gender': gender
|
|
@@ -91,30 +87,18 @@ if menu == "π€ Profile":
|
|
| 91 |
equipment_list = ", ".join(equipment)
|
| 92 |
|
| 93 |
prompt = f"""
|
| 94 |
-
Generate a 5-day structured workout plan.
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
Gender: {gender}
|
| 99 |
-
BMI: {bmi:.2f} ({bmi_status})
|
| 100 |
-
Goal: {goal}
|
| 101 |
-
Fitness Level: {fitness_level}
|
| 102 |
-
Available Equipment: {equipment_list}
|
| 103 |
-
|
| 104 |
-
Requirements:
|
| 105 |
-
- Include warmup
|
| 106 |
-
- Include exercises with sets and reps
|
| 107 |
-
- Include rest time
|
| 108 |
-
- Adjust intensity based on BMI and fitness level
|
| 109 |
-
- Keep it structured day-wise
|
| 110 |
"""
|
| 111 |
|
| 112 |
with st.spinner("Generating your AI workout plan..."):
|
| 113 |
-
|
|
|
|
| 114 |
|
| 115 |
st.subheader("ποΈ Your Personalized Workout Plan")
|
| 116 |
st.write(result)
|
| 117 |
-
# --- MAM'S SUBMIT LOGIC END ---
|
| 118 |
|
| 119 |
elif menu == "π Dashboard":
|
| 120 |
if not st.session_state.profile_complete:
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
# --- Page Config ---
|
| 5 |
st.set_page_config(page_title="FitPlan AI", page_icon="π", layout="wide")
|
|
|
|
| 35 |
if bmi < 30: return "Overweight"
|
| 36 |
return "Obese"
|
| 37 |
|
| 38 |
+
# --- AI Model Loading ---
|
| 39 |
@st.cache_resource
|
| 40 |
def load_model():
|
| 41 |
+
# FIXED: Changed back to "text-generation" to match your error's allowed list
|
| 42 |
+
return pipeline("text-generation", model="google/flan-t5-base")
|
| 43 |
|
| 44 |
+
generator = load_model()
|
| 45 |
|
| 46 |
# --- Sidebar Navigation ---
|
| 47 |
with st.sidebar:
|
|
|
|
| 51 |
# --- NAVIGATION LOGIC ---
|
| 52 |
|
| 53 |
if menu == "π€ Profile":
|
| 54 |
+
st.title("π€ User Profile")
|
| 55 |
|
|
|
|
| 56 |
name = st.text_input("Name", value=st.session_state.user_data['name'])
|
| 57 |
gender = st.selectbox("Gender", ["Male", "Female", "Other"])
|
| 58 |
col1, col2 = st.columns(2)
|
|
|
|
| 65 |
|
| 66 |
bmi = calculate_bmi(u_weight, u_height)
|
| 67 |
|
| 68 |
+
# --- MAM'S SUBMIT LOGIC ---
|
| 69 |
if st.button("Submit Profile"):
|
| 70 |
|
| 71 |
if not name:
|
| 72 |
st.error("Please enter your name.")
|
|
|
|
| 73 |
elif not equipment:
|
| 74 |
st.error("Please select at least one equipment option.")
|
|
|
|
| 75 |
elif bmi is None:
|
| 76 |
st.error("Please enter valid height and weight.")
|
|
|
|
| 77 |
else:
|
| 78 |
st.success("β
Profile Submitted Successfully!")
|
| 79 |
|
|
|
|
| 80 |
st.session_state.user_data.update({
|
| 81 |
'name': name, 'height': u_height, 'weight': u_weight,
|
| 82 |
'goal': goal, 'equip': equipment, 'level': fitness_level, 'gender': gender
|
|
|
|
| 87 |
equipment_list = ", ".join(equipment)
|
| 88 |
|
| 89 |
prompt = f"""
|
| 90 |
+
Generate a 5-day structured workout plan for {name}.
|
| 91 |
+
Gender: {gender}, BMI: {bmi:.2f} ({bmi_status}), Goal: {goal}, Level: {fitness_level}.
|
| 92 |
+
Equipment: {equipment_list}.
|
| 93 |
+
Plan:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
"""
|
| 95 |
|
| 96 |
with st.spinner("Generating your AI workout plan..."):
|
| 97 |
+
# Using the generator as per mam's code
|
| 98 |
+
result = generator(prompt, max_new_tokens=200)[0]["generated_text"]
|
| 99 |
|
| 100 |
st.subheader("ποΈ Your Personalized Workout Plan")
|
| 101 |
st.write(result)
|
|
|
|
| 102 |
|
| 103 |
elif menu == "π Dashboard":
|
| 104 |
if not st.session_state.profile_complete:
|