-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJarvis V2.py
119 lines (98 loc) · 3.56 KB
/
Jarvis V2.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
#Jarvis v2
import speech_recognition as sr
import os
import webbrowser
import openai
from config import apikey
import datetime
import random
import numpy as np
chatStr = ""
# https://youtu.be/Z3ZAJoi4x6Q
def chat(query):
global chatStr
print(chatStr)
openai.api_key = apikey
chatStr += f"Harry: {query}\n Jarvis: "
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 = 0.6
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language="en-in")
print(f"User said: {query}")
return query
except Exception as e:
return "Some Error Occurred. Sorry from Jarvis"
if __name__ == '__main__':
print('Welcome to Jarvis A.I')
say("Jarvis A.I")
while True:
print("Listening...")
query = takeCommand()
# todo: Add more sites
sites = [["youtube", "https://www.youtube.com"], ["wikipedia", "https://www.wikipedia.com"], ["google", "https://www.google.com"],]
for site in sites:
if f"Open {site[0]}".lower() in query.lower():
say(f"Opening {site[0]} sir...")
webbrowser.open(site[1])
# todo: Add a feature to play a specific song
if "open music" in query:
musicPath = "/Users/harry/Downloads/downfall-21371.mp3"
os.system(f"open {musicPath}")
elif "the time" in query:
musicPath = "/Users/harry/Downloads/downfall-21371.mp3"
hour = datetime.datetime.now().strftime("%H")
min = datetime.datetime.now().strftime("%M")
say(f"Sir time is {hour} bajke {min} minutes")
elif "open facetime".lower() in query.lower():
os.system(f"open /System/Applications/FaceTime.app")
elif "open pass".lower() in query.lower():
os.system(f"open /Applications/Passky.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(query)