From 21dc55d1d79ec711f369b63526e59c3b7f39c340 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Fri, 24 Aug 2018 12:19:05 -0400 Subject: [PATCH] Chatterbot GUI Front End - Machine Learning Initial checkin of a GUI front-end to the Chatterbot Machine Learning software package. Uses graphical progress meters to show training progress Provides a "chat-window" style interface for conversing --- Demo_Chatterbot.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Demo_Chatterbot.py diff --git a/Demo_Chatterbot.py b/Demo_Chatterbot.py new file mode 100644 index 00000000..a0e69844 --- /dev/null +++ b/Demo_Chatterbot.py @@ -0,0 +1,38 @@ +import PySimpleGUI as gui +from chatterbot import ChatBot +import chatterbot.utils + +''' +Demo_Chatterbot.py +A GUI wrapped arouind the Chatterbot package. +The GUI is used to show progress bars during the training process and +to collect user input that is sent to the chatbot. The reply is displayed in the GUI window +''' + +# redefine the chatbot text based progress bar with a graphical one +def print_progress_bar(description, iteration_counter, total_items, progress_bar_length=20): + gui.EasyProgressMeter(description, iteration_counter, total_items) + +chatterbot.utils.print_progress_bar = print_progress_bar + +chatbot = ChatBot('Ron Obvious', trainer='chatterbot.trainers.ChatterBotCorpusTrainer') + +# Train based on the english corpus +chatbot.train("chatterbot.corpus.english") + +################# GUI ################# +with gui.FlexForm('Chat Window', auto_size_text=True, default_element_size=(30, 2)) as form: + layout = [ [gui.Output(size=(80, 20))], + [gui.Multiline(size=(70, 5), enter_submits=True), + gui.ReadFormButton('SEND', bind_return_key=True), gui.SimpleButton('EXIT')]] + + form.Layout(layout) + # ---===--- Loop taking in user input and using it to query HowDoI web oracle --- # + while True: + button, (value,) = form.Read() + if button != 'SEND': + break + print(value.rstrip()) + # send the user input to chatbot to get a response + response = chatbot.get_response(value.rstrip()) + print(response) \ No newline at end of file