Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
from huggingface_hub import InferenceClient
|
| 4 |
|
|
|
|
|
|
|
| 5 |
client = InferenceClient("microsoft/phi-4")
|
| 6 |
|
| 7 |
-
|
| 8 |
def respond(message, history):
|
| 9 |
-
|
| 10 |
-
messages = [
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
if history:
|
| 13 |
messages.extend(history)
|
| 14 |
|
|
|
|
| 15 |
messages.append({"role": "user", "content": message})
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Fitora: AI Fitness Chatbot
|
| 2 |
+
# Run with: pip install gradio huggingface_hub
|
| 3 |
+
|
| 4 |
import gradio as gr
|
| 5 |
+
from huggingface_hub import InferenceClient
|
|
|
|
| 6 |
|
| 7 |
+
# Create Hugging Face inference client
|
| 8 |
+
# Make sure you have a valid Hugging Face token if required
|
| 9 |
client = InferenceClient("microsoft/phi-4")
|
| 10 |
|
| 11 |
+
# Chatbot logic
|
| 12 |
def respond(message, history):
|
| 13 |
+
# System prompt for fitness personality
|
| 14 |
+
messages = [
|
| 15 |
+
{
|
| 16 |
+
"role": "system",
|
| 17 |
+
"content": (
|
| 18 |
+
"You are Fitora, an upbeat, energetic personal fitness trainer AI. "
|
| 19 |
+
"You give motivational, supportive responses with specific workout tips, "
|
| 20 |
+
"nutrition advice, and healthy lifestyle encouragement. Always be positive "
|
| 21 |
+
"and help the user stay consistent in their fitness journey."
|
| 22 |
+
)
|
| 23 |
+
}
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
# Add previous chat history if it exists
|
| 27 |
if history:
|
| 28 |
messages.extend(history)
|
| 29 |
|
| 30 |
+
# Add user message
|
| 31 |
messages.append({"role": "user", "content": message})
|
| 32 |
|
| 33 |
+
# Get AI response from Hugging Face
|
| 34 |
+
response = client.chat_completion(
|
| 35 |
+
messages,
|
| 36 |
+
max_tokens=500
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
return response['choices'][0]['message']['content'].strip()
|
| 40 |
|
| 41 |
+
# Build Gradio interface
|
| 42 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 43 |
+
gr.Markdown(
|
| 44 |
+
"""
|
| 45 |
+
# 🏋️♀️ **Fitora — Your AI Fitness Coach**
|
| 46 |
+
Your virtual workout buddy!
|
| 47 |
+
Get workout plans, nutrition tips, and a boost of motivation.
|
| 48 |
+
Let’s reach your goals together 💪🔥
|
| 49 |
+
"""
|
| 50 |
+
)
|
| 51 |
+
chatbot = gr.ChatInterface(
|
| 52 |
+
respond,
|
| 53 |
+
type="messages",
|
| 54 |
+
title="Fitora - AI Fitness Coach",
|
| 55 |
+
examples=[
|
| 56 |
+
["Give me a 15-minute HIIT workout for home"],
|
| 57 |
+
["Motivate me to do a workout after a long day"],
|
| 58 |
+
["Suggest a quick healthy breakfast"],
|
| 59 |
+
["What’s a good stretching routine before running?"]
|
| 60 |
+
]
|
| 61 |
+
)
|
| 62 |
|
| 63 |
+
# Launch app
|
| 64 |
+
if __name__ == "__main__":
|
| 65 |
+
demo.launch()
|