diff --git a/README.md b/README.md index 2f53aa0..51eb13d 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,6 @@ Creating a simple Python chatbot using natural language processing and deep learning. +# Run BOT gui + +python botgui.py \ No newline at end of file diff --git a/botgui.py b/botgui.py new file mode 100644 index 0000000..1b4b924 --- /dev/null +++ b/botgui.py @@ -0,0 +1,485 @@ +import nltk +from nltk.stem import WordNetLemmatizer +from numpy.lib.arraysetops import isin +lemmatizer = WordNetLemmatizer() +import pickle +import numpy as np +from tensorflow import keras +from datetime import date, datetime +import json +import random +import time +from threading import Thread +import threading +import tkinter +from tkinter import * +import helpers as helpers +import pyaudio +import wave +import speech_recognition as sr + +from PIL import ImageTk, Image + +class GUI(Frame): + + chunk = 1024 + sample_format = pyaudio.paInt16 + channels = 2 + fs = 44100 + + def __init__(self) -> None: + + # int resources + self.intents = json.loads(open('intents.json').read()) + self.user = json.loads(open('user.json').read()) + self.words = pickle.load(open('words.pkl','rb')) + self.classes = pickle.load(open('classes.pkl','rb')) + self.model = keras.models.load_model('chatbot_model.h5') + self.YEARLY_EVENT_DICT = { + 'christmas': '2000/12/25', + 'birthday': self.user['birthday'], + 'work_aniversary': self.user['work_aniversary'] + } + self.DAILY_EVENT_DICT = { + 'ask_employee': '17:37' + } + self.REMINDER_DICT = { + 'drink_water': 0.5, + 'stand_up': 60.0, + 'walk': 60.0, + 'do_exercise': 60.0 + } + + self.p = pyaudio.PyAudio() + self.frames = [] + + # chat window which is currently hidden + self.chat_window = Tk() + self.chat_window.withdraw() + + # hello window + self.hellow_window = Toplevel() + + # set hello window as midle screen + w = 400 + h = 400 + ws = self.hellow_window.winfo_screenwidth() # width of the screen + hs = self.hellow_window.winfo_screenheight() # height of the screen + x = (ws/2) - (w/2) + y = (hs/2) - (h/2) + self.hellow_window.geometry('%dx%d+%d+%d' % (w, h, x, y)) + + # set the title + self.hellow_window.title("CareU") + self.hellow_window.resizable(width = False, + height = False) + self.hellow_window.configure(width = w, + height = h) + + # create a hello string user Label and place it + hello_str = "Greetings to you, " + helpers.get_user_name() + # hello_str = self.getResponseFromTag('inspiration', self.intents) + self.pls = Label(self.hellow_window, + text = hello_str, + justify = CENTER, + font = "Helvetica 14 bold") + self.pls.place(relheight = 0.15, + relx = 0.2, + rely = 0.07) + + # BotGui image say hi + bot_say_hi_img = ImageTk.PhotoImage(Image.open("./resources/images/ava.jpg")) + bot_say_hi_label = Label( + self.hellow_window, + image=bot_say_hi_img, + ) + bot_say_hi_label.place( + relheight = 0.50, + relwidth = 0.60, + relx = 0.2, + rely = 0.25 + ) + + # create a Miss You Button + # along with action + self.go = Button( + self.hellow_window, + text = "Let's talk!", + font = "Helvetica 14 bold", + command = lambda: self.goAhead(helpers.get_user_name()), + ) + + self.go.place( + relx = 0.4, + rely = 0.8 + ) + + # chat window run + self.chat_window.mainloop() + + #auto event + + def call_str(self, str): + self.textCons.config(state=NORMAL) + self.textCons.config(foreground="#442265", font=("Verdana", 12)) + + self.textCons.insert(END, str) + + self.textCons.config(state=DISABLED) + self.textCons.yview(END) + + + def goAhead(self, name): + self.hellow_window.destroy() + self.layout_chat_window(name) + + # The main layout of the chat + def layout_chat_window(self, name): + + self.name = name + # to show chat window123 + self.chat_window.deiconify() + + # set hello window as midle screen + w = 500 + h = 550 + ws = self.chat_window.winfo_screenwidth() # width of the screen + hs = self.chat_window.winfo_screenheight() # height of the screen + x = (ws/2) - (w/2) + y = (hs/2) - (h/2) + self.chat_window.geometry('%dx%d+%d+%d' % (w, h, x, y)) + self.chat_window.title("CareU3000") + self.chat_window.resizable(width = False, + height = False) + self.chat_window.configure(width = 470, + height = 550, + bg = "#17202A") + + # Show user name + self.labelHead = Label( + self.chat_window, + text = self.name , + font = "Helvetica 13 bold", + pady = 5 + ) + self.labelHead.place(relwidth = 1) + + # Line + self.line = Label(self.chat_window, + width = 450, + bg = "#ABB2B9") + self.line.place(relwidth = 1, + rely = 0.07, + relheight = 0.012) + + # ChatLog + self.textCons = Text(self.chat_window, + width = 20, + height = 2, + font = "Helvetica 14", + padx = 5, + pady = 5) + + image_ = ImageTk.PhotoImage(Image.open("./resources/images/Background2.jpg")) + + self.textCons.place(relheight = 0.745, + relwidth = 1, + rely = 0.08) + + self.labelBottom = Label(self.chat_window, + bg = "#ABB2B9", + height = 80) + + self.labelBottom.place(relwidth = 1, + rely = 0.825) + + self.entryMsg = Text(self.labelBottom, + font = "Helvetica 13") + + # place the given widget + # into the gui window + self.entryMsg.place(relwidth = 0.74, + relheight = 0.06, + rely = 0.008, + relx = 0.011) + + self.entryMsg.focus() + + # create record Button + self.record_button = Button( + self.labelBottom, + text = "Record", + font = "Helvetica 10 bold", + width = 10, + bg = "#ABB2B9", + command = lambda : self.startrecording() + ) + + self.record_button.place( + relx = 0.70, + rely = 0.008, + relheight = 0.06, + relwidth = 0.16 + ) + + # create stop record Button + self.stop_record_button = Button( + self.labelBottom, + text = "Stop", + font = "Helvetica 10 bold", + width = 10, + bg = "#ABB2B9", + command = lambda : self.stop_record() + ) + + # currently, we will hide stop record button + # when click record button, stop record will unhide + self.stop_record_button.pack_forget() + # self.record_button.place( + # relx = 0.70, + # rely = 0.008, + # relheight = 0.06, + # relwidth = 0.16 + # ) + + # create a Send Button + self.buttonMsg = Button(self.labelBottom, + text = "Send", + font = "Helvetica 10 bold", + width = 10, + bg = "#ABB2B9", + command = lambda : self.send()) + + self.buttonMsg.place(relx = 0.85, + rely = 0.008, + relheight = 0.06, + relwidth = 0.16) + + self.textCons.config(cursor = "arrow") + + # create a scroll bar + scrollbar = Scrollbar(self.textCons) + + # place the scroll bar + # into the gui window + scrollbar.place(relheight = 1, + relx = 0.974) + + scrollbar.config(command = self.textCons.yview) + + self.textCons.config(state = DISABLED) + + #auto call inspiration event + self.call_event("inspiration") + + # auto call event + for event in list(self.YEARLY_EVENT_DICT.keys()): + if (datetime.strptime(self.YEARLY_EVENT_DICT[event], '%Y/%m/%d').day == date.today().day and + datetime.strptime(self.YEARLY_EVENT_DICT[event], '%Y/%m/%d').month == date.today().month): + self.call_event(event) + + # auto call reminder + reminder_list = [] + # for reminder in list(self.REMINDER_DICT.keys()): + # t = Thread(target=self.call_reminder, args=(self.REMINDER_DICT[reminder], reminder,)) + # reminder_list.append(t) + # reminder_list[-1].start() + + for reminder in list(self.DAILY_EVENT_DICT.keys()): + t = Thread(target=self.call_daily, args=(self.DAILY_EVENT_DICT[reminder], reminder,)) + reminder_list.append(t) + reminder_list[-1].start() + + for event in list(self.YEARLY_EVENT_DICT.keys()): + if (datetime.strptime(self.YEARLY_EVENT_DICT[event], '%Y/%m/%d').day == date.today().day and + datetime.strptime(self.YEARLY_EVENT_DICT[event], '%Y/%m/%d').month == date.today().month): + self.call_event(event) + + def call_event(self, event): + try: + self.textCons.config(state=NORMAL) + self.textCons.config(foreground="#442265", font=("Verdana", 12 )) + + res = self.getResponseFromTag(event, self.intents) + self.textCons.insert(END, "Bot: " + res + '\n\n') + + self.textCons.config(state=DISABLED) + self.textCons.yview(END) + except: + pass + + def call_reminder(self, sleep_time, event): + while 1: + time.sleep(sleep_time * 60) # Sleep_time is in minute + self.call_event(event) + + def call_daily(self, time_call, event): + while 1: + time.sleep(60) + if datetime.strptime(time_call, '%H:%M').strftime('%H:%M') == datetime.now().strftime('%H:%M'): + self.call_event(event) + + def send(self): + msg = self.entryMsg.get("1.0",'end-1c').strip() + self.entryMsg.delete("0.0",END) + + if msg != '': + self.textCons.config(state=NORMAL) + self.textCons.insert(END, "You: " + msg + '\n\n') + self.textCons.config(foreground="#442265", font=("Verdana", 12 )) + + res = self.chatbot_response(msg) + self.textCons.insert(END, "Bot: " + res + '\n\n') + + self.textCons.config(state=DISABLED) + self.textCons.yview(END) + + def send_message(self, message): + if message != '': + self.textCons.config(state=NORMAL) + self.textCons.insert(END, "You: " + message + '\n\n') + self.textCons.config(foreground="#442265", font=("Verdana", 12 )) + + res = self.chatbot_response(message) + self.textCons.insert(END, "Bot: " + res + '\n\n') + + self.textCons.config(state=DISABLED) + self.textCons.yview(END) + + + def chatbot_response(self, msg): + ints = self.predict_class(msg, self.model) + res = self.getResponse(ints, self.intents) + return res + + def predict_class(self, sentence, model): + # filter out predictions below a threshold + p = self.bow(sentence, self.words, show_details=False) + print(p) + if not np.any(p): + return [{"intent": 'noanswer', "probability": 1.0}] + res = model.predict(np.array([p]))[0] + ERROR_THRESHOLD = 0.25 + results = [[i,r] for i,r in enumerate(res) if r>ERROR_THRESHOLD] + # sort by strength of probability + results.sort(key=lambda x: x[1], reverse=True) + return_list = [] + for r in results: + return_list.append({"intent": self.classes[r[0]], "probability": str(r[1])}) + return return_list + + def getResponse(self, ints, intents_json): + tag = ints[0]['intent'] + list_of_intents = intents_json['intents'] + result = '' + for i in list_of_intents: + if i['tag'] == tag: + result = random.choice(i['responses']) + break + return result + + def bow(self, sentence, words, show_details=True): + # tokenize the pattern + sentence_words = self.clean_up_sentence(sentence) + # bag of words - matrix of N words, vocabulary matrix + bag = [0]*len(words) + for s in sentence_words: + for i, w in enumerate(words): + if w == s: + # assign 1 if current word is in the vocabulary position + bag[i] = 1 + if show_details: + print("found in bag: %s" % w) + return(np.array(bag)) + + def clean_up_sentence(self, sentence): + sentence_words = nltk.word_tokenize(sentence) + sentence_words = [lemmatizer.lemmatize(word.lower()) for word in sentence_words] + return sentence_words + + def getResponseFromTag(self, tag, intents_json): + list_of_intents = intents_json['intents'] + result = '' + for i in list_of_intents: + if i['tag'] == tag: + result = random.choice(i['responses']) + break + return result + + def startrecording(self): + self.stream = self.p.open(format=self.sample_format,channels=self.channels,rate=self.fs,frames_per_buffer=self.chunk,input=True) + self.isrecording = True + + print('Recording') + t = threading.Thread(target=self.record) + t.start() + + # hide record button + self.record_button.pack_forget() + # unhide stop record button + self.stop_record_button.place( + relx = 0.70, + rely = 0.008, + relheight = 0.06, + relwidth = 0.16 + ) + + def record(self): + while self.isrecording: + # data = self.stream.read(self.chunk) + # self.frames.append(data) + + # file_name = "./resources/records/record.wav" + # r = sr.Recognizer() + # with sr.AudioFile(file_name) as source: + # # listen for the data (load audio to memory) + # audio_data = r.record(source) + # # recognize (convert from speech to text) + # text = r.recognize_google(audio_data, language = 'fr-CA', show_all=True) + # print(f"-----------text: {text}") + # self.call_str(text) + r = sr.Recognizer() + with sr.Microphone() as source: + print("Please wait. Calibrating microphone...") + # listen for 5 seconds and create the ambient noise energy level + r.record(source, duration=2) + # r.adjust_for_ambient_noise(source, duration=5) + print("Say something!") + audio = r.listen(source) + text = r.recognize_google(audio, language = 'en-IN', show_all = True) + for i in text["alternative"]: + trans = i["transcript"] + print(f"I thinks you said: {trans}") + # self.call_str("You: " + trans + "\n\n") + self.send_message(trans) + + + def stop_record(self): + print("Stop record") + # hide stop record button + self.stop_record_button.place_forget() + # unhide record button + self.record_button.place( + relx = 0.70, + rely = 0.008, + relheight = 0.06, + relwidth = 0.16 + ) + # self.buttonMsg.place( + # relx = 0.85, + # rely = 0.008, + # relheight = 0.06, + # relwidth = 0.16 + # ) + + self.isrecording = False + print('recording complete') + self.filename = "record.wav" + wf = wave.open("./resources/records/" + self.filename, 'wb') + wf.setnchannels(self.channels) + wf.setsampwidth(self.p.get_sample_size(self.sample_format)) + wf.setframerate(self.fs) + wf.writeframes(b''.join(self.frames)) + wf.close() + +gui = GUI() \ No newline at end of file diff --git a/chatbot_model.h5 b/chatbot_model.h5 index a30ec63..f42817e 100644 Binary files a/chatbot_model.h5 and b/chatbot_model.h5 differ diff --git a/chatgui.py b/chatgui.py index adbc6cd..1b5dfbc 100644 --- a/chatgui.py +++ b/chatgui.py @@ -1,19 +1,43 @@ - import nltk from nltk.stem import WordNetLemmatizer +from numpy.lib.arraysetops import isin lemmatizer = WordNetLemmatizer() import pickle import numpy as np - -from keras.models import load_model -model = load_model('chatbot_model.h5') +from tensorflow import keras +from datetime import date, datetime import json import random +import time +from threading import Thread +#from keras.models import load_model + + +model = keras.models.load_model('chatbot_model.h5') + intents = json.loads(open('intents.json').read()) +user = json.loads(open('user.json').read()) words = pickle.load(open('words.pkl','rb')) classes = pickle.load(open('classes.pkl','rb')) +YEARLY_EVENT_DICT = { + 'christmas': '2000/12/25', + 'birthday': user['birthday'], + 'work_aniversary': user['work_aniversary'] +} + +REMINDER_DICT = { + 'drink_water': 1.0, + 'stand_up': 2.0, + 'walk': 3.0, + 'do_exercise': 4.0 +} + +DAILY_EVENT_DICT = { + 'ask_employee': '17:37' +} + def clean_up_sentence(sentence): sentence_words = nltk.word_tokenize(sentence) sentence_words = [lemmatizer.lemmatize(word.lower()) for word in sentence_words] @@ -27,17 +51,19 @@ def bow(sentence, words, show_details=True): # bag of words - matrix of N words, vocabulary matrix bag = [0]*len(words) for s in sentence_words: - for i,w in enumerate(words): + for i, w in enumerate(words): if w == s: # assign 1 if current word is in the vocabulary position bag[i] = 1 if show_details: - print ("found in bag: %s" % w) + print("found in bag: %s" % w) return(np.array(bag)) def predict_class(sentence, model): # filter out predictions below a threshold - p = bow(sentence, words,show_details=False) + p = bow(sentence, words, show_details=False) + if not np.any(p): + return [{"intent": 'noanswer', "probability": 1.0}] res = model.predict(np.array([p]))[0] ERROR_THRESHOLD = 0.25 results = [[i,r] for i,r in enumerate(res) if r>ERROR_THRESHOLD] @@ -51,8 +77,18 @@ def predict_class(sentence, model): def getResponse(ints, intents_json): tag = ints[0]['intent'] list_of_intents = intents_json['intents'] + result = '' for i in list_of_intents: - if(i['tag']== tag): + if i['tag'] == tag: + result = random.choice(i['responses']) + break + return result + +def getResponseFromTag(tag, intents_json): + list_of_intents = intents_json['intents'] + result = '' + for i in list_of_intents: + if i['tag'] == tag: result = random.choice(i['responses']) break return result @@ -83,9 +119,43 @@ def send(): ChatLog.config(state=DISABLED) ChatLog.yview(END) +def call_event(event): + try: + ChatLog.config(state=NORMAL) + ChatLog.config(foreground="#442265", font=("Verdana", 12 )) + res = getResponseFromTag(event, intents) + ChatLog.insert(END, "Bot: " + res + '\n\n') + + ChatLog.config(state=DISABLED) + ChatLog.yview(END) + except: + pass + +def call_reminder(sleep_time, event): + while 1: + time.sleep(sleep_time * 60) # Sleep_time is in minute + call_event(event) + +def call_daily(time_call, event): + while 1: + time.sleep(60) + if datetime.strptime(time_call, '%H:%M').strftime('%H:%M') == datetime.now().strftime('%H:%M'): + call_event(event) + +def call_str(str): + ChatLog.config(state=NORMAL) + ChatLog.config(foreground="#442265", font=("Verdana", 12 )) + + ChatLog.insert(END, str) + + ChatLog.config(state=DISABLED) + ChatLog.yview(END) + +isInit = True +reminder_list = [] base = Tk() -base.title("Hello") +base.title("CareU") base.geometry("400x500") base.resizable(width=FALSE, height=FALSE) @@ -101,7 +171,7 @@ def send(): #Create Button to send message SendButton = Button(base, font=("Verdana",12,'bold'), text="Send", width="12", height=5, bd=0, bg="#32de97", activebackground="#3c9d9b",fg='#ffffff', - command= send ) + command = send ) #Create the box to enter message EntryBox = Text(base, bd=0, bg="white",width="29", height="5", font="Arial") @@ -111,7 +181,28 @@ def send(): #Place all components on the screen scrollbar.place(x=376,y=6, height=386) ChatLog.place(x=6,y=6, height=386, width=370) + +if isInit: + call_event('inspiration') + + for reminder in list(REMINDER_DICT.keys()): + t = Thread(target=call_reminder, args=(REMINDER_DICT[reminder], reminder,)) + reminder_list.append(t) + reminder_list[-1].start() + + isInit = False + +for reminder in list(DAILY_EVENT_DICT.keys()): + t = Thread(target=call_daily, args=(DAILY_EVENT_DICT[reminder], reminder,)) + reminder_list.append(t) + reminder_list[-1].start() + +for event in list(YEARLY_EVENT_DICT.keys()): + if (datetime.strptime(YEARLY_EVENT_DICT[event], '%Y/%m/%d').day == date.today().day and + datetime.strptime(YEARLY_EVENT_DICT[event], '%Y/%m/%d').month == date.today().month): + call_event(event) + EntryBox.place(x=128, y=401, height=90, width=265) SendButton.place(x=6, y=401, height=90) -base.mainloop() +base.mainloop() \ No newline at end of file diff --git a/classes.pkl b/classes.pkl index 04320f6..2bbbd27 100644 Binary files a/classes.pkl and b/classes.pkl differ diff --git a/helpers.py b/helpers.py new file mode 100644 index 0000000..b6aad8b --- /dev/null +++ b/helpers.py @@ -0,0 +1,14 @@ +import getpass + +# Bot say hello string template +def say_hello_str(): + os_username = getpass.getuser() + return f"Greetings to you, {os_username} \r\n\n" + +def get_user_name(): + user_name = getpass.getuser() + arr = user_name.split(" ") + if len(arr) > 2: + user_name = f"{arr[0]} {arr[len(arr) - 1]}" + + return user_name diff --git a/intents.json b/intents.json index a6cccc4..cf95a7e 100644 --- a/intents.json +++ b/intents.json @@ -1,9 +1,14 @@ {"intents": [ {"tag": "greeting", "patterns": ["Hi there", "How are you", "Is anyone there?","Hey","Hola", "Hello", "Good day"], - "responses": ["Hello, thanks for asking", "Good to see you again", "Hi there, how can I help?"], + "responses": ["Hello there", "Hola", "It's good to see you", "Hi there, how can I help?"], "context": [""] }, + {"tag": "inspiration", + "patterns": [], + "responses": ["Have a great day!", "Nothing is impossible, the word itself says I'm possible! Just go ahead!", "We all are special we just need to find our specialty.", "The only way to do great work is to love what you do. - Steve Jobs", "Believe you can and you are halfway there. - Theodore Roosevelt"], + "context": [""] + }, {"tag": "goodbye", "patterns": ["Bye", "See you later", "Goodbye", "Nice chatting to you, bye", "Till next time"], "responses": ["See you!", "Have a nice day", "Bye! Come back again soon."], @@ -19,6 +24,26 @@ "responses": ["Sorry, can't understand you", "Please give me more info", "Not sure I understand"], "context": [""] }, + {"tag": "eating", + "patterns": ["I am hungry", "hungry", "I want to eat something", "I need food", "food"], + "responses": ["Maybe, you should have a brunch", "Try healthy yogurt if you like", "Hmm, get some healthy snacks", "A boiled egg is a good choice", "Let's go to boost energy with some snacks."], + "context": [""] + }, + {"tag": "what_to_eat", + "patterns": ["No, it's not enough", "I dont like to eat that", "what should I eat for breakfast?", "what should I eat for lunch?", "what should I eat for dinner?", "what should I cook today?", "Can you suggest something to eat?", "No, I want more", "I wanna cook something"], + "responses": ["Healthy salad is a good choice", "How about pasta?", "You like sandwich with smoked bacon, egg & mayonaise?", "Chicken nuggets with fries & salad", "Do you want some Yangzhou fried rice & juice?", "I think you should try Simmered Pork in fish sauce with pepper & Young tofu soup", "Some healthy dishes like steamed chicken & tomato soup"], + "context": [""] + }, + {"tag": "drink", + "patterns": ["I would like to drink something now", "Can you suggest something to drink?", "Anything to drink", "I hate water"], + "responses":["Orange juice with much Vitamin C is super great for your heath this time", "Try milk juice? there are many flavors", "Do not think of soft drink like coke anymore, you should drink juice", "How about smoothies? If you have some fruit at home, try now", "Maybe a cup of coffee if you feel asleep", "Try a cup of tea with lemon, really fresh!"], + "context": [""] + }, + {"tag": "where_buy_drink", + "patterns": ["how to buy drink?", "how can I buy them?", "due to covid, I cannot go out to buy easily", "can you suggest where to buy drink?", "It's hard hard to buy now, so how can I make healthy drinks?", "how to make that?"], + "responses": ["I think you should by online and check some recepies on Google", "You should buy online on Grab or Now and then try making by yourself! I'm sure it is easy", "Let's check on Grab or Now for some fresh fruits and keep them in your refrigerator. You can make everytime you want"], + "context": [""] + }, {"tag": "options", "patterns": ["How you could help me?", "What you can do?", "What help you provide?", "How you can be helpful?", "What support is offered"], "responses": ["I can guide you through Adverse drug reaction list, Blood pressure tracking, Hospitals and Pharmacies", "Offering support for Adverse drug reaction, Blood pressure, Hospitals and Pharmacies"], @@ -68,6 +93,71 @@ "patterns": [], "responses": ["Loading hospital details"], "context": [""] + }, + {"tag": "birthday", + "patterns": [], + "responses": ["Today is your birthday, I wish you have a wonderful day!", "Happy birthday! I hope all your birthday wishes and dreams come true", "May the joy that you have spread in the past come back to you on this day. Wishing you a very happy birthday!", "Count not the candles, see the lights they give. Count not the years, but the life you live. Wishing you a wonderful time ahead. Happy birthday.", "Your birthday is the first day of another 365-day journey. Be the shining thread in the beautiful tapestry of the world to make this year the best ever. Enjoy the ride.", "A birthday is like a new year and my wish for you, is a great year full of happiness and sunshine!", "May your birthday be sprinkled with fun and laughter. Have a great day!"], + "context": [""] + }, + {"tag": "christmas", + "patterns": [], + "responses": ["Merry Christmas to you and your family", "Let us keep Christmas beautiful without a thought of greed.", "It's the season to wish one another joy, love and peace. These are my wishes for you. Merry Christmas, my dear friend. May you feel the love this special day brings.", "You make the stars shine brighter and the winter days warmer just by being in my life. Merry Christmas to my favourite person in the world", "May the joy and peace that comes with Christmas be with you all through the Year. I wish you a season of blessings from heaven above"], + "context": [""] + }, + {"tag": "work_aniversary", + "patterns": [], + "responses": ["Congratulations on your work milestone at Hitachi Vantara Vietnam, thank you for all your hardwork", "Happy Work Anniversary! Another year of excellence! Thanks for all the amazing work you do. Your effort and enthusiasm are much needed, and very much appreciated.", "Happy work anniversary! They are truly lucky to have such a smart, thoughtful, and talented person like you" ], + "context": [""] + }, + {"tag": "drink_water", + "patterns": [], + "responses": ["Let's have a sip of water, it's good for your health", "Hi, a kind reminder for you to have some water. Leggo!", "Your body told me that it really needs water! Drink now"], + "context": [""] + }, + {"tag": "stand_up", + "patterns": [], + "responses": ["You should stand up for a little while, it's good for your health"], + "context": [""] + }, + {"tag": "walk", + "patterns": [], + "responses": ["You should walk around a litle bit, it's good for your health"], + "context": [""] + }, + {"tag": "do_exercise", + "patterns": [], + "responses": ["You should do a small exercise, it's good for your health"], + "context": [""] + }, + {"tag": "ask_employee", + "patterns": [], + "responses": ["How do you feel today?"], + "context": [""] + }, + {"tag": "answer_good", + "patterns": ["good", "best", "terrific", "today is good", "it is terrific", "better", "this is the best day", "awesome", "delightful", "nice"], + "responses": ["Thank you for your response. I'm glad that you're having a good day."], + "context": [""] + }, + {"tag": "answer_neutral", + "patterns": ["normal", "neutral", "today is normal", "it is neutral", "same day", "as usual"], + "responses": ["Thank you for your response. I'm having a feeling that tomorrow is going to be nice."], + "context": [""] + }, + {"tag": "answer_bad", + "patterns": ["bad", "worse", "worst", "today is bad", "it is terrible", "worse", "this is the worst day", "not good", "I'm tired today", "boring"], + "responses": ["Thank you for your response. I'm sorry to hear that, tomorrow is going to be a brand new awesome day, trust me."], + "context": [""] + }, + {"tag": "joke", + "patterns": ["tell me a joke", "joke", "give me a joke", "tell joke", "tell a joke"], + "responses": ["I'm afraid for the calendar. Its days are numbered.", "My wife said I should do lunges to stay in shape. That would be a big step forward.", "Singing in the shower is fun until you get soap in your mouth. Then it's a soap opera.", "What do you call a fish wearing a bowtie? - Sofishticated.", "Dear Math, grow up and solve your own problems."], + "context": [""] + }, + {"tag": "sing", + "patterns": ["can you sing a song", "can you sing", "sing", "you sing", "song", "turn on a song", "give me a song"], + "responses": ["I cannot sing but here's the link, you could check this on your browser: https://youtu.be/UNZqm3dxd2w", "You can check this link for a song: https://youtu.be/FM7MFYoylVs", "I sure hope I can sing, but here's a link for a song: https://youtu.be/dvgZkm1xWPE"], + "context": [""] } ] } diff --git a/resources/images/Ava.jpg b/resources/images/Ava.jpg new file mode 100644 index 0000000..d78cbcd Binary files /dev/null and b/resources/images/Ava.jpg differ diff --git a/resources/images/Background2.jpg b/resources/images/Background2.jpg new file mode 100644 index 0000000..9dec34b Binary files /dev/null and b/resources/images/Background2.jpg differ diff --git a/resources/images/botgui_say_hi.jpg b/resources/images/botgui_say_hi.jpg new file mode 100644 index 0000000..b4e1239 Binary files /dev/null and b/resources/images/botgui_say_hi.jpg differ diff --git a/resources/images/hitachi_vantara.jpg b/resources/images/hitachi_vantara.jpg new file mode 100644 index 0000000..fa3bfca Binary files /dev/null and b/resources/images/hitachi_vantara.jpg differ diff --git a/resources/records/record.wav b/resources/records/record.wav new file mode 100644 index 0000000..878bf23 Binary files /dev/null and b/resources/records/record.wav differ diff --git a/train_chatbot.py b/train_chatbot.py index 0e7b796..27a9f93 100644 --- a/train_chatbot.py +++ b/train_chatbot.py @@ -1,15 +1,15 @@ import nltk -nltk.download('punkt') -nltk.download('wordnet') +# nltk.download('punkt') +# nltk.download('wordnet') from nltk.stem import WordNetLemmatizer lemmatizer = WordNetLemmatizer() import json import pickle import numpy as np -from keras.models import Sequential -from keras.layers import Dense, Activation, Dropout -from keras.optimizers import SGD +from tensorflow.keras.models import Sequential +from tensorflow.keras.layers import Dense, Activation, Dropout +from tensorflow.keras.optimizers import SGD import random words=[] diff --git a/user.json b/user.json new file mode 100644 index 0000000..709e87d --- /dev/null +++ b/user.json @@ -0,0 +1,5 @@ +{ + "username": "Nguyen Minh Triet", + "birthday": "1998/08/20", + "work_aniversary": "2021/08/20" +} \ No newline at end of file diff --git a/words.pkl b/words.pkl index 8ef1c26..27cd5a1 100644 Binary files a/words.pkl and b/words.pkl differ