File size: 3,202 Bytes
f603ed2
3f25a6a
 
e32ed83
3f25a6a
 
 
e32ed83
3f25a6a
33aab2f
3f25a6a
562c12e
3f25a6a
562c12e
 
3f25a6a
562c12e
e32ed83
3f25a6a
 
57acb49
 
3f25a6a
7d1daea
3f25a6a
e32ed83
 
3f25a6a
e32ed83
b1508b9
3f25a6a
562c12e
 
 
 
 
dbe4a2d
562c12e
 
1dfaee9
 
562c12e
65af30b
562c12e
 
 
 
7d1daea
 
3f25a6a
7d1daea
b1508b9
3f25a6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b1508b9
e32ed83
3f25a6a
e32ed83
0630897
3f25a6a
65af30b
562c12e
3f25a6a
562c12e
3f25a6a
65af30b
3f25a6a
e32ed83
3f25a6a
7d1daea
3f25a6a
1ffc411
3f25a6a
 
57acb49
 
3f25a6a
 
1ffc411
3f25a6a
1ffc411
3f25a6a
65af30b
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
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import torch

# -------------------------
# Page Config
# -------------------------

st.set_page_config(page_title="FitPlan AI", page_icon="💪")

st.title("💪 FitPlan AI — Personalized Workout Generator")

st.write("Fill your details to generate AI workout plan.")

# -------------------------
# Load Model (Small for HF Spaces)
# -------------------------

@st.cache_resource
def load_model():
    tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-large")
    model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large")
    return tokenizer, model

tokenizer, model = load_model()

# -------------------------
# User Inputs
# -------------------------

name = st.text_input("Enter Your Name")

goal = st.selectbox(
    "Select Your Fitness Goal",
    ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
)

equipment = st.multiselect(
    "Available Equipment",
    ["Dumbbells", "Resistance Band", "Yoga Mat", "Skipping Rope",
     "Weight Plates", "Cycling", "Inclined Bench", "Pullups Bar", "No Equipment"]
)

fitness_level = st.radio(
    "Fitness Level",
    ["Beginner", "Intermediate", "Advanced"]
)

# -------------------------
# Function: Create Prompt
# -------------------------

def create_prompt(goal, equipment, fitness_level):

    equipment_list = ", ".join(equipment)

    # Goal instructions
    goal_map = {
        "Build Muscle": "Focus on muscle hypertrophy training.",
        "Weight Loss": "Focus on fat burning and cardio workouts.",
        "Strength Gain": "Focus on heavy compound strength exercises.",
        "Abs Building": "Focus on core and abdominal exercises.",
        "Flexible": "Focus on stretching and mobility exercises."
    }

    # Level instructions
    level_map = {
        "Beginner": "Use simple low intensity exercises.",
        "Intermediate": "Use moderate intensity exercises.",
        "Advanced": "Use high intensity advanced exercises."
    }

    prompt = f"""
    Generate a 5-day workout plan.

    Goal: {goal}
    Fitness Level: {fitness_level}
    Equipment: {equipment_list}

    Goal Instruction:
    {goal_map[goal]}

    Level Instruction:
    {level_map[fitness_level]}

    Requirements:
    - Include warm-up
    - Exercises with sets and reps
    - Rest time
    - Day-wise structure
    """

    return prompt

# -------------------------
# Generate Plan
# -------------------------

if st.button("Generate Workout Plan"):

    if not name:
        st.error("Enter your name")
    elif not equipment:
        st.error("Select at least one equipment")
    else:
        prompt = create_prompt(goal, equipment, fitness_level)

        with st.spinner("Generating your AI workout plan..."):

            inputs = tokenizer(prompt, return_tensors="pt", truncation=True)

            outputs = model.generate(
                **inputs,
                max_new_tokens=700,
                temperature=0.3,
                do_sample=True
            )

            result = tokenizer.decode(outputs[0], skip_special_tokens=True)

        st.success(f"Workout Plan for {name}")
        st.write(result)