-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjarvis.py
234 lines (203 loc) · 8.06 KB
/
jarvis.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
import datetime
import streamlit as st
import queue
import pyttsx3
import speech_recognition as sr
import pyaudio
import wikipedia
import webbrowser
import os
import glob
import pyjokes
import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.keys import Keys
import time
# Import "chatbot" from
# chatterbot package.
# engine=pyttsx3.init('sapi5')
# voices=engine.getProperty('voices')
# #print(voices[0].id)
# engine.setProperty('voice',voices[0].id)
def speak(audio):
engine=pyttsx3.init()
engine.say(audio)
engine.runAndWait()
def wishMe():
time=int(datetime.datetime.now().hour)
if time>=0 and time<12:
speak('Good Morning!')
elif time>=12 and time<15:
speak('Good After Noon!')
elif time>=15 and time<=18:
speak('Good Evening!')
else:
speak('Good Night!')
speak('Hi Soorya I am Jarvis, how may i help you!')
def takeVoice():
r=sr.Recognizer()
with sr.Microphone() as source:
st.write('Listening......')
r.pause_threshold=1
audio=r.listen(source)
try:
st.write('Recognizing....')
query=r.recognize_google(audio,language='en-in')
st.write('User said: ',query)
except Exception as e:
#print(e)
st.write('Say that again..')
return 'None'
return query
# speak('Hi Vasanta, how are you!')
# takeVoice()
# speak('Thats great amma!')
# speak('Hi Srinivas, how are you!')
# takeVoice()
# speak('Thats great daddy!')
import os
import streamlit as st
import openai
from PIL import Image
openai.organization = "org-EAWKAvX0fNJktesxHitezbNV"
openai.api_key = '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'
openai.Model.list()
# function that takes in string argument as parameter
def comp(PROMPT, MaxToken=50, outputs=3):
# using OpenAI's Completion module that helps execute
# any tasks involving text
response = openai.Completion.create(
# model name used here is text-davinci-003
# there are many other models available under the
# umbrella of GPT-3
model="text-davinci-003",
# passing the user input
prompt=PROMPT,
# generated output can have "max_tokens" number of tokens
max_tokens=MaxToken,
# number of outputs generated in one call
n=outputs
)
# creating a list to store all the outputs
output = list()
for k in response['choices']:
output.append(k['text'].strip())
return output
# prompt="Advantages of open source contributions"
def main():
col1,col2=st.columns(2)
with col1:
st.title("J.A.R.V.I.S AI")
with col2:
image = Image.open('jarv.png') # Replace with your image path
st.image(image,width=250)
if st.button("Let's Start the AI mode"):
wishMe()
while True:
query = takeVoice().lower()
if 'ai' in query:
speak('Sure Going To AI Mode Now!')
speak('What do you want now?')
prompt = takeVoice().lower()
response = comp(prompt, MaxToken=3000, outputs=3)[0]
st.write(response)
speak(response)
if 'wikipedia'in query:
speak('Searching Wikipedia...')
query=query.replace('wikipedia','')
results=wikipedia.summary(query,sentences=2)
speak('According to Wikipedia')
speak(results)
elif 'how are you' in query:
speak('I am good Soorya, How are your?')
takeVoice()
speak('Thats great soorya!')
elif 'am i good' in query:
speak('Yeah!, soorya you are good .')
elif 'what language do you speak' in query:
speak('I speak in English, soorya!')
elif 'male or female'in query:
speak('I have no gender soorya , I am a bot, But i have a male voice. ')
elif 'your name' in query:
speak('My name is Jarvis and I am a Basic AI bot.')
elif 'created you' in query:
speak('Mr.Soorya created me')
elif 'good job' in query:
speak('Thank you soorya!!')
elif 'list' in query:
l=[]
c=0
speak('Tell me the items')
for i in range(11):
l.append(takeVoice().lower())
if 'enough' in l:
break
speak('Here is your list')
if 'enough' in l:
l.remove('enough')
print(l)
elif 'open github' in query:
speak('Opening Github')
webbrowser.open('github.com')
elif 'open codestudio' in query:
speak('Opening codestudio')
webbrowser.open('https://www.codingninjas.com/codestudio')
elif 'open kmit telescope' in query:
speak('Opening tesellator kmit')
webbrowser.open('http://kmitonline.com/login/index.php')
elif 'open codechef' in query:
speak('Opening codechef')
webbrowser.open('https://www.codechef.com/')
elif 'open leetcode' in query:
speak('Opening leetcode')
webbrowser.open('https://leetcode.com/')
elif 'open geeks for geeks' in query:
speak('Opening geeks for geeks')
webbrowser.open('https://www.geeksforgeeks.org/')
elif 'open w3schools' in query:
speak('opening w3schools')
webbrowser.open('https://www.w3schools.com/')
elif 'open linkedin' in query:
speak('opening linkedin')
webbrowser.open('https://www.linkedin.com/feed/')
elif 'open youtube' in query:
speak('Opening Youtube')
webbrowser.open('youtube.com')
elif 'open google' in query:
speak('Opening Google')
webbrowser.open('google.com')
elif 'open stackoverflow' in query:
speak('Opening Stackoverflow')
webbrowser.open('stackoverflow.com')
elif 'open spotify' in query:
speak('Opening spotify')
webbrowser.open('https://open.spotify.com/playlist/54T5DjOloBIoWwGS3wX1h6?si=4f33b22119e94700')
elif 'the time' in query:
strtime=datetime.datetime.now().strftime('%H:%M:%S')
speak(f'Soorya the time is : {strtime}')
elif 'open vs code' in query:
code_path="C:\\Users\\MARRI SAI SOORYA\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
os.startfile(code_path)
elif 'joke' in query:
speak('Here is the joke..')
My_joke = pyjokes.get_joke(language="en", category="neutral") # u can change category with 'twister' and 'all'
speak(My_joke)
continue
elif 'open whatsapp' in query:
speak('Opening Whatsapp Web')
webbrowser.open('https://web.whatsapp.com/')
elif 'open notion' in query:
code_path="C:\\Users\\MARRI SAI SOORYA\\AppData\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Notion.lnk"
os.startfile(code_path)
elif 'how are you' in query:
speak('I am good Soorya, How are your?')
takeVoice()
speak('Thats great soorya!')
elif 'stop' in query:
speak('Ok, I am stopping, Bye Soorya')
break
if __name__ == "__main__":
main()