DrishtiSharma's picture
Upload 6 files
7ef4406 verified
raw
history blame
4.63 kB
import gradio as gr
from langchain_core.messages import HumanMessage
from config import *
from tools import tools
from agents import *
from workflow import create_workflow
graph = create_workflow()
def run_graph(input_message, history):
try:
# relevant fitness-related keywords to handle irrelevant user prompts
relevant_keywords = [
"workout", "training", "exercise", "cardio", "strength training", "hiit (high-intensity interval training)",
"flexibility", "yoga", "pilates", "aerobics", "crossfit", "bodybuilding", "endurance", "running",
"cycling", "swimming", "martial arts", "stretching", "warm-up", "cool-down",
"diet plan", "meal plan", "macronutrients", "micronutrients", "vitamins", "minerals", "protein",
"carbohydrates", "fats", "calories", "calorie", "daily", "nutrition", "supplements", "hydration", "weightloss",
"weight gain", "healthy eating","health", "fitness", "intermittent fasting", "keto diet", "vegan diet", "paleo diet",
"mediterranean diet", "gluten-free", "low-carb", "high-protein", "bmi", "calculate", "body mass index", 'calculator'
"mental health", "mindfulness", "meditation", "stress management", "anxiety relief", "depression",
"positive thinking", "motivation", "self-care", "relaxation", "sleep hygiene", "therapy",
"counseling", "cognitive-behavioral therapy (cbt)", "mood tracking", "mental", "emotional well-being",
"healthy lifestyle", "fitness goals", "health routines", "daily habits", "ergonomics",
"posture", "work-life balance", "workplace", "habit tracking", "goal setting", "personal growth",
"injury prevention", "recovery", "rehabilitation", "physical therapy", "sports injuries",
"pain management", "recovery techniques", "foam rolling", "stretching exercises",
"injury management", "injuries", "apps", "health tracking", "wearable technology", "equipment",
"home workouts", "gym routines", "outdoor activities", "sports", "wellness tips", "water", "adult", "adults"
"child", "children", "infant", "sleep", "habit", "habits", "routine", "loose", "weight", "fruits", "vegetables",
"chicken", "veg", "vegetarian", "non-veg", "non-vegetarian", "plant", "plant-based", "plant based", "fat", "resources",
"help", "cutting", "bulking", "link", "links", "website", "online", "websites", "peace", "mind", "equipments", "equipment",
"watch", "tracker", "watch", "band", "height", "injured", "quick", "remedy", "solution", "solutions", "pain", "male", "female"
]
greetings=["hello", "hi", "how are you doing"]
# Check if the input message contains any relevant keywords
if any(keyword in input_message.lower() for keyword in relevant_keywords):
response = graph.invoke({
"messages": [HumanMessage(content=input_message)]
})
return response['messages'][1].content
elif any(keyword in input_message.lower() for keyword in greetings):
return "Hi there, I am FIT bot, your personal wellbeing coach "
else:
return "I'm here to assist with fitness, nutrition, mental health, and related topics. Please ask questions related to these areas."
except Exception as e:
return f"An error occurred while processing your request: {e}"
bot = gr.Chatbot(render=False,placeholder="<strong>Your Personal Assistant</strong><br>Ask Me Anything",
show_copy_button=True,
layout="bubble",
container=True,
label="FIT.AI",
show_label=True,
avatar_images=("user.png","bot.png"),
likeable=True)
demo = gr.ChatInterface(
fn=run_graph,
clear_btn="πŸ—‘οΈ Clear",
theme="soft",
undo_btn="Delete Previous",
autofocus=True,
textbox=gr.Textbox(placeholder="Ask away any fitness related questions", scale=7),
stop_btn="Stop",
show_progress="full",
description="<strong>An intelligent assistant for fitness, diet and mental health guidance.<strong>",
js="custom.js",
examples=["Provide health and fitness tips", "My daily Calorie intake",
"Better mental health","Best sleep habits","Water intake for a fully grown adult",
"Ergonomics in the workplace","Injuries Rehabilitation"],
chatbot=bot,
)
demo.launch(share=True)