Chatterbot front-end. Machine Learning

This commit is contained in:
MikeTheWatchGuy 2018-08-24 12:20:01 -04:00
parent 60a6c07b7a
commit 595b3c0993
1 changed files with 38 additions and 0 deletions

38
Demo_Chatterbot.py Normal file
View File

@ -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)