-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElevatorAI.py
590 lines (486 loc) · 18.3 KB
/
ElevatorAI.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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
import base64
import sys
import pyttsx3 # pip install pyttsx3
import os # pip install os
import speech_recognition as sr # pip install speechRecognition
import wikipedia # pip install wikipedia
import webbrowser # pip install webbrowser
import openai # pip install openai
from django.contrib.sites import requests
from google import generativeai
import google.generativeai as genai # pip install google-generativeai
from config import apikey
import datetime # pip install datetime
import random # pip install random
import numpy as np # pip install numpy
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
# print(voices[1].id)
engine.setProperty("voice", voices[0].id)
chatStr = ""
# Source: https://youtu.be/Z3ZAJoi4x6Q
def chat(query):
global chatStr
print(chatStr)
openai.api_key = apikey
chatStr += f"{Username}: {query}\n Elevator AI: "
response = openai.Completion.create(
model="text-davinci-003",
prompt=chatStr,
temperature=0.2,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
try:
say(response["choices"][0]["text"])
chatStr += f"{response['choices'][0]['text']}\n"
return response["choices"][0]["text"]
except Exception:
print("Some problem occurred!")
speak("Some problem occurred!")
chat(query)
def ai(prompt):
openai.api_key = apikey
text = f"OpenAI response for Prompt: {prompt} \n *************************\n\n"
response = openai.Completion.create(
model="text-davinci-003",
prompt=prompt,
temperature=0.2,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
try:
# 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, 2343434356)}", "w") as f:
with open(f"Openai/{''.join(prompt.split('intelligence')[1:]).strip()}.txt", "w") as f:
f.write(text)
except Exception:
print("Some problem occurred!")
speak("Some problem occurred!")
ai(prompt)
# Speaking function :-
def speak(audio):
try:
engine.say(audio)
engine.runAndWait()
except Exception:
print("Some problem occurred!")
speak("Some problem occurred!")
speak(audio)
# https://youtu.be/Z3ZAJoi4x6Q
def chat(query):
try:
global chatStr
print(chatStr)
except Exception:
print("Some problem occurred!")
speak("Some problem occurred!")
chat(query)
def ai(prompt):
try:
text = f"OpenAI response for Prompt: {prompt} \n *************************\n\n"
# with open(f"Openai/prompt- {random.randint(1, 2343434356)}", "w") as f:
with open(
f"Openai/{''.join(prompt.split('intelligence')[1:]).strip()}.txt", "w"
) as f:
f.write(text)
except Exception:
print("Some problem occurred!")
speak("Some problem occurred!")
ai(prompt)
def say(text):
try:
os.system(f'say "{text}"')
except Exception:
print("Some problem occurred!")
speak("Some problem occurred!")
say(text)
def takeCommand():
try:
r = sr.Recognizer()
with sr.Microphone() as source:
# r.pause_threshold = 0.6
audio = r.listen(source)
try:
print("Recognizing...")
speak("Recognizing...")
query = r.recognize_google(audio, language="en-in")
print(f"User said: {query}")
return query
except Exception:
return "Some Error Occurred. Sorry from Elevator A.I"
except Exception:
print("Some problem occurred!")
speak("Some problem occurred!")
takeCommand()
def _on_update_interval():
try:
pass
except Exception:
print("Some problem occurred!")
speak("Some problem occurred!")
_on_update_interval()
_on_update_interval()
print("Elevator AI")
speak("Elevator AI")
print(
"Hello, My name is Arinjay Kumar. I am the founder of this AI. I hope you like it."
)
print("Enjoy!")
Username = str(input("Please enter your username to continue: "))
def the_main():
try:
if Username == "Arinjay":
print("Your name is same as our founder i.e. Arinjay Kumar")
elif Username == "":
print("Please write your preferred username:")
speak("Please write your preferred username:")
elif Username == "arinjay":
print("Your name is same as our founder i.e. Arinjay Kumar")
elif Username == "Arinjay Kumar":
print("Your name is same as our founder i.e. Arinjay Kumar")
elif Username == "arinjay kumar":
print("Your name is same as our founder i.e. Arinjay Kumar")
elif Username == "Arinjay kumar":
print("Your name is same as our founder i.e. Arinjay Kumar")
elif Username == "arinjay Kumar":
print("Your name is same as our founder i.e. Arinjay Kumar")
except Exception:
print("Some problem occurred!")
speak("Some problem occurred!")
the_main()
the_main()
Usernameage = int(input("Please enter your current age for verification: "))
def the_main_v():
try:
if Usernameage >= 18:
print("🔃 Loading 🔃")
if Usernameage <= 120:
print("🔃 Loading 🔃")
if Usernameage <= 18:
print("You are not allowed!")
int(input("Please enter your current age for verification: "))
if Usernameage >= 120:
print("You are not allowed!")
int(input("Please enter your current age for verification: "))
except Exception:
print("Some problem occurred!")
speak("Some problem occurred!")
the_main_v()
the_main_v()
print("Hello,", Username)
print("🔃 Loading 🔃")
print("Fixing screws")
print("Starting engine")
print("Ready!")
print("** Warning **")
print(
"This is in beta stage and is currently in development. We strictly do not recommend users to give any personal "
"information on this app."
)
print("🔃 Loading 🔃")
q1 = "Who is me?"
q11 = "who is me"
q111 = "Who is me"
q1111 = "who is me?"
q2 = "Who is your founder?"
q22 = "who is your founder"
q222 = "Who is your founder"
q2222 = "who is your?"
q3 = "Who are you?"
q33 = "who are you"
q333 = "Who are you"
q3333 = "who are you?"
List=[
"1. OpenAI's ChatGPT 3.5",
"2. Google's Gemini 1.0 AI",
"3. Stability XL 1024 1.0",
"4. Or continue with Elevator AI..."
]
print(List)
Diversion = str(input("Please enter the number of the AI model you are going to use: "))
def chat_List_Def():
if Diversion == "1. OpenAI's ChatGPT 3.5" or 1:
chatgpt()
elif Diversion == "2. Google's Gemini 1.0 AI" or 2:
gemini()
elif Diversion == "3. Stability XL 1024 1.0" or 3:
stability()
elif Diversion == "4. Or continue with Elevator AI..." or 4:
the_maingame()
else:
print("Elevator AI -> That is not what I expected!")
print("Elevator AI -> Please try again by restarting the application.")
sys.exit()
chat_List_Def()
def chatgpt():
def chat():
input = input("Please enter your ChatGPT API Key from https://platform.openai.com/api-keys -> ")
openai.api_key = input
maininput = input("You -> ")
response = openai.Completion.create(
model="text-davinci-003",
prompt=maininput,
temperature=0.2,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
print("ChatGPT -> ", response)
def loop():
if chat():
chat()
loop()
else:
chat()
loop()
loop()
def gemini():
def chat():
maininput = input("Please enter your Gemini API Key from https://aistudio.google.com/app/prompts/new_chat -> ")
input = input("You -> ")
print("""
I am still under development, and there are many things that I do not know. If I don't know the answer to a question, I will say so honestly. I will also try to provide some context or resources that may help you find the answer yourself. For example, I might say something like "I'm not sure about that, but I can find out for you. Can you give me more information about what you're looking for?" or "I'm not familiar with that topic, but I can provide you with some links to relevant websites."
I am always learning new things, and I am committed to providing accurate and helpful information to my users. If you ever notice that I have made a mistake, please feel free to let me know. I appreciate your feedback and will use it to improve my performance.
""")
"""
At the command line, only need to run once to install the package via pip:
$ pip install google-generativeai
"""
genai.configure(api_key="maininput")
# Set up the model
generation_config = {
"temperature": 1,
"top_p": 1,
"top_k": 1,
"max_output_tokens": 2048,
}
safety_settings = [
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
]
model = genai.GenerativeModel(model_name="gemini-1.0-pro-001",
generation_config=generation_config,
safety_settings=safety_settings)
convo = model.start_chat(history=[
])
convo.send_message("input")
print(convo.last.text)
def loop():
if chat():
chat()
loop()
else:
chat()
loop()
loop()
def stability():
def chat():
url = "https://api.stability.ai/v1/generation/stable-diffusion-xl-1024-v1-0/text-to-image"
maininput = input("Please enter your Stability API Key from https://platform.stability.ai/account/keys -> ")
input = input("Your prompt -> ")
input2 = input("How you want it to look like? Separate your options by a comma -> ")
text_Prompt = input
prompt_type = input2
body = {
"steps": 40,
"width": 1024,
"height": 1024,
"seed": 0,
"cfg_scale": 5,
"samples": 1,
"text_prompts": [
{
"text": text_Prompt,
"weight": 1
},
{
"text": prompt_type,
"weight": -1
}
],
}
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": maininput,
}
response = requests.post(
url,
headers=headers,
json=body,
)
if response.status_code != 200:
raise Exception("Non-200 response: " + str(response.text))
data = response.json()
# make sure the out directory exists
if not os.path.exists("./output"):
os.makedirs("./output")
for i, image in enumerate(data["artifacts"]):
with open(f'./output/tti_{image["seed"]}.png', "wb") as f:
f.write(base64.b64decode(image["base64"]))
print("Elevator AI -> Finished, check this directory.")
def loop():
if chat():
chat()
loop()
else:
chat()
loop()
loop()
Chat = str(input("Please write what you like to say: "))
def the_maingame():
query = Chat
try:
if "Wikipedia" in query:
print("Finding...")
query = query.replace("Wikipedia", "")
results = wikipedia.summary(query, sentences=2)
print("According to Wikipedia : ")
speak("According to Wikipedia : ")
print(results)
speak(results)
if "What" in query:
print("Finding...")
query = query.replace("Wikipedia", "")
results = wikipedia.summary(query, sentences=2)
print("According to Wikipedia : ")
speak("According to Wikipedia : ")
print(results)
speak(results)
if "what" in query:
print("Finding...")
query = query.replace("Wikipedia", "")
results = wikipedia.summary(query, sentences=2)
print("According to Wikipedia : ")
speak("According to Wikipedia : ")
print(results)
speak(results)
if "Who" in query:
print("Finding...")
query = query.replace("Wikipedia", "")
results = wikipedia.summary(query, sentences=2)
print("According to Wikipedia : ")
speak("According to Wikipedia : ")
print(results)
speak(results)
if "who" in query:
print("Finding...")
query = query.replace("Wikipedia", "")
results = wikipedia.summary(query, sentences=2)
print("According to Wikipedia : ")
speak("According to Wikipedia : ")
print(results)
speak(results)
if query == q1:
print("You are ", Username)
str(input("Please write what you like to say: "))
if query == q11:
print("You are ", Username)
str(input("Please write what you like to say: "))
if query == q111:
print("You are ", Username)
str(input("Please write what you like to say: "))
if query == q1111:
print("You are ", Username)
str(input("Please write what you like to say: "))
if query == q2:
print("I am founded by the ElevatorAI Developer Team.")
speak("I am founded by the ElevatorAI Developer Team.")
str(input("Please write what you like to say: "))
if query == q22:
print("I am founded by the ElevatorAI Developer Team.")
speak("I am founded by the ElevatorAI Developer Team.")
str(input("Please write what you like to say: "))
if query == q222:
print("I am founded by the ElevatorAI Developer Team.")
speak("I am founded by the ElevatorAI Developer Team.")
str(input("Please write what you like to say: "))
if query == q2222:
print("I am founded by the ElevatorAI Developer Team.")
speak("I am founded by the ElevatorAI Developer Team.")
str(input("Please write what you like to say: "))
if query == q3:
print(
"I am an AI(Artificial Intelligence) made by my founder - Mr. Arinjay Kumar."
)
speak(
"I am an AI(Artificial Intelligence) made by my founder - Mr. Arinjay Kumar."
)
str(input("Please write what you like to say: "))
if query == q33:
print(
"I am an AI(Artificial Intelligence) made by my founder - Mr. Arinjay Kumar."
)
speak(
"I am an AI(Artificial Intelligence) made by my founder - Mr. Arinjay Kumar."
)
str(input("Please write what you like to say: "))
if query == q333:
print(
"I am an AI(Artificial Intelligence) made by my founder - Mr. Arinjay Kumar."
)
speak(
"I am an AI(Artificial Intelligence) made by my founder - Mr. Arinjay Kumar."
)
str(input("Please write what you like to say: "))
if query == q3333:
print(
"I am an AI(Artificial Intelligence) made by my founder - Mr. Arinjay Kumar."
)
speak(
"I am an AI(Artificial Intelligence) made by my founder - Mr. Arinjay Kumar."
)
str(input("Please write what you like to say: "))
else:
print("Sorry, I have not gained that particular information yet.")
speak("Sorry, I have not gained that particular information yet.")
print("You can make me learn it, please write the answer then : ")
speak("You can make me learn it, please write the answer then : ")
userinput = input(
"You can make me learn it, please write the answer then : "
)
except Exception:
print("Some problem occurred!")
speak("Some problem occurred!")
the_maingame()
def userinput_change():
try:
if userinput != query:
name = open("usernames.txt", "w")
name.write(userinput)
name.close()
open1 = open("usernames.txt", "r")
print(open1.read())
except Exception:
print("Some problem occurred!")
speak("Some problem occurred!")
userinput_change()
str(input("Please write what you like to say: "))
the_maingame()
print("The End!")
speak("The End!")
def on_update_interval():
pass