Проект Chatbot, использующий chatterbot & chatterbot-corpus, дает неправильный вывод на все вопросы, которые я задаю - PullRequest
1 голос
/ 28 февраля 2020

Я пытаюсь создать проект чат-бота, используя python 3.6 & Pycharm в качестве IDE, но ответы, которые он дает в качестве вывода, не подходят и не имеют абсолютно никакого смысла. Итак, мой вопрос: как мне его тренировать или какие изменения я должен сделать, чтобы он дал мне соответствующий результат.

Это скриншот моего разговора с моим чат-ботом. Что не имеет смысла

Here is my code:

from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
import conversation_module
from tkinter import *
import speech_recognition as s
import threading
import pyaudio
import pyttsx3 as pp
import win32com.client

eng = pp.init()

voices = eng.getProperty('voices')
print(voices)

eng.setProperty('voice', voices[0].id)

def speak(word):
    eng.say(word)
    eng.runAndWait()

bot = ChatBot("Bot1")
convo = conversation_module.con(bot)
trainer = ListTrainer(bot)
trainer.train(convo)

main = Tk()
main.geometry("500x700")
main.title("CS Department")
img = PhotoImage(file='unnamed.png')
photo = Label(main, image=img)
photo.pack(pady=2)

frame = Frame(main)
sc = Scrollbar(frame)
msg = Listbox(frame, width=80, height=20, yscrollcommand=sc.set)
sc.pack(side=RIGHT, fill=Y)
msg.pack(side=LEFT, fill=BOTH, pady=10)
frame.pack()

#take query : it takes audio as a input & convert it into string
def take_query():
    sr=s.Recognizer() #i want to use the class which are defined within the speechrec module
    sr.pause_threshold=1
    print("Your Bot is listening try to speak")
    with s.Microphone() as m:
        try:
            audio = sr.listen(m)
            question = sr.recognize_google(audio, language='eng-in')
            print(question)
            text.delete(0, END)
            text.insert(0, question)
            Ask_from_Bot()
        except Exception as e:
            print(e)
            print("Not recognized")

def Ask_from_Bot():
    question = text.get()
    ans = bot.get_response(question)
    msg.insert(END, "You : " + question)
    print(type(ans))
    msg.insert(END, "Bot : " + str(ans))
    speak(ans)
    text.delete(0, END)
    msg.yview(END)

# Creating text field
text = Entry(main, font=("Times", 15))
text.pack(pady=10)

btn = Button(main, text="Ask From Bot", font=("Times", 16), command=Ask_from_Bot)
btn.pack()

# Press Enter & get Output
def Enter_fun(event):
    btn.invoke()

main.bind('<Return>', Enter_fun)
def repeatL():
    while True:
        take_query()
t=threading.Thread(target=repeatL)
t.start()
main.mainloop()
...