-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsft.py
97 lines (74 loc) · 3.07 KB
/
sft.py
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#importing tkinter
#importing the wolframalpha API to access it's portal
#importing wikipedia API, MODULE to access it' portal
import wolframalpha
import wikipedia
import tkinter as tk
from tkinter import *
#importing browser module
import webbrowser
#importing text to speech module
from gtts import gTTS
#passing the question ang language in which answer to be seen
def search():
q = inp_que.get()
#change lang string to standard of wikipedia
langu = inp_lang.get()
if(langu.lower() == 'english'):
langu ='en'
elif(lang.lower() == 'tamil'):
langu = 'ta'
#try the wolframalpha search
try:
app_id = "APP ID FROM WOLFRAMALPHA WEBSITE"
client = wolframalpha.Client(app_id)
result = client.query(q)
#answer = next(result.results).text
ans = next(result.results).text
message.delete('1.0', END)
message.insert('1.0',ans)
gTTS(text =ans,lang='en' )
#if above doesn't satisfy then try wikipedia search
except:
wikipedia.set_lang(langu)
#answer = wikipedia.summary(q)
ans = wikipedia.summary(q)
message.delete('1.0', END)
message.insert('1.0',ans)
gTTS(text=ans, lang=langu)
def browser():
browser = inp_browser.get()
if(browser.lower()=='google'):
url = "https://www.google.com"
gTTS(text="opening google",lang='en')
webbrowser.open_new(url)
elif(browser.lower()=='youtube'):
url= "https://www.youtube.com"
gTTS(text="opening youtube",lang='en')
webbrowser.open_new(url)
larger_font = ('bold',15)
medium_font = ('verdana',15)
#creating main window
window = tk.Tk()
window.title("personal Bot !!!")
#configuring the window's geometry
mainframe =Frame(window, bg='#cc0000',cursor='dot',height='1500',width='1000')
mainframe.pack()
label1 = tk.Label(mainframe, text='Enter the question :',bg='#3377ff',font=larger_font).pack()
inp_que = Entry(mainframe, bg='#b3ecff',font=medium_font,width='100')
inp_que.pack()
#creating language input box
label2 = tk.Label(mainframe, text= 'Enter the language :',bg='#3377ff',font=larger_font).pack()
inp_lang = Entry(mainframe, bg='#b3ecff',font=medium_font,width='100')
inp_lang.pack()
label2 = tk.Label(mainframe, text= 'Enter the website to be opened :',bg='#3377ff',font=larger_font).pack()
inp_browser = Entry(mainframe, bg='#b3ecff',font=medium_font,width='100')
inp_browser.pack()
#creating search button
searchButton = tk.Button(mainframe, text='search answer',command = search,bg='#800080',foreground='#ffff00').pack()
searchBrowser = tk.Button(mainframe, text='open website',command = browser,bg='#800080',foreground='#ffff00').pack()
#creating output box
label3 = tk.Label(mainframe, text ='The answer is !!! ',bg='#99ff99',font=larger_font).pack()
message = tk.Text(mainframe,bg='#d580ff',width='200',height ='600',pady=5,padx=5)
message.pack()
window.mainloop()