chatbot / app.py
elloxli's picture
Update app.py
844cb96 verified
# Fitora: AI Fitness Chatbot
# Run with: pip install gradio huggingface_hub
import gradio as gr
from huggingface_hub import InferenceClient
# Create Hugging Face inference client
# Make sure you have a valid Hugging Face token if required
client = InferenceClient("microsoft/phi-4")
# Chatbot logic
def respond(message, history):
# System prompt for fitness personality
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."
)
}
]
# Add previous chat history if it exists
if history:
messages.extend(history)
# Add user message
messages.append({"role": "user", "content": message})
# Get AI response from Hugging Face
response = client.chat_completion(
messages,
max_tokens=500
)
return response['choices'][0]['message']['content'].strip()
# Build Gradio interface
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown(
"""
# 🏋️‍♀️ **Fitora — Your AI Fitness Coach**
Your virtual workout buddy!
Get workout plans, nutrition tips, and a boost of motivation.
Let’s reach your goals together 💪🔥
"""
)
chatbot = gr.ChatInterface(
respond,
type="messages",
title="Fitora - AI Fitness Coach",
examples=[
["Give me a 15-minute HIIT workout for home"],
["Motivate me to do a workout after a long day"],
["Suggest a quick healthy breakfast"],
["What’s a good stretching routine before running?"]
]
)
# Launch app
if __name__ == "__main__":
demo.launch()