Spaces:
Sleeping
Sleeping
File size: 5,968 Bytes
d6dc11c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | import streamlit as st
from datetime import datetime
from prompt_builder import build_prompt, bmi_category # Import from prompt_builder
from model_api import query_model # Import the model API
st.set_page_config(
page_title="FIT Plan AI - Milestone 1",
page_icon="πͺ",
layout="centered"
)
st.title("πͺ FIT Plan AI β Personalized Fitness Profile")
st.markdown("---")
# Initialize session state
if "form_submitted" not in st.session_state:
st.session_state.form_submitted = False
if "workout_plan" not in st.session_state:
st.session_state.workout_plan = None
with st.form("fitness_profile_form"):
st.header("π Your Fitness Profile")
st.subheader("π€ Personal Information")
col1, col2 = st.columns(2)
with col1:
name = st.text_input("Full Name *")
height = st.number_input("Height (cm) *", min_value=1.0, max_value=300.0, value=170.0)
with col2:
age = st.number_input("Age", min_value=10, max_value=120, value=25)
weight = st.number_input("Weight (kg) *", min_value=1.0, max_value=500.0, value=70.0)
gender = st.selectbox("Gender", ["Male", "Female", "Other"])
st.subheader("π― Fitness Details")
goal = st.selectbox(
"Fitness Goal *",
["Weight Loss", "Build Muscle", "Strength Gain", "Abs Building", "Flexibility"]
)
equipment = st.multiselect(
"Available Equipment *",
[
"Dumbbells",
"Resistance Bands",
"Barbell",
"Pull-up Bar",
"Treadmill",
"Kettlebells",
"Jump Rope",
"Yoga Mat",
"No Equipment (Bodyweight only)"
],
default=["No Equipment (Bodyweight only)"]
)
fitness_level = st.select_slider(
"Fitness Level *",
options=["Beginner", "Intermediate", "Advanced"],
value="Beginner"
)
st.markdown("---")
submit = st.form_submit_button("Submit Profile", use_container_width=True)
if submit:
if not name:
st.error("Please enter your name.")
st.stop()
if not equipment:
st.error("Please select at least one equipment option.")
st.stop()
# Build prompt using the imported function
prompt, bmi, bmi_status = build_prompt(
name=name,
gender=gender,
height=height,
weight=weight,
goal=goal,
fitness_level=fitness_level,
equipment=equipment
)
st.success("β
Profile Submitted Successfully!")
st.session_state.update({
"form_submitted": True,
"name": name,
"bmi": bmi,
"bmi_status": bmi_status,
"age": age,
"goal": goal,
"equipment": equipment,
"fitness_level": fitness_level,
"height": height,
"weight": weight,
"gender": gender,
"prompt": prompt # Store the generated prompt
})
if st.session_state.form_submitted:
st.markdown("---")
st.success(f"Welcome, *{st.session_state.name}*!")
col1, col2, col3 = st.columns(3)
col1.metric("π BMI", f"{st.session_state.bmi:.2f}")
col2.metric("π· Category", st.session_state.bmi_status)
col3.metric("ποΈ Level", st.session_state.fitness_level)
# Generate Workout Plan Button
st.markdown("---")
st.subheader("ποΈ Generate Your Personalized Workout Plan")
if st.button("Generate Workout Plan", type="primary", use_container_width=True):
with st.spinner("Creating your personalized workout plan... This may take a moment."):
# Call the model API
workout_plan = query_model(st.session_state.prompt)
st.session_state.workout_plan = workout_plan
# Display workout plan if generated
if st.session_state.workout_plan:
st.markdown("---")
st.subheader("π Your 5-Day Workout Plan")
with st.container():
st.markdown(st.session_state.workout_plan)
# Download button for workout plan
workout_text = f"""
FIT PLAN AI - PERSONALIZED WORKOUT PLAN
Generated for: {st.session_state.name}
Date: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
Profile Summary:
- BMI: {st.session_state.bmi:.2f} ({st.session_state.bmi_status})
- Goal: {st.session_state.goal}
- Level: {st.session_state.fitness_level}
- Equipment: {', '.join(st.session_state.equipment)}
{st.session_state.workout_plan}
---
Stay consistent and trust the process!
"""
col1, col2 = st.columns(2)
with col1:
st.download_button(
"π₯ Download Workout Plan",
data=workout_text,
file_name=f"FITPlanAI_{st.session_state.name}_Workout.txt",
mime="text/plain",
use_container_width=True
)
with col2:
if st.button("Generate New Plan", use_container_width=True):
st.session_state.workout_plan = None
st.rerun()
# Profile Report Section
st.markdown("---")
with st.expander("π View Profile Report"):
report_text = f"""
FIT PLAN AI - PROFILE REPORT
Generated on: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
Name: {st.session_state.name}
Age: {st.session_state.age}
Gender: {st.session_state.gender}
Height: {st.session_state.height} cm
Weight: {st.session_state.weight} kg
BMI: {st.session_state.bmi:.2f}
Category: {st.session_state.bmi_status}
Goal: {st.session_state.goal}
Level: {st.session_state.fitness_level}
Equipment: {', '.join(st.session_state.equipment)}
Stay consistent and trust the process!
"""
st.download_button(
"π₯ Download Profile Report",
data=report_text,
file_name=f"FITPlanAI_{st.session_state.name}_Profile.txt",
mime="text/plain",
use_container_width=True
)
st.markdown("---")
st.caption("FIT Plan AI - Milestone 1 | Powered by Mistral-7B") |