elloxli commited on
Commit
5c1f773
·
verified ·
1 Parent(s): 593f4ac

Update app.py

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