Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Chatbot 1

from tkinter import *


root = Tk()
def send():
send = "You:"+ e.get()
text.insert(END,"\n" + send)
if(e.get()=='hi'):
text.insert(END, "\n" + "Bot: hello")
elif(e.get()=='hello'):
text.insert(END, "\n" + "Bot: hi")
elif (e.get() == 'how are you?'):
text.insert(END, "\n" + "Bot: i'm fine and you?")
elif (e.get() == "i'm fine too"):
text.insert(END, "\n" + "Bot: nice to hear that")
else:
text.insert(END, "\n" + "Bot: Sorry I didnt get it.")
text = Text(root,bg='blue', fg='white')
text.grid(row=0,column=0,columnspan=2)
e = Entry(root,width=80)
send = Button(root,text='Send',bg='deeppink', fg='white',
width=20,command=send).grid(row=1,column=1)
e.grid(row=1,column=0)
root.title('CHATBOT.COM')
root.mainloop()

Chatbot 2

# importing the required modules  

1. from chatterbot import ChatBot  
2. from chatterbot.trainers import ListTrainer  
3. from chatterbot.trainers import ChatterBotCorpusTrainer  
4.   
5. # creating a chatbot  
6. myBot = ChatBot(  
7.     name = 'Sakura',  
8.     read_only = True,  
9.     logic_adapters = [  
10.         'chatterbot.logic.MathematicalEvaluation',  
11.         'chatterbot.logic.BestMatch'  
12.         ]  
13.         )  
14.   
15. # training the chatbot  
16. small_convo = [  
17.     'Hi there!',  
18.     'Hi',  
19.     'How do you do?',  
20.     'How are you?',  
21.     'I\'m cool.',  
22.     'Always cool.',  
23.     'I\'m Okay',  
24.     'Glad to hear that.',  
25.     'I\'m fine',  
26.     'I feel awesome',  
27.     'Excellent, glad to hear that.',  
28.     'Not so good',  
29.     'Sorry to hear that.',  
30.     'What\'s your name?',  
31.     ' I\'m Sakura. Ask me a math question, please.'  
32.     ]  
33.   
34. math_convo_1 = [  
35.     'Pythagorean theorem',  
36.     'a squared plus b squared equals c squared.'  
37.     ]  
38.   
39. math_convo_2 = [  
40.     'Law of Cosines',  
41.     'c**2 = a**2 + b**2 - 2*a*b*cos(gamma)'  
42.     ]  
43.   
44. # using the ListTrainer class  
45. list_trainee = ListTrainer(myBot)  
46. for i in (small_convo, math_convo_1, math_convo_2):  
47.     list_trainee.train(i)  
48.   
49. # using the ChatterBotCorpusTrainer class  
50. corpus_trainee = ChatterBotCorpusTrainer(myBot)  
51. corpus_trainee.train('chatterbot.corpus.english')  

You might also like