Skip to content

Commit

Permalink
Add gui and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Madhur215 committed Mar 29, 2020
1 parent db1c97d commit 9339cbf
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 73 deletions.
43 changes: 25 additions & 18 deletions calender.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def authenticate():

# Call the Calendar API

def get_all_events(service):
def get_all_events(service, msg_list, tk):

now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time

events_result = service.events().list(calendarId='primary', timeMin=now,
Expand All @@ -129,23 +130,25 @@ def get_all_events(service):
events = events_result.get('items', [])

if not events:
print('No upcoming events found.')
for event in events:
speak(f"You have {len(events)} events.")
# print('No upcoming events found.')
msg_list.insert(tk.END, "Boss: No upcoming events found!")

for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
print(start, event['summary'])
start_time = str(start.split("T")[1].split("-")[0])
if int(start_time.split(":")[0]) < 12:
start_time = start_time + "am"
else:
start_time = str(int(start_time.split(":")[0])-12)
start_time = start_time + "pm"
speak(f"You have {len(events)} events.")
for event in events:

start = event['start'].get('dateTime', event['start'].get('date'))
# print(start, event['summary'])
msg_list.insert(tk.END, "Boss: " + str(start) + str(event['summary']))
start_time = str(start.split("T")[1].split("-")[0])
if int(start_time.split(":")[0]) < 12:
start_time = start_time + "am"
else:
start_time = str(int(start_time.split(":")[0])-12) + start_time.split(":")[1]
start_time = start_time + "pm"

speak(event["summary"] + " at " + start_time)
speak(event["summary"] + " at " + start_time)

def get_selected_events(service, day):
def get_selected_events(service, day, msg_list, tk):
date = datetime.datetime.combine(day, datetime.datetime.min.time())
end_date = datetime.datetime.combine(day, datetime.datetime.max.time())
utc = pytz.UTC
Expand All @@ -158,12 +161,14 @@ def get_selected_events(service, day):

if not events:
speak('No events found!')
msg_list.insert(tk.END, "Boss: No events found!")
else:
speak(f"You have {len(events)} events on this day.")

for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
print(start, event['summary'])
# print(start, event['summary'])
msg_list.insert(tk.END, "Boss: " + str(start) + str(event['summary']))
start_time = str(start.split("T")[1].split("-")[0])
if int(start_time.split(":")[0]) < 12:
start_time = start_time + "am"
Expand All @@ -181,10 +186,12 @@ def get_date_for_day(text):
return today
if text.count("tomorrow") > 0:
day = today.day + 1
if day > MONTH_DAYS.get(today.month):
day -= MONTH_DAYS.get(today.month)
month = today.month
year = today.year
if day > MONTH_DAYS.get(today.month):
day -= MONTH_DAYS.get(today.month)
month += 1

if month > 11:
month -= 11
year += 1
Expand Down
Binary file added images/voice1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/voice2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/voice4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 67 additions & 55 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import nltk
from nltk.stem.lancaster import LancasterStemmer
import numpy as np
import json
import random
Expand All @@ -12,8 +10,27 @@
import speech_recognition as sr
import subprocess
import datetime
import tkinter as tk
from tkinter import Text
import os

SERVICE = cl.authenticate()

root = tk.Tk()
root.geometry('500x600')
heading = tk.Label(root, text="Welcome! Press the Button and ask whatever you want!",
font=('verdana',12,"bold"), fg="orange").pack()
frame = tk.Frame(root, bg="#FFF")
frame.place(relwidth=0.8, relheight=0.8, relx=0.1, rely=0.1)
your_msg = tk.StringVar()
scroll_bar = tk.Scrollbar(frame)
msg_list = tk.Listbox(frame, height=20, width=50, yscrollcommand=scroll_bar.set)
scroll_bar.pack(side=tk.RIGHT, fill=tk.Y)
msg_list.pack(side=tk.LEFT, fill=tk.BOTH)
msg_list.pack()
frame.pack()


stemmer = LancasterStemmer()
with open("intents.json") as file:
data = json.load(file)

Expand Down Expand Up @@ -98,6 +115,7 @@ def make_note():
write = get_audio()
note(write)
speak("I've made a note of that.")
msg_list.insert(tk.END, "Boss: I've made a note of that.")

def prepare_tags_list():

Expand All @@ -113,65 +131,59 @@ def prepare_tags_list():

prepare_tags_list()

def start_chat():

print("Welcome!")
while True:
def main():

print("Listening: ")
sentence = get_audio()
if sentence.lower() == "exit":
print("Good bye!")
speak("Good bye")
break
sentence = get_audio()
msg_list.insert(tk.END, "You: " + sentence)
if sentence.count("exit") > 0:
msg_list.insert(tk.END, "Boss: Good Bye!")
speak("Good bye")
root.quit()
return

tag = model.predict_tag(sentence)
sub = sub_tags_models[tag].predict_tag(sentence)
tag_word = tags[tag]
tag = model.predict_tag(sentence)
sub = sub_tags_models[tag].predict_tag(sentence)
tag_word = tags[tag]

sub_list = tags_dict.get(tag_word)
sub_tag_word = sub_list[sub]

if sub_tag_word == "know-date":
date = cl.get_date_for_day(sentence)
speak(date)
print("Boss: ", date)

elif sub_tag_word == "get-events":
try:
day = cl.get_date(sentence)
cl.get_selected_events(cl.authenticate(), day)
except:
speak("None")
print("Boss: None")
elif sub_tag_word == "all-events":
try:
cl.get_all_events(cl.authenticate())
except:
print("None")
speak("Boss: None")
elif sub_tag_word == "make-notes":
try:
make_note()
except:
print("Try again!")
speak("try again")
else:
ans = answers_dict.get(sub_tag_word)
a = random.choice(ans)
speak(a)
print("Boss: ", a)

start_chat()

# day date error



sub_list = tags_dict.get(tag_word)
sub_tag_word = sub_list[sub]

if sub_tag_word == "know-date":
date = cl.get_date_for_day(sentence)
speak(date)
msg_list.insert(tk.END, "Boss: " + str(date))

elif sub_tag_word == "get-events":
try:
day = cl.get_date(sentence)
cl.get_selected_events(SERVICE, day, msg_list, tk)
except:
speak("None")
msg_list.insert(tk.END, "Boss: None")
elif sub_tag_word == "all-events":
try:
cl.get_all_events(SERVICE, msg_list, tk)
except:
msg_list.insert(tk.END, "Boss: None")
speak("Boss: None")
elif sub_tag_word == "make-notes":
try:
make_note()
except:
msg_list.insert(tk.END, "Boss: Try again")
speak("try again")
else:
ans = answers_dict.get(sub_tag_word)
a = random.choice(ans)
speak(a)
msg_list.insert(tk.END, "Boss: " + str(a))

picture = tk.PhotoImage(file = r"D:\Chatbot\images\voice4.png")
send_button = tk.Button(root, image=picture, command=main)
send_button.pack()


root.mainloop()



0 comments on commit 9339cbf

Please sign in to comment.