elloxli commited on
Commit
593f4ac
Β·
verified Β·
1 Parent(s): 8a5d0cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -56
app.py CHANGED
@@ -1,78 +1,50 @@
1
-
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
- import random
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
- messages.append({"role": "user", "content": message})
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
- πŸ“ **Personalized Plan for {goal} in {timeframe}**
35
- - Warm-up: 5 min light cardio (jumping jacks, jogging in place)
36
- - Main workout: 3x10 {goal}-focused exercises
37
- - Cool-down: 5 min stretching
38
- - Nutrition tip: Stay hydrated and aim for balanced meals 🌸
 
 
 
 
 
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 AI Fitness Coach**
57
- Welcome to your pink-powered, motivational fitness buddy!
58
- Let's crush your goals together πŸ’ͺ✨
59
  """
60
  )
61
 
62
- with gr.Tab("πŸ’¬ Chat with Fitora"):
63
- gr.ChatInterface(respond, type="messages", title="Fitora - AI Fitness Coach")
64
 
65
- with gr.Tab("πŸ“ Personalized Workout Planner"):
 
66
  goal_input = gr.Textbox(label="Your Fitness Goal", placeholder="e.g., tone arms, lose weight")
67
- time_input = gr.Textbox(label="Timeframe", placeholder="e.g., 4 weeks, 3 months")
68
- plan_btn = gr.Button("Generate Plan")
 
69
  plan_output = gr.Markdown()
70
- plan_btn.click(make_workout_plan, [goal_input, time_input], plan_output)
71
 
72
- with gr.Tab("✨ Daily Motivation"):
73
- quote_btn = gr.Button("Get Inspired!")
74
  quote_output = gr.Markdown()
75
  quote_btn.click(lambda: random_quote(), outputs=quote_output)
76
 
77
- # Launch
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()