Skip to content

Commit

Permalink
Add google search feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Madhur215 committed Mar 30, 2020
1 parent 9339cbf commit d346b34
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
Binary file modified __pycache__/model.cpython-36.pyc
Binary file not shown.
45 changes: 45 additions & 0 deletions intents.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,51 @@
"answers":["Sure"]
}
]
},
{
"tag": "age-work",
"all_questions": ["what is your age", "how old are you", "do you have some age",
"are you older than me", "when were you born?", "are you younger than me",
"tell me your age", "are you old", "are you young","what is your work", "what do you do?", "what is your daily routine",
"do you have a job?", "whats your hobby", "what you do in your day",
"do you have any hobby","what do you like to do", "what you love the most"],
"sub_tags": [
{
"sub": "age",
"questions": ["what is your age", "how old are you", "do you have some age",
"are you older than me", "when were you born?", "are you younger than me",
"tell me your age", "are you old", "are you young"],
"answers": ["Do you really think I would have some age?", "I am a computer programme. How am I supposed to have an age!",
"How can I have some age, I am a computer programme!"]
},
{
"sub": "work",
"questions": ["what is your work", "what do you do?", "what is your daily routine",
"do you have a job?", "what you do in your day"],
"answers": ["I help others", "I do work for others and talk to them",
"I help people"]
},
{
"sub": "hobby",
"questions": ["what are your hobbies","whats your hobby","do you have any hobby","what do you like to do", "what you love the most"],
"answers": ["I like to talk to people very much.", "I like talking with people and helping them!"]
}
]
},
{
"tag": "google-search",
"all_questions": ["can you search something for me", "search this for me","make a google search",
"hey, can you search one thing for me", "can you search something on google",
"perform a google search", "search on google", "search google"],
"sub_tags": [
{
"sub": "search-google",
"questions": ["can you search something for me", "search this for me","make a google search",
"hey, can you search one thing for me", "can you search something on google",
"perform a google search", "search on google", "search google"],
"answers": ["Sure, let me search!"]
}
]
}
]
}
30 changes: 27 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
import tkinter as tk
from tkinter import Text
import os
import webbrowser as wb
try:
from googlesearch import search
except:
print("googlesearch not imported!")

SERVICE = cl.authenticate()

Expand All @@ -23,9 +28,11 @@
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)
y_scroll_bar = tk.Scrollbar(frame)
x_scroll_bar = tk.Scrollbar(frame, orient= tk.HORIZONTAL)
msg_list = tk.Listbox(frame, height=20, width=50, yscrollcommand=y_scroll_bar.set, xscrollcommand=x_scroll_bar.set)
y_scroll_bar.pack(side=tk.RIGHT, fill=tk.Y)
x_scroll_bar.pack(side=tk.BOTTOM, fill=tk.X)
msg_list.pack(side=tk.LEFT, fill=tk.BOTH)
msg_list.pack()
frame.pack()
Expand Down Expand Up @@ -117,6 +124,17 @@ def make_note():
speak("I've made a note of that.")
msg_list.insert(tk.END, "Boss: I've made a note of that.")

def perform_google_search():
speak("what would you like me to search for")
query = get_audio()
speak("I have the following results")
msg_list.insert(tk.END, "Boss: I have the following results:")
for result in search(query, tld="co.in",num=1, stop=1, pause=2):
msg_list.insert(tk.END, "Boss: " + str(result))
res = result

wb.open(res)

def prepare_tags_list():

for intent in data["intents"]:
Expand Down Expand Up @@ -172,6 +190,12 @@ def main():
except:
msg_list.insert(tk.END, "Boss: Try again")
speak("try again")
elif sub_tag_word == "search-google":
try:
perform_google_search()
except:
msg_list.insert(tk.END, "Boss: An error occurred!")
speak("An error occurred")
else:
ans = answers_dict.get(sub_tag_word)
a = random.choice(ans)
Expand Down
2 changes: 1 addition & 1 deletion model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, train, output, tags, all_questions_words):
self.network = tflearn.regression(self.network)
self.model = tflearn.DNN(self.network)

def fit_model(self, train, output, n=150, batch = 8, metric=True):
def fit_model(self, train, output, n=400, batch = 8, metric=True):
self.model.fit(train, output, n_epoch = n, batch_size=batch, show_metric=metric)


Expand Down

0 comments on commit d346b34

Please sign in to comment.