Fixed to work with latest PySimpleGUI. Used really old code! Still needs version 0.8.7 of Chatterbot
This commit is contained in:
parent
e84ef76b36
commit
9c5d49d7b4
|
@ -1,11 +1,17 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
from chatterbot import ChatBot
|
|
||||||
import chatterbot.utils
|
import chatterbot.utils
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Demo_Chatterbot.py
|
Demo_Chatterbot.py
|
||||||
|
|
||||||
|
Note - this code was written using version 0.8.7 of Chatterbot... to install:
|
||||||
|
|
||||||
|
python -m pip install chatterbot==0.8.7
|
||||||
|
|
||||||
|
It still runs fine with the old version.
|
||||||
|
|
||||||
A GUI wrapped arouind the Chatterbot package.
|
A GUI wrapped arouind the Chatterbot package.
|
||||||
The GUI is used to show progress bars during the training process and
|
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
|
to collect user input that is sent to the chatbot. The reply is displayed in the GUI window
|
||||||
|
@ -50,15 +56,32 @@ def print_progress_bar(description, iteration_counter, total_items, progress_bar
|
||||||
# redefine the chatbot text based progress bar with a graphical one
|
# redefine the chatbot text based progress bar with a graphical one
|
||||||
chatterbot.utils.print_progress_bar = print_progress_bar
|
chatterbot.utils.print_progress_bar = print_progress_bar
|
||||||
|
|
||||||
|
|
||||||
|
from chatterbot import ChatBot
|
||||||
|
from chatterbot.trainers import ChatterBotCorpusTrainer
|
||||||
|
|
||||||
|
chatbot = ChatBot('Ron Obvious')
|
||||||
|
|
||||||
|
# Create a new trainer for the chatbot
|
||||||
|
trainer = ChatterBotCorpusTrainer(chatbot)
|
||||||
|
|
||||||
|
# Train based on the english corpus
|
||||||
|
trainer.train("chatterbot.corpus.english")
|
||||||
|
|
||||||
|
# Train based on english greetings corpus
|
||||||
|
trainer.train("chatterbot.corpus.english.greetings")
|
||||||
|
|
||||||
|
# Train based on the english conversations corpus
|
||||||
|
trainer.train("chatterbot.corpus.english.conversations")
|
||||||
chatbot = ChatBot('Ron Obvious', trainer='chatterbot.trainers.ChatterBotCorpusTrainer')
|
chatbot = ChatBot('Ron Obvious', trainer='chatterbot.trainers.ChatterBotCorpusTrainer')
|
||||||
|
|
||||||
# Train based on the english corpus
|
# Train based on the english corpus
|
||||||
chatbot.train("chatterbot.corpus.english")
|
# chatbot.train("chatterbot.corpus.english")
|
||||||
|
|
||||||
################# GUI #################
|
################# GUI #################
|
||||||
|
|
||||||
layout = [[sg.Output(size=(80, 20))],
|
layout = [[sg.Multiline(size=(80, 20), reroute_stdout=True, echo_stdout_stderr=True)],
|
||||||
[sg.MLine(size=(70, 5), enter_submits=True),
|
[sg.MLine(size=(70, 5), key='-MLINE IN-', enter_submits=True, do_not_clear=False),
|
||||||
sg.Button('SEND', bind_return_key=True), sg.Button('EXIT')]]
|
sg.Button('SEND', bind_return_key=True), sg.Button('EXIT')]]
|
||||||
|
|
||||||
window = sg.Window('Chat Window', layout,
|
window = sg.Window('Chat Window', layout,
|
||||||
|
@ -66,11 +89,11 @@ window = sg.Window('Chat Window', layout,
|
||||||
|
|
||||||
# ---===--- Loop taking in user input and using it to query HowDoI web oracle --- #
|
# ---===--- Loop taking in user input and using it to query HowDoI web oracle --- #
|
||||||
while True:
|
while True:
|
||||||
event, (value,) = window.read()
|
event, values = window.read()
|
||||||
if event != 'SEND':
|
if event != 'SEND':
|
||||||
break
|
break
|
||||||
string = value.rstrip()
|
string = values['-MLINE IN-'].rstrip()
|
||||||
print(' ' + string)
|
print(' ' + string)
|
||||||
# send the user input to chatbot to get a response
|
# send the user input to chatbot to get a response
|
||||||
response = chatbot.get_response(value.rstrip())
|
response = chatbot.get_response(values['-MLINE IN-'].rstrip())
|
||||||
print(response)
|
print(response)
|
||||||
|
|
|
@ -9,6 +9,14 @@ import os
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Demo_Chatterbot.py
|
Demo_Chatterbot.py
|
||||||
|
|
||||||
|
|
||||||
|
Note - this code was written using version 0.8.7 of Chatterbot... to install:
|
||||||
|
|
||||||
|
python -m pip install chatterbot==0.8.7
|
||||||
|
|
||||||
|
It still runs fine with the old version.
|
||||||
|
|
||||||
A GUI wrapped arouind the Chatterbot package.
|
A GUI wrapped arouind the Chatterbot package.
|
||||||
The GUI is used to show progress bars during the training process and
|
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
|
to collect user input that is sent to the chatbot. The reply is displayed in the GUI window
|
||||||
|
@ -72,22 +80,22 @@ chatbot.train("chatterbot.corpus.english")
|
||||||
|
|
||||||
################# GUI #################
|
################# GUI #################
|
||||||
|
|
||||||
layout = [[sg.Output(size=(80, 20))],
|
layout = [[sg.Multiline(size=(80, 20), reroute_stdout=True, echo_stdout_stderr=True)],
|
||||||
[sg.MLine(size=(70, 5), enter_submits=True),
|
[sg.MLine(size=(70, 5), key='-MLINE IN-', enter_submits=True, do_not_clear=False),
|
||||||
sg.Button('SEND', bind_return_key=True), sg.Button('EXIT')]]
|
sg.Button('SEND', bind_return_key=True), sg.Button('EXIT')]]
|
||||||
|
|
||||||
window = sg.Window('Chat Window', layout, default_element_size=(30, 2))
|
window = sg.Window('Chat Window', layout,
|
||||||
|
default_element_size=(30, 2))
|
||||||
|
|
||||||
# ---===--- Loop taking in user input and using it to query HowDoI web oracle --- #
|
# ---===--- Loop taking in user input and using it to query HowDoI web oracle --- #
|
||||||
while True:
|
while True:
|
||||||
event, (value,) = window.read()
|
event, values = window.read()
|
||||||
if event != 'SEND':
|
if event != 'SEND':
|
||||||
break
|
break
|
||||||
string = value.rstrip()
|
string = values['-MLINE IN-'].rstrip()
|
||||||
print(' '+string)
|
print(' ' + string)
|
||||||
# send the user input to chatbot to get a response
|
# send the user input to chatbot to get a response
|
||||||
response = chatbot.get_response(value.rstrip())
|
response = chatbot.get_response(values['-MLINE IN-'].rstrip())
|
||||||
print(response)
|
print(response)
|
||||||
speak(str(response))
|
|
||||||
|
|
||||||
window.close()
|
window.close()
|
Loading…
Reference in New Issue