├── images ├── demo.jpg ├── voice1.png ├── voice2.png ├── voice4.png └── chatbot.jpg ├── __pycache__ ├── keys.cpython-36.pyc ├── model.cpython-36.pyc ├── prepare.cpython-36.pyc └── weather.cpython-36.pyc ├── .gitignore ├── requirements.txt ├── weather.py ├── model.py ├── prepare.py ├── README.md ├── calender.py ├── main.py └── intents.json /images/demo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madhur215/Chatbot-cum-voice-Assistant/HEAD/images/demo.jpg -------------------------------------------------------------------------------- /images/voice1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madhur215/Chatbot-cum-voice-Assistant/HEAD/images/voice1.png -------------------------------------------------------------------------------- /images/voice2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madhur215/Chatbot-cum-voice-Assistant/HEAD/images/voice2.png -------------------------------------------------------------------------------- /images/voice4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madhur215/Chatbot-cum-voice-Assistant/HEAD/images/voice4.png -------------------------------------------------------------------------------- /images/chatbot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madhur215/Chatbot-cum-voice-Assistant/HEAD/images/chatbot.jpg -------------------------------------------------------------------------------- /__pycache__/keys.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madhur215/Chatbot-cum-voice-Assistant/HEAD/__pycache__/keys.cpython-36.pyc -------------------------------------------------------------------------------- /__pycache__/model.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madhur215/Chatbot-cum-voice-Assistant/HEAD/__pycache__/model.cpython-36.pyc -------------------------------------------------------------------------------- /__pycache__/prepare.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madhur215/Chatbot-cum-voice-Assistant/HEAD/__pycache__/prepare.cpython-36.pyc -------------------------------------------------------------------------------- /__pycache__/weather.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Madhur215/Chatbot-cum-voice-Assistant/HEAD/__pycache__/weather.cpython-36.pyc -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .google-cookie 2 | .idea/ 3 | 2020-03-29 12-29-25.514266-note.txt 4 | 2020-04-02 11-58-18.891477-note.txt 5 | 2020-04-02 12-02-23.100966-note.txt 6 | 2020-04-04 13-28-50.257437-note.txt 7 | 2020-04-04 13-29-12.895953-note.txt 8 | __pycache__/calender.cpython-36.pyc 9 | credentials.json 10 | token.pickle 11 | *note.txt 12 | keys.py -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | google==2.0.3 2 | google-api-core==1.16.0 3 | google-api-python-client==1.8.0 4 | google-auth==1.11.2 5 | google-auth-httplib2==0.0.3 6 | google-auth-oauthlib==0.4.1 7 | google-pasta==0.1.8 8 | google-search-results==1.7.1 9 | googleapis-common-protos==1.51.0 10 | grpcio==1.27.2 11 | gTTS==2.1.1 12 | gTTS-token==1.1.3 13 | Keras==2.3.1 14 | Keras-Applications==1.0.8 15 | Keras-Preprocessing==1.1.0 16 | openpyxl==3.0.3 17 | pickleshare==0.7.5 18 | Pillow==6.2.0 19 | pyttsx3==2.87 20 | pytz==2017.3 21 | SpeechRecognition==3.8.1 22 | tensorboard==2.1.0 23 | tensorflow==1.14.0 24 | tensorflow-estimator==2.1.0 25 | #openpyxl==3.0.2 26 | -------------------------------------------------------------------------------- /weather.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import keys 3 | 4 | 5 | def get_weather(city): 6 | try: 7 | key = keys.WEATHER_KEY() 8 | weather_key = key 9 | url = "https://api.openweathermap.org/data/2.5/weather" 10 | params = {'APPID': weather_key, 'q': city, 'units': 'imperial'} 11 | response = requests.get(url, params=params) 12 | weather = response.json() 13 | text = "The weather condition of " + str(weather['name']) + " is as follows " + "the overhead condition is " + \ 14 | str(weather['weather'][0]['description']) + " and the temperature in fahrenheit is " + str(weather['main']['temp']) 15 | return text 16 | except: 17 | return "Oops! Could not find any city by this name" 18 | -------------------------------------------------------------------------------- /model.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import tflearn 3 | import tensorflow as tf 4 | import nltk 5 | from nltk.stem.lancaster import LancasterStemmer 6 | 7 | class create_model: 8 | 9 | def __init__(self, train, output, tags, all_questions_words): 10 | tf.reset_default_graph() 11 | self.tags = tags 12 | self.words = all_questions_words 13 | self.network = tflearn.input_data(shape=[None,len(train[0])]) 14 | self.network = tflearn.fully_connected(self.network, 8) 15 | self.network = tflearn.fully_connected(self.network, 8) 16 | self.network = tflearn.fully_connected(self.network, len(output[0]), activation= "softmax") 17 | self.network = tflearn.regression(self.network) 18 | self.model = tflearn.DNN(self.network) 19 | 20 | def fit_model(self, train, output, n=400, batch = 8, metric=True): 21 | self.model.fit(train, output, n_epoch = n, batch_size=batch, show_metric=metric) 22 | 23 | 24 | def input_words(self, sentence): 25 | bag_of_words = [0 for _ in range(len(self.words))] 26 | stemmer = LancasterStemmer() 27 | sentence_words = nltk.word_tokenize(sentence) 28 | sentence_words = [stemmer.stem(w.lower()) for w in sentence_words] 29 | 30 | for s in sentence_words: 31 | for i,j in enumerate(self.words): 32 | if j == s: 33 | bag_of_words[i] = 1 34 | 35 | return np.array(bag_of_words) 36 | 37 | def predict_tag(self, sentence): 38 | results = self.model.predict([self.input_words(sentence)]) 39 | # tag = self.tags[np.argmax(results)] 40 | return np.argmax(results) 41 | 42 | def get_tags(self): 43 | return self.tags 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /prepare.py: -------------------------------------------------------------------------------- 1 | import nltk 2 | from nltk.stem.lancaster import LancasterStemmer 3 | import numpy as np 4 | 5 | 6 | class prepare_data: 7 | 8 | def __init__(self, data): 9 | self.all_words = [] 10 | self.all_tags = [] 11 | self.all_words_lists = [] 12 | self.tags_lists = [] 13 | self.data = data 14 | 15 | def prepare(self, level1_data, level1_index, level2_index, tag): 16 | 17 | for content in level1_data[level1_index]: 18 | for dt in content[level2_index]: 19 | token_words = nltk.word_tokenize(dt) 20 | self.all_words.extend(token_words) 21 | self.all_words_lists.append(token_words) 22 | self.tags_lists.append(content[tag]) 23 | 24 | if content[tag] not in self.all_tags: 25 | self.all_tags.append(content[tag]) 26 | 27 | 28 | 29 | stemmer = LancasterStemmer() 30 | self.all_words = [stemmer.stem(w.lower()) for w in self.all_words if w != "?" and "!"] 31 | self.all_words = sorted(list(set(self.all_words))) 32 | 33 | return self.all_words, self.all_tags, self.all_words_lists, self.tags_lists 34 | 35 | def get_training_set(self): 36 | 37 | self.questions_train = [] 38 | self.tags_output = [] 39 | r = [0 for _ in range(len(self.all_tags))] 40 | for i, word in enumerate(self.all_words_lists): 41 | bag_of_words = [] 42 | stemmer = LancasterStemmer() 43 | word = [stemmer.stem(w.lower()) for w in word] 44 | for wr in self.all_words: 45 | 46 | if wr in word: 47 | bag_of_words.append(1) 48 | else: 49 | bag_of_words.append(0) 50 | 51 | row = r[:] 52 | row[self.all_tags.index(self.tags_lists[i])] = 1 53 | self.questions_train.append(bag_of_words) 54 | self.tags_output.append(row) 55 | 56 | return self.questions_train, self.tags_output 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Chatbot cum Voice Assistant 2 | This a chatbot cum voice assistant that can be used for different purposes. It can do the following tasks: 3 | 1. Normal conversation through voice. 4 | 2. Get your all events or particular ones from your google calender. 5 | 3. Make a google search of your query and open up the browser with the results. 6 | 4. Make notes to write down something using notepad. 7 | 5. Send emails using Gmail. 8 | 6. Open music and vs code application. 9 | 7. Search directly anything on Wikipedia. 10 | 8. Get real time weather report of your city. 11 | 12 | ## Screenshots of the project 13 | ![Image](/images/chatbot.jpg) 14 | 15 | ## Installation 16 | * All the modules which are required for this application are stated in requirements.txt file. 17 | To install all of them rum the following command: 18 | ``` 19 | pip3 install -r requirements.txt 20 | ``` 21 | 22 | * Enable Google Calender API with your account here: https://developers.google.com/calendar/quickstart/python 23 | * Get a weather api key by creating your account on https://openweathermap.org/api 24 | * Create a keys.py file and add the following: 25 | * EMAIL = "your email id to send emails from" 26 | * PASSWORD = "pasword of your email id" 27 | * DICT = "A dictionary to store the emails of recipients" 28 | * WEATHER_KEY = "your weather api key" 29 | 30 | ## Working of the project 31 | The working of the assistant is pretty simple. 32 | First, a simple GUI shows up, in which you can see all your ongoing conversation. 33 | When we click on the speak icon, it detects the voice and converts it to text using 34 | speech_recognition module. 35 | On the text, first NLP is applied that creates a bag of words model which is then passed to a pre trained neural network made using the tflearn module. This network returns the "tag" with which 36 | the sentence is associated(see intents.json). 37 | This "tag" is then used to find the "sub tag" with which the sentence is associated 38 | again with the help of the same model. 39 | Once, the subtag is determined, it returns the appropriate answer associated with that 40 | subtag, and the pyttsx3 module is used to convey the answer through voice. 41 | 42 | 43 | -------------------------------------------------------------------------------- /calender.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | import datetime 3 | import pickle 4 | import os.path 5 | from googleapiclient.discovery import build 6 | from google_auth_oauthlib.flow import InstalledAppFlow 7 | from google.auth.transport.requests import Request 8 | import pytz 9 | import pyttsx3 10 | import speech_recognition as sr 11 | 12 | SCOPES = ['https://www.googleapis.com/auth/calendar.readonly'] 13 | MONTHS = ["january", "febraury", "march", "april", "may", "june", "july", "august", "september" 14 | , "october", "november", "december"] 15 | DAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"] 16 | DAY_EXTENTIONS = ["st", "nd", "th", "rd"] 17 | MONTH_DAYS = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 18 | 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31} 19 | 20 | 21 | def speak(text): 22 | speaker = pyttsx3.init() 23 | speaker.say(text) 24 | speaker.runAndWait() 25 | 26 | 27 | def get_audio(): 28 | r = sr.Recognizer() 29 | with sr.Microphone() as source: 30 | audio = r.listen(source) 31 | said = "" 32 | 33 | try: 34 | said = r.recognize_google(audio) 35 | print(said) 36 | except Exception as e: 37 | print("Exception: " + str(e)) 38 | 39 | return said 40 | 41 | 42 | def get_date(text): 43 | today = datetime.date.today() 44 | text = text.lower() 45 | if text.count("today") > 0: 46 | return today 47 | 48 | if text.count("tomorrow") > 0: 49 | day = today.day + 1 50 | if day > MONTH_DAYS.get(today.month): 51 | day -= MONTH_DAYS.get(today.month) 52 | month = today.month 53 | year = today.year 54 | if month > 11: 55 | month -= 11 56 | year += 1 57 | 58 | return datetime.date(month=month, day=day, year=year) 59 | 60 | day = -1 61 | day_of_week = -1 62 | month = -1 63 | year = today.year 64 | 65 | for word in text.split(): 66 | if word in MONTHS: 67 | month = MONTHS.index(word) + 1 68 | elif word in DAYS: 69 | day_of_week = DAYS.index(word) 70 | elif word.isdigit(): 71 | day = int(word) 72 | else: 73 | for ext in DAY_EXTENTIONS: 74 | found = word.find(ext) 75 | if found > 0: 76 | try: 77 | day = int(word[:found]) 78 | except: 79 | pass 80 | 81 | if month < today.month and month != -1: 82 | year = year + 1 83 | 84 | if month == -1 and day != -1: 85 | if day < today.day: 86 | month = today.month + 1 87 | else: 88 | month = today.month 89 | 90 | if month == -1 and day == -1 and day_of_week != -1: 91 | current_day_of_week = today.weekday() 92 | dif = day_of_week - current_day_of_week 93 | 94 | if dif < 0: 95 | dif += 7 96 | if text.count("next") >= 1: 97 | dif += 7 98 | 99 | return today + datetime.timedelta(dif) 100 | 101 | if day != -1: 102 | return datetime.date(month=month, day=day, year=year) 103 | 104 | 105 | def authenticate(): 106 | creds = None 107 | if os.path.exists('token.pickle'): 108 | with open('token.pickle', 'rb') as token: 109 | creds = pickle.load(token) 110 | if not creds or not creds.valid: 111 | if creds and creds.expired and creds.refresh_token: 112 | creds.refresh(Request()) 113 | else: 114 | flow = InstalledAppFlow.from_client_secrets_file( 115 | 'credentials.json', SCOPES) 116 | creds = flow.run_local_server(port=0) 117 | with open('token.pickle', 'wb') as token: 118 | pickle.dump(creds, token) 119 | 120 | service = build('calendar', 'v3', credentials=creds) 121 | 122 | return service 123 | 124 | # Call the Calendar API 125 | 126 | 127 | def get_all_events(service, msg_list, tk): 128 | now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time 129 | 130 | events_result = service.events().list(calendarId='primary', timeMin=now, 131 | maxResults=20, singleEvents=True, 132 | orderBy='startTime').execute() 133 | events = events_result.get('items', []) 134 | 135 | if not events: 136 | print('No upcoming events found.') 137 | msg_list.insert(tk.END, "Boss: No upcoming events found!") 138 | 139 | speak(f"You have {len(events)} events.") 140 | for event in events: 141 | 142 | start = event['start'].get('dateTime', event['start'].get('date')) 143 | # print(start, event['summary']) 144 | msg_list.insert(tk.END, "Boss: " + str(start) + str(event['summary'])) 145 | start_time = str(start.split("T")[1].split("-")[0]) 146 | if int(start_time.split(":")[0]) < 12: 147 | start_time = start_time + "am" 148 | else: 149 | start_time = str(int(start_time.split(":")[0]) - 12) + start_time.split(":")[1] 150 | start_time = start_time + "pm" 151 | 152 | speak(event["summary"] + " at " + start_time) 153 | 154 | 155 | def get_selected_events(service, day, msg_list, tk): 156 | date = datetime.datetime.combine(day, datetime.datetime.min.time()) 157 | end_date = datetime.datetime.combine(day, datetime.datetime.max.time()) 158 | utc = pytz.UTC 159 | date = date.astimezone(utc) 160 | end_date = end_date.astimezone(utc) 161 | 162 | events_result = service.events().list(calendarId='primary', timeMin=date.isoformat(), timeMax=end_date.isoformat(), 163 | singleEvents=True, orderBy='startTime').execute() 164 | events = events_result.get('items', []) 165 | 166 | if not events: 167 | speak('No events found!') 168 | msg_list.insert(tk.END, "Boss: No events found!") 169 | else: 170 | speak(f"You have {len(events)} events on this day.") 171 | 172 | for event in events: 173 | start = event['start'].get('dateTime', event['start'].get('date')) 174 | # print(start, event['summary']) 175 | msg_list.insert(tk.END, "Boss: " + str(start) + str(event['summary'])) 176 | start_time = str(start.split("T")[1].split("-")[0]) 177 | if int(start_time.split(":")[0]) < 12: 178 | start_time = start_time + "am" 179 | else: 180 | start_time = str(int(start_time.split(":")[0]) - 12) 181 | start_time = start_time + "pm" 182 | 183 | speak(event["summary"] + " at " + start_time) 184 | 185 | 186 | def get_date_for_day(text): 187 | text = text.lower() 188 | today = datetime.date.today() 189 | 190 | if text.count("today") > 0: 191 | return today 192 | if text.count("tomorrow") > 0: 193 | day = today.day + 1 194 | month = today.month 195 | year = today.year 196 | if day > MONTH_DAYS.get(today.month): 197 | day -= MONTH_DAYS.get(today.month) 198 | month += 1 199 | 200 | if month > 11: 201 | month -= 11 202 | year += 1 203 | 204 | return datetime.date(month=month, day=day, year=year) 205 | 206 | for word in text.split(): 207 | if word in DAYS: 208 | # TODO just get the date 209 | required_day = DAYS.index(word) 210 | diff = required_day - today.day + 1 211 | if diff < 0: 212 | diff += 7 213 | if text.count("next") >= 1: 214 | diff += 7 215 | 216 | curr_month = today.month 217 | day = today.day + diff 218 | if day > MONTH_DAYS.get(curr_month): 219 | day -= MONTH_DAYS.get(curr_month) 220 | curr_month = today.month - 1 221 | year = today.year 222 | return datetime.date(month=curr_month, day=day, year=year) 223 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import json 3 | from model import create_model 4 | import random 5 | import tensorflow as tf 6 | from prepare import prepare_data 7 | import calender as cl 8 | import pyttsx3 9 | import speech_recognition as sr 10 | import subprocess 11 | import datetime 12 | import tkinter as tk 13 | import os 14 | import webbrowser as wb 15 | import threading 16 | import weather 17 | import wikipedia 18 | import smtplib 19 | import keys 20 | 21 | try: 22 | from googlesearch import search 23 | except: 24 | print("googlesearch not imported!") 25 | 26 | SERVICE = cl.authenticate() 27 | 28 | root = tk.Tk() 29 | root.geometry('500x600') 30 | heading = tk.Label(root, text="Welcome! Press the Button and ask whatever you want!", 31 | font=('montserrat', 12, "bold"), fg="black").pack() 32 | frame = tk.Frame(root, bg="#FFF") 33 | frame.place(relwidth=0.8, relheight=0.8, relx=0.1, rely=0.1) 34 | your_msg = tk.StringVar() 35 | y_scroll_bar = tk.Scrollbar(frame) 36 | x_scroll_bar = tk.Scrollbar(frame, orient=tk.HORIZONTAL) 37 | msg_list = tk.Listbox(frame, height=20, width=50, yscrollcommand=y_scroll_bar.set, xscrollcommand=x_scroll_bar.set) 38 | y_scroll_bar.pack(side=tk.RIGHT, fill=tk.Y, expand=tk.FALSE) 39 | x_scroll_bar.pack(side=tk.BOTTOM, fill=tk.X, expand=tk.FALSE) 40 | msg_list.pack(side=tk.LEFT, fill=tk.BOTH) 41 | msg_list.pack() 42 | frame.pack() 43 | 44 | with open("intents.json") as file: 45 | data = json.load(file) 46 | 47 | 48 | def speak(text): 49 | speaker = pyttsx3.init() 50 | speaker.say(text) 51 | speaker.runAndWait() 52 | 53 | 54 | def get_audio(): 55 | r = sr.Recognizer() 56 | with sr.Microphone() as source: 57 | audio = r.listen(source) 58 | said = "" 59 | 60 | try: 61 | said = r.recognize_google(audio) 62 | print(said) 63 | except Exception as e: 64 | print("Exception: " + str(e)) 65 | 66 | return said 67 | 68 | 69 | tags = [] # Contains all the different tags 70 | all_questions_list = [] # Contains the different question with their words tokenized 71 | questions_tags = [] # Contains the questions tags corresponding to the questions in above list 72 | all_question_words = [] # Contains all the words in all the questions of the dataset 73 | 74 | pr = prepare_data(data) 75 | all_question_words, tags, all_questions_list, questions_tags = pr.prepare(data, "intents", "all_questions", "tag") 76 | 77 | all_questions_train = [] 78 | tags_output = [] 79 | 80 | all_questions_train, tags_output = pr.get_training_set() 81 | all_questions_train = np.array(all_questions_train) 82 | tags_output = np.array(tags_output) 83 | 84 | tf.reset_default_graph() 85 | model = create_model(all_questions_train, tags_output, tags, all_question_words) 86 | model.fit_model(all_questions_train, tags_output) 87 | 88 | # Preparing sub tags models 89 | sub_tags_list = [] 90 | sub_tags_models = [] 91 | 92 | for intent in data["intents"]: 93 | all_words_sub_questions = [] 94 | all_sub_tags = [] 95 | sub_question_tags = [] 96 | all_sub_questions_list = [] 97 | 98 | tr = prepare_data(data) 99 | all_words_sub_questions, all_sub_tags, all_sub_questions_list, sub_question_tags = tr.prepare(intent, "sub_tags", 100 | "questions", "sub") 101 | 102 | all_sub_questions_train = [] 103 | sub_tags_output = [] 104 | all_sub_questions_train, sub_tags_output = tr.get_training_set() 105 | all_sub_questions_train = np.array(all_sub_questions_train) 106 | sub_tags_output = np.array(sub_tags_output) 107 | 108 | sub_model = create_model(all_sub_questions_train, sub_tags_output, all_sub_tags, all_words_sub_questions) 109 | sub_model.fit_model(all_sub_questions_train, sub_tags_output) 110 | sub_tags_models.append(sub_model) 111 | 112 | sub_tags_list.extend(all_sub_tags) 113 | 114 | tags_dict = {} 115 | answers_dict = {} 116 | 117 | 118 | def note(text): 119 | date = datetime.datetime.now() 120 | file_name = str(date).replace(":", "-") + "-note.txt" 121 | with open(file_name, "w") as f: 122 | f.write(text) 123 | 124 | subprocess.Popen(["notepad.exe", file_name]) 125 | 126 | 127 | def make_note(): 128 | speak("What would you like me to write down? ") 129 | write = get_audio() 130 | note(write) 131 | speak("I've made a note of that.") 132 | msg_list.insert(tk.END, "Boss: I've made a note of that.") 133 | 134 | 135 | def perform_google_search(): 136 | speak("what would you like me to search for") 137 | query = get_audio() 138 | speak("I have the following results") 139 | msg_list.insert(tk.END, "Boss: I have the following results:") 140 | for result in search(query, tld="co.in", num=1, stop=1, pause=2): 141 | msg_list.insert(tk.END, "Boss: " + str(result)) 142 | res = result 143 | 144 | wb.open(res) 145 | 146 | 147 | def prepare_tags_list(): 148 | for intent in data["intents"]: 149 | curr_tag = intent["tag"] 150 | s_tags_list = [] 151 | for sub_tg in intent["sub_tags"]: 152 | curr_sub_tag = sub_tg["sub"] 153 | s_tags_list.append(curr_sub_tag) 154 | answers_dict[curr_sub_tag] = sub_tg["answers"] 155 | 156 | tags_dict[curr_tag] = s_tags_list 157 | 158 | 159 | def wish(): 160 | hour = int(datetime.datetime.now().hour) 161 | if 0 <= hour < 12: 162 | speak("Good Morning") 163 | elif 12 <= hour < 18: 164 | speak("Good Afternoon") 165 | else: 166 | speak("Good Evening") 167 | speak("I am Boss sir, How can I help you") 168 | 169 | 170 | 171 | 172 | def send_mails(to, body): 173 | server = smtplib.SMTP('smtp.gmail.com', 587) 174 | server.ehlo() 175 | server.starttls() 176 | server.login(keys.EMAIL, keys.PASSWORD) 177 | server.sendmail('4as1827000224@gmail.com', to, body) 178 | server.close() 179 | 180 | 181 | prepare_tags_list() 182 | 183 | 184 | def main(): 185 | sentence = get_audio() 186 | msg_list.insert(tk.END, "You: " + sentence) 187 | if sentence.count("exit") > 0: 188 | msg_list.insert(tk.END, "Boss: Good Bye!") 189 | speak("Good bye") 190 | root.quit() 191 | 192 | tag = model.predict_tag(sentence) 193 | sub = sub_tags_models[tag].predict_tag(sentence) 194 | tag_word = tags[tag] 195 | 196 | sub_list = tags_dict.get(tag_word) 197 | sub_tag_word = sub_list[sub] 198 | 199 | if sub_tag_word == "mails-send": 200 | try: 201 | speak("Who do you want to send this mail") 202 | to = get_audio() 203 | speak("what should I say to " + to) 204 | body = get_audio() 205 | send_mails(keys.DICT[to], body) 206 | speak("Your mail has been sent successfully !") 207 | msg_list.insert(tk.END, "Boss: Your mail has been sent successfully !") 208 | except Exception as e: 209 | print(e) 210 | speak("Sorry, Could not send this E-mail") 211 | msg_list.insert(tk.END, "Boss: Sorry, Could not send this E-mail") 212 | elif sub_tag_word == "wikipedia-open": 213 | ans = answers_dict.get(sub_tag_word) 214 | a = random.choice(ans) 215 | speak(a) 216 | results = wikipedia.summary(sentence, sentences=2) 217 | speak("According to wikipedia") 218 | speak(results) 219 | msg_list.insert(tk.END, "Boss: " + str(results)) 220 | elif sub_tag_word == "music-open": 221 | path = keys.PATH_MUSIC 222 | ans = answers_dict.get(sub_tag_word) 223 | a = random.choice(ans) 224 | speak(a) 225 | os.startfile(path) 226 | msg_list.insert(tk.END, "Boss: opened Spotify") 227 | elif sub_tag_word == "visual-studio-code-open": 228 | path = keys.PATH_VS_CODE 229 | ans = answers_dict.get(sub_tag_word) 230 | a = random.choice(ans) 231 | speak(a) 232 | os.startfile(path) 233 | msg_list.insert(tk.END, "Boss: opened visual studio") 234 | elif sub_tag_word == "call-weather-api": 235 | speak("Please tell me the name of the city") 236 | city = get_audio() 237 | print("city: " + str(city)) 238 | weather_conditions = weather.get_weather(str(city)) 239 | speak(weather_conditions) 240 | msg_list.insert(tk.END, "Boss: " + str(weather_conditions)) 241 | elif sub_tag_word == "know-date": 242 | date = cl.get_date_for_day(sentence) 243 | speak(date) 244 | msg_list.insert(tk.END, "Boss: " + str(date)) 245 | 246 | elif sub_tag_word == "get-events": 247 | try: 248 | day = cl.get_date(sentence) 249 | cl.get_selected_events(SERVICE, day, msg_list, tk) 250 | except: 251 | speak("None") 252 | msg_list.insert(tk.END, "Boss: None") 253 | elif sub_tag_word == "all-events": 254 | try: 255 | cl.get_all_events(SERVICE, msg_list, tk) 256 | except: 257 | msg_list.insert(tk.END, "Boss: None") 258 | speak("None") 259 | elif sub_tag_word == "make-notes": 260 | try: 261 | make_note() 262 | except: 263 | msg_list.insert(tk.END, "Boss: Try again") 264 | speak("try again") 265 | elif sub_tag_word == "search-google": 266 | try: 267 | perform_google_search() 268 | except: 269 | msg_list.insert(tk.END, "Boss: An error occurred!") 270 | speak("An error occurred") 271 | else: 272 | ans = answers_dict.get(sub_tag_word) 273 | a = random.choice(ans) 274 | speak(a) 275 | msg_list.insert(tk.END, "Boss: " + str(a)) 276 | 277 | 278 | def run(): 279 | main_thread = threading.Thread(target=main) 280 | main_thread.start() 281 | 282 | 283 | picture = tk.PhotoImage(file=keys.PATH_IMAGE) 284 | send_button = tk.Button(root, image=picture, command=run, borderwidth=0) 285 | send_button.pack() 286 | 287 | wish() 288 | 289 | root.mainloop() 290 | -------------------------------------------------------------------------------- /intents.json: -------------------------------------------------------------------------------- 1 | {"intents":[ 2 | {"tag": "greeting", 3 | "all_questions": ["Hi", "Hello", "How are you?", "How do you do?", "Is anyone there?", "What's up?", "Are you fine", 4 | "Howdy"], 5 | "sub_tags":[ 6 | { 7 | "sub":"normal-greeting", 8 | "questions": ["Hi", "Hello", "Hey!", "Howdy", "Hola", "Hhh"], 9 | "answers": ["Hi", "Hello", "Hey!", "Howdy"] 10 | }, 11 | { 12 | "sub": "asking", 13 | "questions": ["How are you?", "How do you do?", "Is anyone there?", "What's up?", "Are you fine", "Hows you?", 14 | "Whats going on?"], 15 | "answers": ["I am fine, what about you?", "I am good!", "I am fine, you say"] 16 | } 17 | ] 18 | }, 19 | {"tag":"name", 20 | "all_questions": ["Hi, what's your name?", "Hello, may I know your name", "Tell me your name?","May I know your name", "whats your good name", 21 | "What should I call you?", "Do you have a name?", "what is your name?", "My name is john, what's your name?"], 22 | "sub_tags":[ 23 | { 24 | "sub": "normal-ask-name", 25 | "questions": ["Hi, what's your name?", "Hello, may I know your name", "Tell me your name?","May I know your name", "whats your good name", 26 | "What should I call you?", "Do you have a name?", "what is your name?"], 27 | "answers": ["I am Boss!", "You can call me Boss!", "My name is Boss!", "Hello, I am Boss", "Good to see you, I am Boss"] 28 | } 29 | ] 30 | }, 31 | {"tag":"days", 32 | "all_questions": ["whats the date on monday?", "whats the date on tuesday?", "whats the date on wednesday?", 33 | "whats the date on thursday?","whats the date on friday?","whats the date on saturday?","whats the date on sunday?", 34 | "whats the date on coming sunday?", "whats the date on coming monday?", "whats the date on coming tuesday?", 35 | "whats the date on coming wednesday?", "whats the date on coming thursday?", "whats the date on coming friday?", 36 | "whats the date on coming saturday?", "date on coming monday?", "date tomorrow?", "whats the date tomorrow", 37 | "date monday", "date tuesday", "date wednesday", "date thursday", "date friday", "date saturday", 38 | "date sunday", "what month is this?", "whats day today", "whats date today", 39 | "what is sunday?", "what is monday", "what is thursday", "what are days", 40 | "what are friday","am i busy on sunday","am i busy on 31st august","is there any commitment for 16th febraury", 41 | "whats the event on monday","whats the event on tuesday", "whats the event on wednesday", 42 | "whats the event on thursday", "whats the event on friday", "whats the event on saturday", 43 | "whats the event on sunday", "do I have plans on sunday", "is there any event on 5th september", 44 | "do i have plans on friday", "what are my plans on sunday", "what are my plans on monday", 45 | "tell me my plans on 16th november", "what are my plans on tuesday 13th", 46 | "what are my plans on 22nd november", "do I have any event on 21st december", "Is there any event on 30th january", 47 | "what are events on next monday","do I have any event this tuesday", "events on 21st june", 48 | "events on 3rd may", "events on coming friday", "plans on next month", "do i have some commitments this thursday", 49 | "what are my commitments for sunday", "what are commitments for 23rd april", 50 | "what are my upcoming events", "what are commitments next days", "tell me my upcoming plans", 51 | "what are the commitments i have for next days", "tell me all the plans of mine", "what are the plans i have next", 52 | "give all the plans i have", "upcoming plans", "all upcoming events", "do i have any plans now", 53 | "do i have any events", "do i have some commitments now", "is there any event left", "is there any plan i am forgetting", 54 | "remind me my plans", "remind my the upcoming events"], 55 | "sub_tags": [ 56 | { 57 | "sub": "know-date", 58 | "questions": ["whats the date on monday?", "whats the date on tuesday?", "whats the date on wednesday?", 59 | "whats the date on thursday?","whats the date on friday?","whats the date on saturday?","whats the date on sunday?", 60 | "whats the date on coming sunday?", "whats the date on coming monday?", "whats the date on coming tuesday?", 61 | "whats the date on coming wednesday?", "whats the date on coming thursday?", "whats the date on coming friday?", 62 | "whats the date on coming saturday?", "date on coming monday?", "date tomorrow?", "whats the date tomorrow", 63 | "date monday", "date tuesday", "date wednesday", "date thursday", "date friday", "date saturday", 64 | "date sunday", "what month is this?", "whats day today", "whats date today"], 65 | "answers": ["none-from-here"] 66 | }, 67 | { 68 | "sub": "get-events", 69 | "questions": ["am i busy on sunday","am i busy on 31st august","is there any commitment for 16th febraury", 70 | "whats the event on monday","whats the event on tuesday", "whats the event on wednesday", 71 | "whats the event on thursday", "whats the event on friday", "whats the event on saturday", 72 | "whats the event on sunday", "do I have plans on sunday", "is there any event on 5th september", 73 | "do i have plans on friday", "what are my plans on sunday", "what are my plans on monday", 74 | "tell me my plans on 16th november", "what are my plans on tuesday 13th", 75 | "what are my plans on 22nd november", "do I have any event on 21st december", "Is there any event on 30th january", 76 | "what are events on next monday","do I have any event this tuesday", "events on 21st june", 77 | "events on 3rd may", "events on coming friday", "plans on next month", "do i have some commitments this thursday", 78 | "what are my commitments for sunday", "what are commitments for 23rd april"], 79 | "answers": ["none"] 80 | }, 81 | { 82 | "sub": "normal", 83 | "questions": ["what is sunday?", "what is monday", "what is thursday", "what are days", 84 | "what are friday"], 85 | "answers": ["Its just a normal day!", "Do not you have any plans that day?"] 86 | }, 87 | { 88 | "sub": "all-events", 89 | "questions": ["what are my upcoming events", "what are commitments next days", "tell me my upcoming plans", 90 | "what are the commitments i have for next days", "tell me all the plans of mine", "what are the plans i have next", 91 | "give all the plans i have", "upcoming plans", "all upcoming events", "do i have any plans now", 92 | "do i have any events", "do i have some commitments now", "is there any event left", "is there any plan i am forgetting", 93 | "remind me my plans", "remind my the upcoming events"], 94 | "answers": ["No upcoming events"] 95 | } 96 | ] 97 | }, 98 | { 99 | "tag": "notes", 100 | "all_questions": ["write down for me", "write this down for me", "will you write this for me", 101 | "please write something for me", "could you please write one thing for me", 102 | "can you make a note", "make a note", "type this", "please type this", "can you type something for me", 103 | "make some note", "remember this", "can you remember one thing for me", "write this", "note it", "note this", 104 | "remember it"], 105 | "sub_tags": [ 106 | { 107 | "sub": "make-notes", 108 | "questions": ["write down for me", "write this down for me", "will you write this for me", 109 | "please write something for me", "could you please write one thing for me", 110 | "can you make a note", "make a note", "type this", "please type this", "can you type something for me", 111 | "make some note", "remember this", "can you remember one thing for me", "write this", "note it", "note this", 112 | "remember it"], 113 | "answers":["Sure"] 114 | } 115 | ] 116 | }, 117 | { 118 | "tag": "age-work", 119 | "all_questions": ["what is your age", "how old are you", "do you have some age", 120 | "are you older than me", "when were you born?", "are you younger than me", 121 | "tell me your age", "are you old", "are you young","what is your work", "what do you do?", "what is your daily routine", 122 | "do you have a job?", "whats your hobby", "what you do in your day", 123 | "do you have any hobby","what do you like to do", "what you love the most"], 124 | "sub_tags": [ 125 | { 126 | "sub": "age", 127 | "questions": ["what is your age", "how old are you", "do you have some age", 128 | "are you older than me", "when were you born?", "are you younger than me", 129 | "tell me your age", "are you old", "are you young"], 130 | "answers": ["Do you really think I would have some age?", "I am a computer programme. How am I supposed to have an age!", 131 | "How can I have some age, I am a computer programme!"] 132 | }, 133 | { 134 | "sub": "work", 135 | "questions": ["what is your work", "what do you do?", "what is your daily routine", 136 | "do you have a job?", "what you do in your day"], 137 | "answers": ["I help others", "I do work for others and talk to them", 138 | "I help people"] 139 | }, 140 | { 141 | "sub": "hobby", 142 | "questions": ["what are your hobbies","whats your hobby","do you have any hobby","what do you like to do", "what you love the most"], 143 | "answers": ["I like to talk to people very much.", "I like talking with people and helping them!"] 144 | } 145 | ] 146 | }, 147 | { 148 | "tag": "google-search", 149 | "all_questions": ["can you search something for me", "search this for me","make a google search", 150 | "hey, can you search one thing for me", "can you search something on google", 151 | "perform a google search", "search on google", "search google"], 152 | "sub_tags": [ 153 | { 154 | "sub": "search-google", 155 | "questions": ["can you search something for me", "search this for me","make a google search", 156 | "hey, can you search one thing for me", "can you search something on google", 157 | "perform a google search", "search on google", "search google"], 158 | "answers": ["Sure, let me search!"] 159 | } 160 | ] 161 | }, 162 | { 163 | "tag": "weather-api-call", 164 | "all_questions": ["can you tell me something about the weather conditions", "what is the current weather conditions","I want to go out now is it raining", 165 | "hey, how is the weather", "hey, tell me about the weather conditions i want to go out for a walk", 166 | "what is the current temperature", "Is it cloudy outside", "is it sunny outside", "is it raining", "how is the weather"], 167 | "sub_tags": [ 168 | { 169 | "sub": "call-weather-api", 170 | "questions": ["can you tell me something about the weather conditions", "what is the current weather conditions","I want to go out now is it raining", 171 | "hey, how is the weather", "hey, tell me about the weather conditions i want to go out for a walk", 172 | "what is the current temperature", "Is it cloudy outside", "is it sunny outside", "is it raining", "how is the weather"], 173 | "answers": ["Sure, let me find out"] 174 | } 175 | ] 176 | }, 177 | { 178 | "tag": "open-visual-studio-code", 179 | "all_questions": ["Hey open Visual Studio code", "Can you open visual studio for me", 180 | "hey open visual studio for me", "Hello I want to do some coding", 181 | "open VS code", "Hey open VS code", "Can you open VS code for me", "hey open VS code for me"], 182 | "sub_tags": [ 183 | { 184 | "sub": "visual-studio-code-open", 185 | "questions": ["Hey open Visual Studio code", "Can you open visual studio for me", 186 | "hey open visual studio for me", "Hello I want to do some coding", 187 | "open VS code", "Hey open VS code", "Can you open VS code for me", "hey open VS code for me"], 188 | "answers": ["Sure sir, opening Visual Studio Code, please wait!"] 189 | } 190 | ] 191 | }, 192 | { 193 | "tag": "open-music", 194 | "all_questions": ["Hey! i want to listen some music", "Can you play some music for me", 195 | "Play music", "Play songs", "its music time", "its coffee time", 196 | "open music app", "its coffee time Boss", "Hello play songs for me", "hey play some music"], 197 | "sub_tags": [ 198 | { 199 | "sub": "music-open", 200 | "questions": ["Hey! i want to listen some music", "Can you play some music for me", 201 | "Play music", "Play songs", "its music time", "its coffee time", "its music time", 202 | "open music app", "its coffee time Boss", "Hello play songs for me", "hey play some music"], 203 | "answers": ["Sure sir, opening Spotify, please wait!"] 204 | } 205 | ] 206 | }, 207 | { 208 | "tag": "open-wikipedia", 209 | "all_questions": ["Hey! search on wikipedia about dhoni", "search on wikipedia about dhoni", 210 | "According to wikipedia who is Dhoni", "According to wikipedia what is maths", "who is dhoni according to wikipedia", 211 | "show me the search results of wikipedia on dhoni"], 212 | "sub_tags": [ 213 | { 214 | "sub": "wikipedia-open", 215 | "questions": ["Hey! search on wikipedia about dhoni", "search on wikipedia about dhoni", 216 | "According to wikipedia who is Dhoni", "According to wikipedia what is maths", "who is dhoni according to wikipedia", 217 | "show me the search results of wikipedia on dhoni"], 218 | "answers": ["Sure sir, looking wikipedia for information, please wait!"] 219 | } 220 | ] 221 | }, 222 | { 223 | "tag": "send-mails", 224 | "all_questions": ["Hey! can you send a mail", "Boss send a mail", 225 | "send a mail", "please send a mail", "compose a mail", "please compose a mail", 226 | "send an email", "Please send an email", "compose an email"], 227 | "sub_tags": [ 228 | { 229 | "sub": "mails-send", 230 | "questions": ["Hey! can you send a mail", "Boss send a mail", 231 | "send a mail", "please send a mail", "compose a mail", "please compose a mail", 232 | "send an email", "Please send an email", "compose an email"], 233 | "answers": ["Sure sir !"] 234 | } 235 | ] 236 | } 237 | ] 238 | } --------------------------------------------------------------------------------