快来!建立你的第一个Python聊天机器人项目
ChatBox.insert(END, "You: " + msg+ 'nn') ChatBox.config(foreground="#446665", font=("Verdana", 12 )) ints= predict_class(msg) res= getResponse(ints,intents) ChatBox.insert(END, "Bot: " + res+ 'nn') ChatBox.config(state=DISABLED) ChatBox.yview(END) root= Tk() root.title("Chatbot") root.geometry("400x500" root.resizable(width=FALSE, height=FALSE) #Create Chat window ChatBox= Text(root, bd=0, bg="white",height="8", width="50", font="Arial",) ChatBox.config(state=DISABLED) #Bind scrollbar to Chat window scrollbar= Scrollbar(root,command=ChatBox.yview, cursor="heart") ChatBox['yscrollcommand'] = scrollbar.set #Create Button to send message SendButton = Button(root,font=("Verdana",12,'bold'),text="Send", width="12", height=5, bd=0,bg="#f9a602",activebackground="#3c9d9b",fg='#000000', command=send ) #Create the box to enter message EntryBox= Text(root, bd=0, bg="white",width="29", height="5", font="Arial") #EntryBox.bind("<Return>",send) #Place all components on the screen scrollbar.place(x=376,y=6, height=386) ChatBox.place(x=6,y=6, height=386,width=370) EntryBox.place(x=128,y=401, height=90,width=265) SendButton.place(x=6,y=401, height=90) root.mainloop() 运行聊天机器人 现在有两个独立的文件,一个是train_chatbot.py,首先使用它来训练模型。 pythontrain_chatbot.py (编辑:晋中站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |