import streamlit as st import pandas as pd from auth import generate_otp, create_jwt, verify_jwt from email_utils import send_otp_email from dotenv import load_dotenv from database import add_user, user_exists, verify_login # Load environment variables load_dotenv() # --- Page Config --- st.set_page_config( page_title="FitPlan AI", page_icon="🏋️♂️", layout="wide", initial_sidebar_state="expanded" ) # --- INNOVATIVE LIGHT MODE UI --- st.markdown(""" """, unsafe_allow_html=True) # --- Initialize Session State --- if "user_data" not in st.session_state: st.session_state.user_data = None if "otp" not in st.session_state: st.session_state.otp = None if "authenticated" not in st.session_state: st.session_state.authenticated = False if "token" not in st.session_state: st.session_state.token = None # --- FULL WORKOUT GENERATOR WITH ALL PLANS --- def workout_generator(prompt, goal, max_new_tokens=1000): plans = { "Build Muscle": """ ➡️Day 1: Chest (Push) - Focus on the "stretch and squeeze" of the pectoral fibers. - Barbell Bench Press: 4 sets 6–8 reps. - Incline Dumbbell Press: 3 sets 10–12 reps. - Chest Dips (Leaning forward): 3 sets Failure. - Cable Flys (Middle to Low): 3 sets 15 reps. - Push-ups: 2 sets Max reps (as a finisher). ➡️Day 2: Back (Pull) - Drive with your elbows to ensure the lats are doing the work, not just your biceps. - Deadlifts: 3 sets 5 reps (Heavy). - Pull-Ups (or Lat Pulldowns): 4 sets 8–10 reps. - Bent-Over Barbell Rows: 3 sets 10 reps. - Seated Cable Rows: 3 sets 12 reps. - Face Pulls: 3 sets 15–20 reps (for rear delts and posture). ➡️Day 3: Legs (Lower) - The most demanding day. Ensure you hit full depth on your movements. - Barbell Back Squats: 4 sets 8–10 reps. - Leg Press: 3 sets 12–15 reps. - Romanian Deadlifts: 3 sets 10–12 reps (for hamstrings). - Leg Extensions: 3 sets 15 reps. - Seated Calf Raises: 4 sets 15–20 reps. ➡️Day 4: Shoulders - Prioritize the side (lateral) head of the delt for maximum width. - Overhead Press (Barbell or DB): 4 sets 8–10 reps. - Lateral Raises (Dumbbell): 4 sets 15–20 reps. - Front Raises (Plate or DB): 3 sets 12 reps. - Reverse Pec Deck (Rear Delts): 3 sets 15 reps. - Dumbbell Shrugs: 3 sets 12 reps. ➡️Day 5: Arms & Abs - High volume to force blood into the smaller muscle groups. - Barbell Curls: 3 sets 10 reps. - Close-Grip Bench Press: 3 sets 8–10 reps. - Hammer Curls: 3 sets 12 reps. - Tricep Rope Pushdowns: 3 sets 15 reps. - Hanging Leg Raises: 3 sets 15 reps. - Plank: 3 sets 60 seconds """, "Weight Loss": """ ➡️Day 1: Upper Body (Push) - Focuses on chest, shoulders, and triceps. - Dumbbell Chest Press: 3 sets of 10–12 reps. - Shoulder Press: 3 sets of 10–12 reps. - Triceps Pushdowns: 3 sets of 12–15 reps. - Push-ups: 3 sets to failure. - Cardio Finisher: 15 minutes of brisk walking. ➡️Day 2: Lower Body - Focuses on quads, glutes, and hamstrings. - Goblet Squats: 3 sets of 12 reps. - Walking Lunges: 3 sets of 10 reps per leg. - Romanian Deadlifts: 3 sets of 10 reps. - Glute Bridges: 3 sets of 15 reps. - Cardio Finisher: 15 minutes on a cycle or treadmill. ➡️Day 3: Cardio HIIT - Designed to spike your heart rate and burn fat quickly. - Format: 30 seconds of high intensity (sprint/jumping jacks/burpees) followed by 60 seconds of low intensity (walking). - Repeat: 10–15 rounds. - Exercises to Mix: Mountain climbers, burpees, high knees, and skipping rope. ➡️Day 4: Upper Body (Pull) - Focuses on the back and biceps. - Lat Pulldowns: 3 sets of 10–12 reps. - Seated Cable Rows: 3 sets of 12 reps. - Dumbbell Bicep Curls: 3 sets of 12 reps. - Face Pulls: 3 sets of 15 reps. - Cardio Finisher: 15 minutes on the rowing machine. ➡️Day 5: Steady-State Cardio & Core - Lower intensity to promote recovery while still burning calories. - Steady Cardio: 35–40 minutes of jogging, swimming, or brisk walking. - Core Circuit (Repeat 3 times). - Plank: Hold for 45–60 seconds. - Russian Twists: 20 reps. - Bicycle Crunches: 15 reps per side. """, "Strength Gain": """ ➡️Day 1: Full Body Strength - Focus on hitting every major muscle group in a single, high-intensity session. - Barbell Squats: 3–5 sets of 5 reps. - Barbell Bench Press: 3–5 sets of 5 reps. - Barbell Rows: 3 sets of 6–8 reps. - Overhead Press: 3 sets of 5–8 reps. - Deadlifts: 1–3 sets of 5 reps. ➡️Day 2: Lower Body - Focus on the largest muscles in the body to build massive foundational strength. - Barbell Squats: 3 sets of 5–8 reps (Main power move). - Romanian Deadlifts: 3 sets of 8–10 reps (Targets hamstrings and glutes). - Leg Press or Lunges: 3 sets of 10 reps (Builds quad volume). - Calf Raises: 3 sets of 15 reps (Lower leg stability). - Plank / Core Work: 3 sets of 60 seconds. ➡️Day 3: Leg Day - Hit the main lifts for the second time this week. - Barbell Squats: 5 sets of 5 reps. - Barbell Bench Press: 5 sets of 5 reps. - Barbell Rows: 5 sets of 5 reps. - Dips: 3 sets to failure (for chest and tricep endurance). - Hanging Leg Raises: 3 sets of 15 reps (core strength). ➡️Day 4: Rest & Recovery - Light Walk: 20 mins to boost blood flow. - Stretch: Focus on hips and lower back. - Hydrate: Drink extra water for muscle repair. - Protein: Keep intake high to rebuild tissue. - Sleep: Aim for 8 hours of quality rest. ➡️Day 5: Upper Body - Dumbbell Shoulder Press: 3 sets × 12 reps (Focus on vertical control). - Cable Rows: 3 sets × 12–15 reps (Keep chest up, squeeze shoulder blades). - Face Pulls: 3 sets × 15–20 reps (Great for posture and rear delts). - Hammer Curls: 3 sets × 12 reps (Targets forearms and biceps). - Tricep Overhead Extension: 3 sets × 12 reps """, "Abs Building": """ ➡️Day 1: Upper Abs Focus - Floor Crunch: 3 sets x 20 reps. Targets the upper rectus abdominis. - Sit-ups: 4 sets x 15 reps. A classic for building core power. - Toe Touches: 4 sets x 30 reps. Engages the upper abs through targeted flexion. - Plank: 3 sets x Max Time. Essential for overall core tension. ➡️Day 2: Lower Abs Focus - Lying Leg Raise: 3 sets x 15 reps. One of the best for lower ab activation. - Reverse Crunch: 4 sets x 10-15 reps. Focuses on bringing the hips toward the chest. - Flutter Kicks: 40 seconds. Keeps constant tension on the lower core. - Scissor Kicks: 4 sets x 30 reps. Mimics walking to engage deep lower muscles. ➡️Day 3: Obliques - Russian Twists: 4 sets x 20 reps. Key for rotational strength and side-ab definition. - Side Plank: 30-45 seconds per side. Builds lateral stability. - Crossbody Mountain Climbers: 30 seconds. Combines cardio with oblique rotation. - Side Crunches: 40 seconds per side. Directly targets the love handle area. ➡️Day 4: Core Stability - Bird Dog: 5 reps per side (slowly). Teaches the core to stay stable during movement. - Plank Shoulder Taps: 40 seconds. Forces the core to resist rotation. - Superman Hold: 40 seconds. Important for lower back health to support front abs. - Plank Jacks: 10-15 reps. Adds a cardio element to traditional planking. ➡️Day 5: Total Core Burn - Bicycle Crunches: 40 seconds. Often cited as the most effective ab exercise. - V-Ups: 10 reps. An advanced move that hits upper and lower abs simultaneously. - Mountain Climbers: 30 seconds. Explosive movement for final fat burning. - High Knees: 30 seconds. Keeps heart rate up to maximize the "afterburn" effect. """, "Flexibility": """ ➡️Day 1: Full Body Dynamic Mobility - Neck Rolls: 2 sets of 30 seconds. - Arm Circles: 2 sets of 20 reps (forward and backward). - Cat-Cow Stretch: 3 sets of 10 reps to warm up the spine. - Leg Swings: 2 sets of 15 reps per leg. - Standing Forward Fold: 3 sets of 20 seconds. ➡️Day 2: Hips & Hamstrings - Downward Dog: 3 sets of 30 seconds for calves and hamstrings. - Lunge Stretch: 3 sets of 20 seconds per leg to open hip flexors. - Butterfly Pose: 3 sets of 30 seconds for inner thighs. - Seated Hamstring Stretch: 3 sets of 30 seconds (lean from hips, not waist). - Pigeon Pose: 2 sets of 30 seconds per side for deep hip opening. ➡️Day 3: Spine & Upper Body - Cobra Stretch: 3 sets of 30 seconds for the front body and lower back. - Child’s Pose: 2 sets of 1 minute for full back relaxation. - Thread the Needle: 2 sets of 30 seconds per side for upper back rotation. - Doorway Chest Stretch: 2 sets of 30 seconds to fix "hunched" posture. - Seated Spinal Twist: 3 sets of 20 seconds per side. ➡️Day 4: Active Flexibility Flow - Stretch: 1 minute per side (lunge + thoracic twist). - Dynamic Lunges with Twist: 2 sets of 10 reps. - Deep Squat Hold: 1–2 minutes (opens ankles and hips). - Wall Angels: 2 sets of 15 reps for shoulder mobility. - Standing Side Stretch: 2 sets of 20 seconds per side. ➡️Day 5: Dynamic Stretching - Sun Salutations: 3 rounds (gentle flow). - Figure-Four Stretch: 2 minutes per side for glutes. - Pancake Stretch: 2 sets of 1 minute (legs wide, leaning forward). - Overhead Triceps Stretch: 30 seconds per side. - Savasana (Corpse Pose): 3–5 minutes for final relaxation. """ } text = plans.get(goal, "### 5-Day General Fitness Plan\nCustomized for your BMI and Age...") return [{"generated_text": text}] # --- Helper Functions --- def calculate_bmi(w, h_cm): if h_cm > 0: return round(w / ((h_cm / 100) ** 2), 2) return None def get_bmi_cat(bmi): if bmi is None: return "Unknown" if bmi < 18.5: return "Underweight" if bmi < 25: return "Normal" if bmi < 30: return "Overweight" return "Obese" # --- LOGIN SCREEN --- if not st.session_state.authenticated: st.markdown("""
Your Ultimate AI-Powered Fitness Transformation
{decoded['email']}
Unlock your personalized AI workout plan
Create your profile first to unlock your AI-powered workout plan!
Your {user['goal']} Transformation Awaits ✨
{user['bmi']}
{status}
Please login again