-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
386 lines (311 loc) · 11.6 KB
/
main.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
import warnings
warnings.filterwarnings("ignore")
import speech_recognition as sr
import pyttsx3
import webbrowser
import os
import openai
from gnewsclient import gnewsclient
from playsound import playsound
import datetime
client = gnewsclient.NewsClient(language='english',location='india',max_results=3)
import time
import wmi
from selenium import webdriver
from selenium.webdriver.common.by import By
from utils import websites
import pyjokes
from urllib.request import urlopen
import json
from ecapture import ecapture as ec
import requests
import getpass
import pywhatkit as kit
import os
import subprocess as sp
from config import apikey
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
def say(text):
text_to_speech = pyttsx3.init()
text_to_speech.say(text)
text_to_speech.runAndWait()
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"User said: {query}\n")
except Exception as e:
print(e)
print("Unable to Recognizing your voice.")
return "None"
return query
def takeCommanduser():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Name of User or Group")
r.pause_threshold = 1
audio = r.listen(source)
try:
query = r.recognize_google(audio, language='en-in')
print(f'Client to whome message is to be sent is : {query}\n')
except Exception as e:
print (e)
print("Unable to recognize Client name")
say("Unable to recognize Client Name")
print("Check your Internet Connectivity")
return query
def takeCommandmessage():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Enter Your Message")
r.pause_threshold = 1
audio = r.listen(source)
try:
query = r.recognize_google(audio, language='en-in')
print(f'Message to be sent is : {query}\n')
except Exception as e:
print (e)
print("Unable to recognize your message")
print("Check your Internet Connectivity")
return query
def find_my_ip():
ip_address = requests.get('https://api64.ipify.org?format=json').json()
return ip_address["ip"]
def get_random_advice():
res = requests.get("https://api.adviceslip.com/advice").json()
return res['slip']['advice']
def play_on_youtube(video):
kit.playonyt(video)
def open_camera():
sp.run('start microsoft.windows.camera:', shell=True)
def open_cmd():
os.system('start cmd')
def open_calculator():
sp.Popen("C:\\Windows\\System32\\calc.exe")
def ai(prompt):
openai.api_key = apikey
text= f"OpenAi response for Prompt: {prompt} \n***************\n"
response = openai.Completion.create(
model="text-davinci-003",
prompt=prompt,
temperature=0.7,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
print(response["choices"][0]["text"])
text +=response["choices"][0]["text"]
if not os.path.exists("Openai"):
os.mkdir("Openai")
# with open(f"Openai/prompt- {random.randint(1,235456455)}","w") as f:
with open(f"Openai/{''.join(prompt.split('intelligence')[1:]).strip()}.txt","w") as f:
f.write(text)
chatStr=""
def chat(query):
global chatStr
# print(chatStr)
openai.api_key = apikey
chatStr +=f"Tyflon: {query}\n Neom:"
response = openai.Completion.create(
model="text-davinci-003",
prompt= chatStr,
temperature=0.7,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
say(response["choices"][0]["text"])
chatStr += f"{response['choices'][0]['text']}\n"
return response["choices"][0]["text"]
def wish():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
say("Good Morning")
elif hour>=12 and hour<18:
say("Good Afternoon")
else:
say("Good Evening")
say("Why to fear if neom is here")
if __name__ == '__main__':
# say("Hello I am NEOM")
wish()
while True:
#print("Listning...")
sites=websites.websites_dict
m='open '.join(sites.keys())
query= takeCommand()
if query.lower() in m.lower() :
for site in sites.keys():
if f"Open {site}".lower() in query.lower():
say(f"Opening {site}")
webbrowser.open(str(sites[site]))
# say(query)
elif "the time" in query:
strftime=datetime.datetime.now().strftime("%H:%M:%S")
say(f"The time is {strftime}")
elif "news" in query:
news_list = client.get_news()
for item in news_list:
st = item['title'].split(' - ', 1)[0]
print(st)
say(st)
elif "suggest" in query:
query = query.replace("suggest", "best")
query = query.replace(" ","+")
webbrowser.open("www.google.com/search?q="+query)
say("These are some results")
elif "calculate" in query:
query = query.replace(" ","")
query = query.replace("calculate","")
query = query.replace("evaluate","")
if 'into' in query:
query = query.replace("into","*")
if 'by' in query:
query = query.replace("by","/")
try:
result=eval(query)
except:
result="invalid"
print("The result is: ",str(result))
say("Result is "+str(result))
elif "send a whatsaap message" in query or "send a WhatsApp message" in query:
driver = webdriver.Chrome('chrome_driver\chromedriver.exe')
driver.get('https://web.whatsapp.com/')
wait = WebDriverWait(driver, 600)
say("Scan QR code before proceding")
tim=10
time.sleep(tim)
say("Enter Name of Group or User")
# name = takeCommanduser()
name="My notes"
say("Enter Your Message")
# msg = takeCommandmessage()
msg="Hello"
x_arg = '//span[contains(@title,' + name + ')]'
group_title = wait.until(EC.presence_of_element_located((By.XPATH, x_arg)))
group_title.click()
inp_xpath = '//div[@class="_13NKt copyable-text selectable-text"][@data-tab="9"]'
input_box = wait.until(EC.presence_of_element_located((By.XPATH, inp_xpath)))
for i in range(100):
input_box.send_keys(msg + Keys.ENTER)
time.sleep(1)
elif 'how are you' in query:
say("I am fine , Thank you")
say("How are you??")
elif 'joke' in query:
say(pyjokes.get_joke())
elif 'is love' in query:
say("It is 7th sense that destroy all other senses")
elif "who are you" in query:
say("I am your virtual assistant created by Tyflon")
elif "will you be my girlfriend" in query or "will you be my boyfriend" in query:
say("I'm not sure about , may be you should give me some time")
elif "how are you" in query:
say("I'm fine, glad you asked me that")
elif "i love you".lower() in query:
say("It's hard to understand")
elif "open Gmail" in query:
webbrowser.open("https://mail.google.com/mail/u/0/#inbox")
elif "where is" in query:
query=query.replace("where is","")
location = query
say("Locating ")
say(location)
webbrowser.open("https://www.google.nl/maps/place/" + location + "")
elif "open camera" in query:
open_camera()
elif "take a photo" in query:
ec.capture(0,"Camera ","img.jpg")
elif "open calculator" in query:
open_calculator()
elif "open command prompt" in query or "open cmd" in query:
open_cmd()
elif "write a note" in query:
say("What should i write: ")
note= takeCommand()
file = open('note.txt','w')
say("Should i include date and time")
snfm = takeCommand()
if 'yes' in snfm or 'sure' in snfm:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
file.write(strTime)
file.write(" :- ")
file.write(note)
else:
file.write(note)
elif "show note" in query:
say("Showing Notes")
file = open("jarvis.txt", "r")
print(file.read())
say(file.read(6))
elif "open notepad".lower() in query.lower():
say('opening notepad for you.......')
path = ("c:\\windows\\system32\\notepad.exe")
os.startfile(path)
elif "close notepad".lower() in query.lower():
say('closing notepad wait.....')
os.system('c:\\windows\\system32\\taskkill.exe /F /IM notepad.exe')
elif "weather" in query:
api_key="8ef61edcf1c576d65d836254e11ea420"
base_url="https://api.openweathermap.org/data/2.5/weather?"
say("whats the city name")
city_name=takeCommand()
complete_url=base_url+"appid="+api_key+"&q="+city_name
response = requests.get(complete_url)
x=response.json()
if x["cod"]!="404":
y=x["main"]
current_temperature = y["temp"]
current_humidiy = y["humidity"]
z = x["weather"]
weather_description = z[0]["description"]
say(" Temperature in kelvin unit is " +
str(current_temperature) +
"\n humidity in percentage is " +
str(current_humidiy) +
"\n description " +
str(weather_description))
print(" Temperature in kelvin unit = " +
str(current_temperature) +
"\n humidity (in percentage) = " +
str(current_humidiy) +
"\n description = " +
str(weather_description))
else:
say(" City Not Found ")
elif "ip address".lower() in query.lower():
say("wait")
ip_address = find_my_ip()
say(f'Your IP Address is {ip_address}.\n For your convenience, I am printing it on the screen.')
print(f'Your IP Address is {ip_address}')
elif "advice" in query:
say(f"Here's an advice for you")
advice = get_random_advice()
print(advice)
say(advice)
elif "youtube".lower() in query.lower():
say('What do you want to play on Youtube?')
video = takeCommand().lower()
play_on_youtube(video)
elif "Using artificial intelligence".lower() in query.lower():
ai(prompt=query)
elif "reset chat" in query:
chatStr=""
elif "bye" in query:
print("Adios amigose")
say("Adios amigose")
exit(0)
else:
chat(query)