-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcbot.py
More file actions
82 lines (71 loc) · 3.04 KB
/
Copy pathcbot.py
File metadata and controls
82 lines (71 loc) · 3.04 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
72
73
74
75
76
77
78
79
80
81
82
import tkinter # python inbuilt package
from tkinter import * #importing all the package
import datetime # for date and time
import wikipedia # for searchin in wiki
import webbrowser
import os
from chatterbot import ChatBot
#from chatterbot.trainers import ChatterBotCorpusTrainer
sam_bot = ChatBot("SAM", storage_adapter="chatterbot.storage.SQLStorageAdapter",logic_adapters=[
"chatterbot.logic.BestMatch"
],
database_uri="sqlite:///db.sqlite3")
#trainer = ChatterBotCorpusTrainer(sam_bot)
#trainer.train("chatterbot.corpus.english")
chromedir= 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s' #for windows
def chat_response(msg):
feed = msg
if 'open youtube' in feed:
webbrowser.get(chromedir).open("youtube.com") # for windows
#webbrowser.open("youtube.com") # for every os
return str('Opening Youtube')
elif 'your name' in feed:
return str("My name is Sam")
elif 'play music' in feed:
music_dir = "E:\Gugan\Music"
#music_dir = "/media/gugan/Gugan/Gugan/Music"
songs = os.listdir(music_dir)
#os.system(os.path.join(music_dir, songs[1])) # for linux
os.startfile(os.path.join(music_dir, songs[0])) # for windows
return str('Opening music')
elif 'time' in feed:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
return str(f"Sir, the time is {strTime}")
elif 'who created' in feed:
return str("I am created by Gugan and Vikash")
else:
return str(sam_bot.get_response(feed))
def send():
"""
This method is for to get from user and displays to chatbox with bot response
"""
msg = EntryBox.get("1.0",'end-1c').strip()
EntryBox.delete("0.0",END)
if msg != '':
ChatBox.config(state=NORMAL)
ChatBox.insert(END, "YOU: " + msg + '\n\n')
ChatBox.config(foreground="#ffffff", font=("Helvetica", 12 ))
res = chat_response(msg)
ChatBox.insert(END, "SAM: " + res + '\n\n')
ChatBox.config(state=DISABLED)
ChatBox.yview(END)
sam = Tk()
sam.title("Sam Chatbot")
sam.geometry("400x440")
sam.iconbitmap('E:/bot/S.ico')
sam.resizable(width=False, height=False)
ChatBox = Text(sam, bg="#00264d", bd=2, height="30", width="42",
font="Arial",cursor="heart")
ChatBox.config(state=NORMAL)
scrollbar = Scrollbar(sam, command=ChatBox.yview, cursor="heart")
ChatBox['yscrollcommand'] = scrollbar.set
SendButton = Button(sam, font=("Verdana",8,'bold'), text="Send", width="9",
height="4", bd=3, bg="#005C97",
activebackground="#2093A7",fg='#ffffff',
command= lambda:send())
EntryBox = Text(sam, bd=2, bg="#B9B4B1",width="25", height="2", font=("Arial",15))
scrollbar.place(x=385,y=6, height=386, width=10)
ChatBox.place(x=6,y=6, height=386, width=375)
EntryBox.place(x=6, y=401, height=30, width=280)
SendButton.place(x=300, y=400, height=30)
sam.mainloop()