Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +16 -216
src/streamlit_app.py
CHANGED
|
@@ -1,226 +1,26 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
|
|
|
| 3 |
|
| 4 |
st.set_page_config(page_title="FitPlan AI", layout="centered")
|
| 5 |
|
| 6 |
-
|
| 7 |
-
# HUGGING FACE API CONFIG
|
| 8 |
-
# ---------------------------------------------------
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
"Content-Type": "application/json"
|
| 15 |
-
}
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
response = requests.post(API_URL, headers=headers, json=payload, timeout=60)
|
| 20 |
|
| 21 |
-
|
| 22 |
-
return {"error": f"API Error {response.status_code}: {response.text}"}
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
# ---------------------------------------------------
|
| 30 |
-
# TITLE
|
| 31 |
-
# ---------------------------------------------------
|
| 32 |
-
|
| 33 |
-
st.title("🏋️ FitPlan AI – User Fitness Profile")
|
| 34 |
-
|
| 35 |
-
# ---------------------------------------------------
|
| 36 |
-
# PERSONAL INFORMATION
|
| 37 |
-
# ---------------------------------------------------
|
| 38 |
-
|
| 39 |
-
st.subheader("👤 Personal Information")
|
| 40 |
-
|
| 41 |
-
name = st.text_input("Enter Your Name")
|
| 42 |
-
|
| 43 |
-
gender = st.radio(
|
| 44 |
-
"Gender",
|
| 45 |
-
["Male", "Female"],
|
| 46 |
-
horizontal=True
|
| 47 |
-
)
|
| 48 |
-
|
| 49 |
-
# ---------------------------------------------------
|
| 50 |
-
# HEIGHT & WEIGHT
|
| 51 |
-
# ---------------------------------------------------
|
| 52 |
-
|
| 53 |
-
col1, col2 = st.columns(2)
|
| 54 |
-
|
| 55 |
-
with col1:
|
| 56 |
-
height = st.number_input(
|
| 57 |
-
"Height (in cm)",
|
| 58 |
-
min_value=0.0,
|
| 59 |
-
max_value=250.0,
|
| 60 |
-
value=0.0,
|
| 61 |
-
step=0.1
|
| 62 |
-
)
|
| 63 |
-
|
| 64 |
-
with col2:
|
| 65 |
-
weight = st.number_input(
|
| 66 |
-
"Weight (in kg)",
|
| 67 |
-
min_value=0.0,
|
| 68 |
-
max_value=200.0,
|
| 69 |
-
value=0.0,
|
| 70 |
-
step=0.1
|
| 71 |
-
)
|
| 72 |
-
|
| 73 |
-
# ---------------------------------------------------
|
| 74 |
-
# BMI FUNCTION
|
| 75 |
-
# ---------------------------------------------------
|
| 76 |
-
|
| 77 |
-
def bmi_category(bmi):
|
| 78 |
-
if bmi < 18.5:
|
| 79 |
-
return "Underweight"
|
| 80 |
-
elif bmi < 25:
|
| 81 |
-
return "Normal weight"
|
| 82 |
-
elif bmi < 30:
|
| 83 |
-
return "Overweight"
|
| 84 |
-
else:
|
| 85 |
-
return "Obese"
|
| 86 |
-
|
| 87 |
-
bmi = None
|
| 88 |
-
|
| 89 |
-
if height > 0 and weight > 0:
|
| 90 |
-
height_m = height / 100
|
| 91 |
-
bmi = weight / (height_m ** 2)
|
| 92 |
-
|
| 93 |
-
st.metric("📊 Your BMI", f"{bmi:.2f}")
|
| 94 |
-
st.info(f"BMI Category: {bmi_category(bmi)}")
|
| 95 |
-
|
| 96 |
-
# ---------------------------------------------------
|
| 97 |
-
# FITNESS GOAL
|
| 98 |
-
# ---------------------------------------------------
|
| 99 |
-
|
| 100 |
-
st.subheader("🎯 Fitness Goal")
|
| 101 |
-
|
| 102 |
-
goal = st.selectbox(
|
| 103 |
-
"Select Your Goal",
|
| 104 |
-
[
|
| 105 |
-
"Flexible",
|
| 106 |
-
"Weight Loss",
|
| 107 |
-
"Build Muscle",
|
| 108 |
-
"Strength Gaining",
|
| 109 |
-
"Abs Building"
|
| 110 |
-
]
|
| 111 |
-
)
|
| 112 |
-
|
| 113 |
-
# ---------------------------------------------------
|
| 114 |
-
# EQUIPMENT
|
| 115 |
-
# ---------------------------------------------------
|
| 116 |
-
|
| 117 |
-
st.subheader("🏋️ Available Equipment")
|
| 118 |
-
|
| 119 |
-
equipment_map = {}
|
| 120 |
-
|
| 121 |
-
col1, col2, col3 = st.columns(3)
|
| 122 |
-
|
| 123 |
-
with col1:
|
| 124 |
-
equipment_map["No Equipment"] = st.checkbox("No Equipment")
|
| 125 |
-
equipment_map["Pull-up Bar"] = st.checkbox("Pull-up Bar")
|
| 126 |
-
equipment_map["Dip Bars"] = st.checkbox("Dip Bars")
|
| 127 |
-
equipment_map["Push-up Handles"] = st.checkbox("Push-up Handles")
|
| 128 |
-
equipment_map["Dumbbells"] = st.checkbox("Dumbbells")
|
| 129 |
-
equipment_map["Adjustable Dumbbells"] = st.checkbox("Adjustable Dumbbells")
|
| 130 |
-
|
| 131 |
-
with col2:
|
| 132 |
-
equipment_map["Barbell"] = st.checkbox("Barbell")
|
| 133 |
-
equipment_map["Weight Plates"] = st.checkbox("Weight Plates")
|
| 134 |
-
equipment_map["Kettlebells"] = st.checkbox("Kettlebells")
|
| 135 |
-
equipment_map["Medicine Ball"] = st.checkbox("Medicine Ball")
|
| 136 |
-
equipment_map["Yoga Mat"] = st.checkbox("Yoga Mat")
|
| 137 |
-
equipment_map["Resistance Band"] = st.checkbox("Resistance Band")
|
| 138 |
-
|
| 139 |
-
with col3:
|
| 140 |
-
equipment_map["Bosu Ball"] = st.checkbox("Bosu Ball")
|
| 141 |
-
equipment_map["Stability Ball"] = st.checkbox("Stability Ball")
|
| 142 |
-
equipment_map["Foam Roller"] = st.checkbox("Foam Roller")
|
| 143 |
-
equipment_map["Treadmill"] = st.checkbox("Treadmill")
|
| 144 |
-
equipment_map["Exercise Bike"] = st.checkbox("Exercise Bike")
|
| 145 |
-
equipment_map["Skipping Rope"] = st.checkbox("Skipping Rope")
|
| 146 |
-
|
| 147 |
-
equipment = [item for item, selected in equipment_map.items() if selected]
|
| 148 |
-
|
| 149 |
-
# ---------------------------------------------------
|
| 150 |
-
# FITNESS LEVEL
|
| 151 |
-
# ---------------------------------------------------
|
| 152 |
-
|
| 153 |
-
st.subheader("📈 Fitness Level")
|
| 154 |
-
|
| 155 |
-
fitness_level = st.radio(
|
| 156 |
-
"Select Fitness Level",
|
| 157 |
-
["Beginner", "Intermediate", "Advanced"],
|
| 158 |
-
horizontal=True
|
| 159 |
-
)
|
| 160 |
-
|
| 161 |
-
# ---------------------------------------------------
|
| 162 |
-
# SUBMIT BUTTON
|
| 163 |
-
# ---------------------------------------------------
|
| 164 |
-
|
| 165 |
-
if st.button("🚀 Submit Profile"):
|
| 166 |
-
|
| 167 |
-
if not name:
|
| 168 |
-
st.error("Please enter your name.")
|
| 169 |
-
|
| 170 |
-
elif height <= 0 or weight <= 0:
|
| 171 |
-
st.error("Please enter valid height and weight.")
|
| 172 |
-
|
| 173 |
-
elif not equipment:
|
| 174 |
-
st.error("Please select at least one equipment option.")
|
| 175 |
-
|
| 176 |
-
else:
|
| 177 |
-
st.success("✅ Profile Submitted Successfully!")
|
| 178 |
-
|
| 179 |
-
bmi_status = bmi_category(bmi)
|
| 180 |
-
equipment_list = ", ".join(equipment)
|
| 181 |
-
|
| 182 |
-
prompt = f"""<s>[INST]
|
| 183 |
-
You are a certified professional fitness trainer.
|
| 184 |
-
|
| 185 |
-
Generate a structured 5-day workout plan.
|
| 186 |
-
|
| 187 |
-
Rules:
|
| 188 |
-
- Clearly label Day 1 to Day 5
|
| 189 |
-
- Include exercises
|
| 190 |
-
- Include sets and reps
|
| 191 |
-
- Include short rest guidance
|
| 192 |
-
- Return only the workout plan
|
| 193 |
-
|
| 194 |
-
User Details:
|
| 195 |
-
Gender: {gender}
|
| 196 |
-
BMI: {bmi:.2f} ({bmi_status})
|
| 197 |
-
Goal: {goal}
|
| 198 |
-
Fitness Level: {fitness_level}
|
| 199 |
-
Equipment Available: {equipment_list}
|
| 200 |
-
[/INST]"""
|
| 201 |
-
|
| 202 |
-
with st.spinner("Generating your AI workout plan..."):
|
| 203 |
-
|
| 204 |
-
output = query({
|
| 205 |
-
"inputs": prompt,
|
| 206 |
-
"parameters": {
|
| 207 |
-
"max_new_tokens": 600,
|
| 208 |
-
"temperature": 0.3,
|
| 209 |
-
"return_full_text": False
|
| 210 |
-
}
|
| 211 |
-
})
|
| 212 |
-
|
| 213 |
-
if isinstance(output, dict) and "error" in output:
|
| 214 |
-
response = f"⚠️ {output['error']}\n\nPlease try again."
|
| 215 |
-
|
| 216 |
-
elif isinstance(output, list):
|
| 217 |
-
response = output[0]["generated_text"].strip()
|
| 218 |
-
|
| 219 |
-
if "[/INST]" in response:
|
| 220 |
-
response = response.split("[/INST]")[-1].strip()
|
| 221 |
-
|
| 222 |
-
else:
|
| 223 |
-
response = "Unexpected response from model."
|
| 224 |
-
|
| 225 |
-
st.subheader("🏋️ Your Personalized Workout Plan")
|
| 226 |
-
st.markdown(response)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from prompt_builder import build_prompt
|
| 3 |
+
from model_api import query_model
|
| 4 |
|
| 5 |
st.set_page_config(page_title="FitPlan AI", layout="centered")
|
| 6 |
|
| 7 |
+
st.title("🏋️ FitPlan AI - Personalized Workout Generator")
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# User Inputs
|
| 10 |
+
goal = st.selectbox("Select Your Goal",
|
| 11 |
+
["Build Muscle", "Lose Weight", "Improve Endurance"])
|
| 12 |
|
| 13 |
+
fitness_level = st.selectbox("Fitness Level",
|
| 14 |
+
["Beginner", "Intermediate", "Advanced"])
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
equipment = st.selectbox("Available Equipment",
|
| 17 |
+
["No Equipment", "Dumbbells", "Full Gym"])
|
|
|
|
| 18 |
|
| 19 |
+
if st.button("Generate Plan"):
|
|
|
|
| 20 |
|
| 21 |
+
with st.spinner("Generating your personalized workout plan..."):
|
| 22 |
+
prompt = build_prompt(goal, fitness_level, equipment)
|
| 23 |
+
response = query_model(prompt)
|
| 24 |
|
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