def on_message(chat: ChatbotGUI, text: str): # this is where you can add chat bot functionality! # text is the text the user has entered into the chat # you can use chat.send_ai_message("") to send a message as the AI # you can use chat.start_gif() and chat.stop_gif() to start and stop the gif # you can use chat.clear() to clear the user and AI chat boxes # print the text the user entered to console print("User Entered Message: " + text) # chat.start_gif() # send a response as the AI # chat.send_ai_message("Hello!") bot_response = chatbot.get_response(text) chat.send_ai_message(bot_response) # if the user send the "clear" message clear the chats if text == "clear": chat.clear()
def on_message(gui: ChatbotGUI, user_message: str): # if the user send the "clear" message clear the chats if user_message.lower().find("clear") != -1: gui.clear() # user can say any form of bye to close the chat. elif user_message.lower().find("bye") != -1: # define a callback which will close the application def close(): gui.exit() # send the goodbye message and provide the close function as a callback gui.send_ai_message( "It has been good talking with you. Have a great day!", callback=close) else: # offload chat bot processing to a worker thread and also send the result as an ai message gui.process_and_send_ai_message(chat_bot.get_response, user_message)
def on_message(chat: ChatbotGUI, text: str): # print the text the user entered to console print("User Entered Message: " + text) ''' Here you can intercept the user input and override the bot output with your own responses and commands.''' # if the user send the "clear" message clear the chats if text.lower().find("erase chat") != -1: chat.clear() # user can say any form of bye to close the chat. elif text.lower().find("bye") != -1: def close(): chat.exit() chat.send_ai_message("Finally! Leave me alone now!", callback=close) else: # offload chat bot processing to a worker thread and also send the result as an ai message chat.process_and_send_ai_message(chatbot.get_response, text)
print("Welcome to the chat with Mr.Chatbot, ask it a question!") is_exit = True while not is_exit: request = input('You: ') response = chatbot.get_response(request) if request.lower().find("bye") != -1: is_exit = True else: print('Bot: ', response) ''' ******************* GUI Below Engine Above **************** ''' # Import for the GUI from chatbot_gui import ChatbotGUI # create the chatbot app app = ChatbotGUI("My Chat Bot (WINDOW NAME HERE)") # time import time # define the function that handles incoming user messages @app.event def on_message(chat: ChatbotGUI, text: str): # this is where you can add chat bot functionality! # text is the text the user has entered into the chat # you can use chat.send_ai_message("") to send a message as the AI # you can use chat.start_gif() and chat.stop_gif() to start and stop the gif # you can use chat.clear() to clear the user and AI chat boxes # print the text the user entered to console print("User Entered Message: " + text)
# Import for the GUI from chatbot_gui import ChatbotGUI chatbot = ChatBot("Reginald") trainer_personality_reginald = ListTrainer(chatbot) trainer_personality_reginald.train(personality_reginald) ''' ******************* GUI Below Engine Above **************** ''' # creating the chatbot app app = ChatbotGUI( title="A Chat with Reginald", gif_path="skeleton.gif", show_timestamps=True, default_voice_options={ "rate": 135, "volume": 1, "voice_id": "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0" } ) # define the function that handles incoming user messages @app.event def on_message(chat: ChatbotGUI, text: str): # print the text the user entered to console print("User Entered Message: " + text) ''' Here you can intercept the user input and override the bot output with your own responses and commands.'''
def on_message(chat: ChatbotGUI, text: str): """ This is where you can add chat bot functionality! You can use chat.send_ai_message(text, callback, voice_options) to send a message as the AI. params: - text: the text you want the bot to say - callback: a function which will be executed when the AI is done talking - voice_options: a dictionary where you can provide options for the AI's speaking voice default: { "rate": 100, "volume": 0.8, "voice": "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0" } You can use chat.start_gif() and chat.stop_gif() to start and stop the gif. You can use chat.clear() to clear the user and AI chat boxes. You can use chat.process_and_send_ai_message to offload chatbot processing to a thread to prevent the GUI from freezing up. params: - ai_response_generator: A function which takes a string as it's input (user message) and responds with a string (AI's response). - text: The text that the ai is responding to. - callback: a function which will be executed when the AI is done talking - voice_options: a dictionary where you can provide options for the AI's speaking voice default: { "rate": 100, "volume": 0.8, "voice": "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0" } :param chat: The chat box object. :param text: Text the user has entered. :return: """ # this is where you can add chat bot functionality! # text is the text the user has entered into the chat # you can use chat.send_ai_message("some text") to send a message as the AI, this will do background # you can use chat.start_gif() and chat.stop_gif() to start and stop the gif # you can use chat.clear() to clear the user and AI chat boxes # print the text the user entered to console print("User Entered Message: " + text) ''' Here you can intercept the user input and override the bot output with your own responses and commands.''' # if the user send the "clear" message clear the chats if text.lower().find("erase chat") != -1: chat.clear() # user can say any form of bye to close the chat. elif text.lower().find("bye") != -1: # define a callback which will close the application def close(): chat.exit() # send the goodbye message and provide the close function as a callback chat.send_ai_message( "It has been good talking with you. Have a great day! Later!", callback=close) else: # offload chat bot processing to a worker thread and also send the result as an ai message chat.process_and_send_ai_message(chatbot.get_response, text)
# create the chatbot app """ Options - title: App window title. - gif_path: File Path to the ChatBot gif. - show_timestamps: If the chat has time-stamps. - default_voice_options: The voice options provided to the text-to-speech engine by default if not specified when calling the send_ai_message() function. """ app = ChatbotGUI( title="Funbot", gif_path="download.gif", show_timestamps=True, default_voice_options={ "rate": 100, "volume": 0.8, "voice": "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0" }) # define the function that handles incoming user messages @app.event def on_message(chat: ChatbotGUI, text: str): """ This is where you can add chat bot functionality! You can use chat.send_ai_message(text, callback, voice_options) to send a message as the AI. params:
chat_bot_corpus_trainer.train('chatterbot.corpus.english') # train chat bot using our custom intents chat_bot_list_trainer.train(personality_mars) chat_bot_list_trainer.train(personality_europa) # import GUI from chatbot_gui import ChatbotGUI # create the chatbot app object app = ChatbotGUI( title="Space Bot", gif_path="talking-robot.gif", show_timestamps=True, default_voice_options={ "rate": 130, "volume": 0.8, "voice": "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0" }) # define function for handling incoming messages from the UI @app.event def on_message(gui: ChatbotGUI, user_message: str): # if the user send the "clear" message clear the chats if user_message.lower().find("clear") != -1: gui.clear() # user can say any form of bye to close the chat. elif user_message.lower().find("bye") != -1: