-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (54 loc) · 1.4 KB
/
main.py
File metadata and controls
71 lines (54 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# import the necessary libraries
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
from tkinter import *
# create object
bot = ChatBot("Roboz")
# create conversations
convo = [
'hello',
'hi there!',
'what is your name?',
'My name is Roboz, I am created by Shaona Kundu',
'how are you?',
'I am fine',
'thank you',
'Where do you live?',
'I live in Kolkata, WB',
'In which language do you speak?',
'I mostly talk in English'
]
trainer = ListTrainer(bot)
# train the bot with help of trainer
trainer.train(convo)
# print("Talk to bot")
# while True:
# query = input()
# if query == 'exit':
# break
# ans = bot.get_response(query)
# print("bot : ", ans)
main = Tk()
main.geometry("500x650")
main.title("My Chat Bot")
img = PhotoImage(file="bot1.png")
photoL = Label(main, image=img)
photoL.pack(pady=5)
def ask_from_bot():
query = textF.get()
answer_from_bot = bot.get_response(query)
msgs.insert(END, "You : " + query)
msgs.insert(END, "Bot : " + str(answer_from_bot))
textF.delete(0, END)
frame = Frame(main)
sc = Scrollbar(frame)
msgs = Listbox(frame, width=80, height=20)
sc.pack(side=RIGHT, fill=Y)
msgs.pack(side=LEFT, fill=BOTH, pady=10)
frame.pack()
# creating text field
textF = Entry(main, font=("Verdana", 20))
textF.pack(fill=X, pady=10)
btn = Button(main, text="Ask from Bot", font=("Verdana", 20), command=ask_from_bot)
btn.pack()
main.mainloop()