File size: 3,423 Bytes
a3b6a00
1585782
 
5c1f773
 
 
a3b6a00
 
 
 
5c1f773
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1585782
5c1f773
 
a3b6a00
5c1f773
 
 
593f4ac
26d2918
593f4ac
 
 
 
5c1f773
593f4ac
 
 
 
26d2918
 
 
5c1f773
 
 
 
 
 
 
 
 
26d2918
5c1f773
8a5d0cc
a3b6a00
72419ee
 
6e9259c
593f4ac
 
72419ee
 
1585782
5c1f773
 
26d2918
5c1f773
593f4ac
26d2918
593f4ac
 
 
26d2918
593f4ac
26d2918
5c1f773
593f4ac
26d2918
 
 
 
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
import os
import gradio as gr
from huggingface_hub import InferenceClient
import random

# --- Hugging Face API setup ---
HF_TOKEN = os.environ.get("HF_TOKEN")  # Safely get from secrets
if not HF_TOKEN:
    raise ValueError("❌ HF_TOKEN not found. Please set it in Hugging Face Space settings.")

client = InferenceClient("microsoft/phi-4", token=HF_TOKEN)

# --- Chatbot function ---
def respond(message, history):
    messages = [
        {
            "role": "system",
            "content": (
                "You are Fitora, an upbeat, energetic personal fitness trainer AI. "
                "You give motivational, supportive responses with specific workout tips, "
                "nutrition advice, and healthy lifestyle encouragement. Always be positive "
                "and help the user stay consistent in their fitness journey."
            )
        }
    ]
    if history:
        messages.extend(history)

    messages.append({"role": "user", "content": message})

    response = client.chat_completion(messages=messages, max_tokens=500)
    return response['choices'][0]['message']['content'].strip()

# --- Personalized workout planner ---
def make_workout_plan(name, goal, style, days):
    plan = f"""
    🌸 **Hi {name}! Here’s Your Personalized Plan** 🌸  
    **Goal:** {goal}  
    **Style:** {style}  
    **Days per week:** {days}  
    **Plan:**  
    - Warm-up: 5 min light cardio  
    - Main workout: Mix of {style}-focused exercises ({days} days/week)  
    - Nutrition tip: Stay hydrated and eat balanced meals 🥗  
    - Motivation: Progress over perfection, always! ✨
    """
    return plan

# --- Daily motivation generator ---
quotes = [
    "💪 Push yourself, because no one else is going to do it for you.",
    "🌸 Progress, not perfection.",
    "🏋️‍♀️ The only bad workout is the one you didn’t do.",
    "✨ Your body can stand almost anything. It’s your mind you have to convince."
]
def random_quote():
    return random.choice(quotes)

# --- Build UI ---
with gr.Blocks(theme=gr.themes.Soft(primary_hue="pink", secondary_hue="rose")) as demo:
    gr.Image(value="8e79ec27-2f8b-4ebf-a249-114a8c0dbc15.png", show_label=False, elem_id="logo")
    gr.Markdown(
        """
        ## 🌸 **Fitora - Be Your Own Inspiration** 🌸  
        Welcome to your cute, colorful fitness buddy!  
        Let’s make workouts fun, personal, and motivating 💪✨
        """
    )

    with gr.Tab("💬 Chat with Fitora"):
        gr.ChatInterface(respond, type="messages", title="Fitora - AI Fitness Coach")

    with gr.Tab("📝 Personalized Workout Planner"):
        name_input = gr.Textbox(label="Your Name", placeholder="e.g., Ella")
        goal_input = gr.Textbox(label="Your Fitness Goal", placeholder="e.g., tone arms, lose weight")
        style_input = gr.Dropdown(["Yoga", "HIIT", "Strength Training", "Pilates", "Mixed"], label="Preferred Workout Style")
        days_slider = gr.Slider(1, 7, step=1, label="Days per Week")
        plan_btn = gr.Button("Generate My Plan ✨")
        plan_output = gr.Markdown()
        plan_btn.click(make_workout_plan, [name_input, goal_input, style_input, days_slider], plan_output)

    with gr.Tab("✨ Daily Motivation"):
        quote_btn = gr.Button("Get Inspired! 🌟")
        quote_output = gr.Markdown()
        quote_btn.click(lambda: random_quote(), outputs=quote_output)

demo.launch()