-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
111 lines (92 loc) · 3.22 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
import speech_recognition as sr
import os
import webbrowser
import openai
import datetime
from config import apikey
import random
import numpy as np
chatStr = ""
# https://youtu.be/Z3ZAJoi4x6Q
def chat(query):
global chatStr
print(chatStr)
openai.api_key = apikey
chatStr += f"Kanishk: {query}\n Macky: "
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
)
# todo: Wrap this inside of a try catch block
say(response["choices"][0]["text"])
chatStr += f"{response['choices'][0]['text']}\n"
return response["choices"][0]["text"]
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.7,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
# todo: Wrap this inside of a try catch block
# 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)
def say(text):
os.system(f"say {text}")
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
r.pause_threshold = 1
audio = r.listen(source)
try:
query = r.recognize_google(audio,language="en-in")
print(f"User said: {query}")
return query
except Exception as e:
return "Some Error occured. Sorry from Macky!"
query = r.recognize_google(audio, language="en-in")
print(f"User said: {query}")
return query
if __name__ == '__main__':
print('PyCharm')
say("Hello I am Macky")
while True:
print("Listening...")
query = takeCommand()
sites = [["youtube","https://youtube.com"],["wikipedia","https://wikipedia.com"],["google","https://google.com"]]
#todo:Make for other sites hence make a list
for site in sites:
if f"Open {site[0]}".lower() in query.lower():
say(f"Opening {site[0]} ...")
webbrowser.open(site[1])
if "the time" in query:
strfTime = datetime.now().strftime("%H:%M:%S")
say(f"The time is... {strfTime}")
#todo:Make for all apps hence make a list
elif "open Facetime".lower() in query.lower():
os.system(f"open /System/Applications/FaceTime.app")
elif "Using artificial intelligence".lower() in query.lower():
ai(prompt=query)
elif "Jarvis Quit".lower() in query.lower():
exit()
elif "reset chat".lower() in query.lower():
chatStr = ""
else:
print("Chatting...")
chat(query)
#say(text)