diff --git a/__pycache__/chatgpt.cpython-310.pyc b/__pycache__/chatgpt.cpython-310.pyc new file mode 100644 index 0000000..951ba29 Binary files /dev/null and b/__pycache__/chatgpt.cpython-310.pyc differ diff --git a/__pycache__/s_functions.cpython-310.pyc b/__pycache__/s_functions.cpython-310.pyc new file mode 100644 index 0000000..2b54c09 Binary files /dev/null and b/__pycache__/s_functions.cpython-310.pyc differ diff --git a/__pycache__/voice_work.cpython-310.pyc b/__pycache__/voice_work.cpython-310.pyc new file mode 100644 index 0000000..05d9e70 Binary files /dev/null and b/__pycache__/voice_work.cpython-310.pyc differ diff --git a/chatgpt.py b/chatgpt.py deleted file mode 100644 index 3de9f4c..0000000 --- a/chatgpt.py +++ /dev/null @@ -1,32 +0,0 @@ -import openai - -class Chatgpt: - def __init__(self) -> None: - openai.api_key = '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' - - def write_code(self, prompt_text): - response = openai.Completion.create( - model="code-davinci-002", - prompt=prompt_text, - temperature=0, - max_tokens=256, - ) - - return response - - def text_out(self, prompt_text: str): - response = openai.Completion.create( - model="text-davinci-003", - prompt=prompt_text, - max_tokens=400, - temperature=0.9, - ) - return response - - def generate_image(self, prompt_text): - response = openai.Image.create( - prompt=prompt_text, - n=1, - size="1024x1024" - ) - return response diff --git a/images/ a dog.jpg b/images/ a dog.jpg deleted file mode 100644 index 6b265a9..0000000 Binary files a/images/ a dog.jpg and /dev/null differ diff --git a/loki.py b/loki.py index 1284297..5ef188e 100644 --- a/loki.py +++ b/loki.py @@ -1,7 +1,5 @@ -from inspect import _void import re -import s_functions -import chatgpt +import s_functions as sf import voice_work import wikipedia # pip install wikipedia import webbrowser @@ -9,65 +7,14 @@ import datetime import requests import random -# import pywhatkit -import BeautifulSoup - - +from bs4 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) # Logic for executing tasks based on command_user - if 'wikipedia' in command_user: - voice_p.speak('Searching Wikipedia...') - command_user = command_user.replace("wikipedia", "") - results = wikipedia.summary(command_user, sentences=2) - voice_p.speak("According to Wikipedia") - return results - - elif 'open youtube' in command_user: + if 'open youtube' in command_user: webbrowser.open("youtube.com") elif 'open google' in command_user: @@ -85,6 +32,15 @@ def commands(command_user): elif 'open whatsapp' in command_user: webbrowser.open("whatsapp.com") + elif "google" in command_user: + sf.searchGoogle(command_user) + + elif "youtube" in command_user: + sf.searchYoutube(command_user) + + elif "wikipedia" in command_user: + sf.searchWikipedia(command_user) + elif 'play music' in command_user: music_dir = 'C:\\Users\\Lenovo\\Music' songs = os.listdir(music_dir) @@ -95,7 +51,7 @@ def commands(command_user): strTime = datetime.datetime.now().strftime("%H:%M:%S") return (f"Sir, the time is {strTime}") - elif 'open code' in command_user: + elif 'open vs code' in command_user: codePath = "C:\\Users\\Lenovo\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe" os.startfile(codePath) @@ -106,70 +62,29 @@ def commands(command_user): except AttributeError: length = 8 - password = s_functions.passwordgenerator(int(length)) + password = sf.passwordgenerator(int(length)) return (f"Your password is {str(password)}") - - 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 "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" + search = "temperature in jaipur" 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" + + elif "weather" in command_user: + search = "temperature in jaipur" 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 + + 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() + else : voice_p.printandspeak("command not found") diff --git a/requirements.txt b/requirements.txt index 1a0bc78..9816cc5 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/s_functions.py b/s_functions.py index 9b9c208..790a62f 100644 --- a/s_functions.py +++ b/s_functions.py @@ -1,47 +1,48 @@ - import random - - -# normal maths import string - - -def addition(a, b): - c = a + b - return c - - -def subtract(a, b): - c = a - b - return c - - -def area_of_circle(radius): - """This function will calculate area of circle . when you enter radius . - This function will calculate automatically area of circle and give you answer.""" - - area = 3.14159 * radius * radius - return area - - -def perimeter_of_circle(radius): - """This function will calculate perimeter of circle . when you enter radius . - This function will calculate automatically perimeter of circle and give you answer.""" - - perimeter = 2 * 3.14159 * radius - return perimeter - - -def factorial(n): - """This function is used to calculate factorial for you. In class 11 and 12 this operation used . - This function is very useful for students. symbol used in maths for this function is !.""" - - a = 1 - b = 1 - while a <= n: - b *= n - n -= 1 - return b +import voice_work +import pywhatkit +import webbrowser +import wikipedia + +voice_p = voice_work.voice() +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) # password_generator