Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lokendarjangid committed Mar 19, 2024
1 parent 9cf11dc commit 5afa274
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/.venv/
/images/
/images/
/env
Binary file added __pycache__/chatgpt.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/s_functions.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/voice_work.cpython-311.pyc
Binary file not shown.
140 changes: 104 additions & 36 deletions loki.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from inspect import _void
import re
import s_functions
import chatgpt
Expand All @@ -8,10 +9,53 @@
import datetime
import requests
import random
# import pywhatkit
import BeautifulSoup



voice_p = voice_work.voice()
chat = chatgpt.Chatgpt()

#other functions

def searchGoogle(query):
if "google" in query:
import wikipedia as googleScrap
query = query.replace("jarvis","")
query = query.replace("google search","")
query = query.replace("google","")
voice_p.speak("This is what I found on google")

try:
# pywhatkit.search(query)
result = googleScrap.summary(query,1)
voice_p.speak(result)

except:
voice_p.speak("No speakable output available")

def searchYoutube(query):
if "youtube" in query:
voice_p.speak("This is what I found for your search!")
query = query.replace("youtube search","")
query = query.replace("youtube","")
query = query.replace("jarvis","")
web = "https://www.youtube.com/results?search_query=" + query
webbrowser.open(web)
# pywhatkit.playonyt(query)
voice_p.speak("Done, Sir")

def searchWikipedia(query):
if "wikipedia" in query:
voice_p.speak("Searching from wikipedia....")
query = query.replace("wikipedia","")
query = query.replace("search wikipedia","")
query = query.replace("jarvis","")
results = wikipedia.summary(query,sentences = 2)
voice_p.speak("According to wikipedia..")
print(results)
voice_p.speak(results)

def commands(command_user):
prompt_text = str(command_user)
Expand Down Expand Up @@ -68,42 +112,66 @@ def commands(command_user):
elif 'bye' in command_user or 'stop' in command_user or 'exit' in command_user:
voice_p.printandspeak("Bye Sir, have a good day.")
exit()

elif 'generate image' in command_user:

response = chat.generate_image(prompt_text=prompt_text)
for image in response['data']:
# print(image['url'])
img_data = requests.get(image['url']).content
command_user = command_user.replace("generate image", "")
if 'of' in command_user:
command_user = command_user.replace("of", "")
# os.chdir('images')1
os.chdir("images")
fname = os.path.join(os.getcwd(), str(command_user)+'.jpg')
with open(fname, 'wb') as handler:
handler.write(img_data)
os.chdir("..")
return "Image generated"

elif 'write code' in command_user or 'write a code' in command_user or 'write program' in command_user:
response = chat.write_code(prompt_text=prompt_text)

for choice in response['choices']:
print(choice['text'])
return"Here is code"

else:
response = chat.text_out(prompt_text=prompt_text)

for choice in response['choices']:
voice_p.printandspeak(choice['text'])
# s_functions.intotxtfile(prompt_text, choice['text'])
if choice['text'].find('?') != -1:
commander()
else:
pass


elif "google" in command_user:
searchGoogle(command_user)

elif "youtube" in command_user:
searchYoutube(command_user)

elif "wikipedia" in command_user:
searchWikipedia(command_user)

elif "temperature" in command_user:
search = "temperature in delhi"
url = f"https://www.google.com/search?q={search}"
r = requests.get(url)
data = BeautifulSoup(r.text,"html.parser")
temp = data.find("div", class_ = "BNeawe").text
voice_p.speak(f"current{search} is {temp}")
elif "weather" in query:
search = "temperature in delhi"
url = f"https://www.google.com/search?q={search}"
r = requests.get(url)
data = BeautifulSoup(r.text,"html.parser")
temp = data.find("div", class_ = "BNeawe").text
voice_p.speak(f"current{search} is {temp}")
# elif 'generate image' in command_user:

# response = chat.generate_image(prompt_text=prompt_text)
# for image in response['data']:
# # print(image['url'])
# img_data = requests.get(image['url']).content
# command_user = command_user.replace("generate image", "")
# if 'of' in command_user:
# command_user = command_user.replace("of", "")
# # os.chdir('images')1
# os.chdir("images")
# fname = os.path.join(os.getcwd(), str(command_user)+'.jpg')
# with open(fname, 'wb') as handler:
# handler.write(img_data)
# os.chdir("..")
# return "Image generated"

# elif 'write code' in command_user or 'write a code' in command_user or 'write program' in command_user:
# response = chat.write_code(prompt_text=prompt_text)

# for choice in response['choices']:
# print(choice['text'])
# return"Here is code"

# else:
# response = chat.text_out(prompt_text=prompt_text)

# for choice in response['choices']:
# voice_p.printandspeak(choice['text'])
# # s_functions.intotxtfile(prompt_text, choice['text'])
# if choice['text'].find('?') != -1:
# commander()
# else:
# pass
else :
voice_p.printandspeak("command not found")

def commander():
command_user = voice_p.takeCommand().lower()
Expand Down
Binary file renamed requirement.txt → requirements.txt
Binary file not shown.
1 change: 1 addition & 0 deletions s_functions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import random


Expand Down
8 changes: 7 additions & 1 deletion voice_work.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import pyttsx3
import datetime
import speech_recognition as sr
import platform

class voice:
def __init__(self) -> None:
self.engine = pyttsx3.init('sapi5')
if platform.system() == 'Linux':
self.engine = pyttsx3.init('nsss')
elif platform.system() == 'Windows':
self.engine = pyttsx3.init('sapi5')
else:
raise Exception("Unsupported platform")
voices = self.engine.getProperty('voices')
# print(voices[3].id)
self.engine.setProperty('voice', voices[0].id)
Expand Down

0 comments on commit 5afa274

Please sign in to comment.