Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,78 +1,50 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
# --- Hugging Face API setup ---
|
| 7 |
-
HF_TOKEN = "hf_xxxxxxxxxxxxxxxxxxxxx" # <-- paste your token here
|
| 8 |
-
client = InferenceClient("microsoft/phi-4", token=HF_TOKEN)
|
| 9 |
-
|
| 10 |
-
# --- Chatbot function ---
|
| 11 |
-
def respond(message, history):
|
| 12 |
-
messages = [
|
| 13 |
-
{
|
| 14 |
-
"role": "system",
|
| 15 |
-
"content": (
|
| 16 |
-
"You are Fitora, an upbeat, energetic personal fitness trainer AI. "
|
| 17 |
-
"You give motivational, supportive responses with specific workout tips, "
|
| 18 |
-
"nutrition advice, and healthy lifestyle encouragement. Always be positive "
|
| 19 |
-
"and help the user stay consistent in their fitness journey."
|
| 20 |
-
)
|
| 21 |
-
}
|
| 22 |
-
]
|
| 23 |
-
if history:
|
| 24 |
-
messages.extend(history)
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
response = client.chat_completion(messages, max_tokens=500)
|
| 29 |
-
return response['choices'][0]['message']['content'].strip()
|
| 30 |
-
|
| 31 |
-
# --- Personalized workout planner ---
|
| 32 |
-
def make_workout_plan(goal, timeframe):
|
| 33 |
plan = f"""
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
"""
|
| 40 |
return plan
|
| 41 |
|
| 42 |
-
# --- Daily motivation generator ---
|
| 43 |
-
quotes = [
|
| 44 |
-
"πͺ Push yourself, because no one else is going to do it for you.",
|
| 45 |
-
"πΈ Progress, not perfection.",
|
| 46 |
-
"ποΈββοΈ The only bad workout is the one you didnβt do.",
|
| 47 |
-
"β¨ Your body can stand almost anything. Itβs your mind you have to convince."
|
| 48 |
-
]
|
| 49 |
-
def random_quote():
|
| 50 |
-
return random.choice(quotes)
|
| 51 |
|
| 52 |
-
# --- Build UI ---
|
| 53 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="pink", secondary_hue="rose")) as demo:
|
|
|
|
| 54 |
gr.Markdown(
|
| 55 |
"""
|
| 56 |
-
# πΈ **Fitora β Your
|
| 57 |
-
Welcome to your
|
| 58 |
-
Let
|
| 59 |
"""
|
| 60 |
)
|
| 61 |
|
| 62 |
-
|
| 63 |
-
gr.ChatInterface(respond, type="messages", title="Fitora - AI Fitness Coach")
|
| 64 |
|
| 65 |
-
|
|
|
|
| 66 |
goal_input = gr.Textbox(label="Your Fitness Goal", placeholder="e.g., tone arms, lose weight")
|
| 67 |
-
|
| 68 |
-
|
|
|
|
| 69 |
plan_output = gr.Markdown()
|
| 70 |
-
plan_btn.click(make_workout_plan, [goal_input,
|
| 71 |
|
| 72 |
-
|
| 73 |
-
quote_btn = gr.Button("Get Inspired!")
|
| 74 |
quote_output = gr.Markdown()
|
| 75 |
quote_btn.click(lambda: random_quote(), outputs=quote_output)
|
| 76 |
|
| 77 |
-
|
| 78 |
demo.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
+
return response['choices'][0]['message']['content'].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
# --- Personalized workout planner ---
|
| 6 |
+
def make_workout_plan(name, goal, style, days):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
plan = f"""
|
| 8 |
+
πΈ **Hi {name}! Hereβs Your Personalized Plan** πΈ
|
| 9 |
+
**Goal:** {goal}
|
| 10 |
+
**Style:** {style}
|
| 11 |
+
**Days per week:** {days}
|
| 12 |
+
|
| 13 |
+
**Plan:**
|
| 14 |
+
- Warm-up: 5 min light cardio
|
| 15 |
+
- Main workout: Mix of {style}-focused exercises ({days} days/week)
|
| 16 |
+
- Nutrition tip: Stay hydrated and eat balanced meals π₯
|
| 17 |
+
- Motivation: Progress over perfection, always! β¨
|
| 18 |
"""
|
| 19 |
return plan
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# --- Build UI ---
|
| 23 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="pink", secondary_hue="rose")) as demo:
|
| 24 |
+
gr.Image(value="/mnt/data/8e79ec27-2f8b-4ebf-a249-114a8c0dbc15.png", show_label=False, elem_id="logo")
|
| 25 |
gr.Markdown(
|
| 26 |
"""
|
| 27 |
+
## πΈ **Fitora β Be Your Own Inspiration** πΈ
|
| 28 |
+
Welcome to your cute, colorful fitness buddy!
|
| 29 |
+
Letβs make workouts fun, personal, and motivating πͺβ¨
|
| 30 |
"""
|
| 31 |
)
|
| 32 |
|
| 33 |
+
gr.ChatInterface(respond, type="messages", title="Fitora - AI Fitness Coach")
|
|
|
|
| 34 |
|
| 35 |
+
with gr.Tab("π Personalized Workout Planner"):
|
| 36 |
+
name_input = gr.Textbox(label="Your Name", placeholder="e.g., Ella")
|
| 37 |
goal_input = gr.Textbox(label="Your Fitness Goal", placeholder="e.g., tone arms, lose weight")
|
| 38 |
+
style_input = gr.Dropdown(["Yoga", "HIIT", "Strength Training", "Pilates", "Mixed"], label="Preferred Workout Style")
|
| 39 |
+
days_slider = gr.Slider(1, 7, step=1, label="Days per Week")
|
| 40 |
+
plan_btn = gr.Button("Generate My Plan β¨")
|
| 41 |
plan_output = gr.Markdown()
|
| 42 |
+
plan_btn.click(make_workout_plan, [name_input, goal_input, style_input, days_slider], plan_output)
|
| 43 |
|
| 44 |
+
with gr.Tab("β¨ Daily Motivation"):
|
| 45 |
+
quote_btn = gr.Button("Get Inspired! π")
|
| 46 |
quote_output = gr.Markdown()
|
| 47 |
quote_btn.click(lambda: random_quote(), outputs=quote_output)
|
| 48 |
|
| 49 |
+
|
| 50 |
demo.launch()
|