Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GUI, Modularise code, Add new features #13

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Jarvis/GUI_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import customtkinter as ctk
import jarvis_GUI
from jarvis_actions import speak
from listen import listen
#import jarvis


#change between light mode and dark mode
def change_appearence_mode(new_mode):
ctk.set_appearance_mode(new_mode)


#listen for user input (male)
def jarvis_button_click_male():
print("Listening")
speak("Listening", 'M')
listen('M')


#listen for user input (female)
def jarvis_button_click_female():
print("Listening")
speak("Listening", 'F')
listen('F')
Binary file added Jarvis/__pycache__/GUI_commands.cpython-312.pyc
Binary file not shown.
Binary file added Jarvis/__pycache__/evaluate_query.cpython-312.pyc
Binary file not shown.
Binary file added Jarvis/__pycache__/jarvis.cpython-312.pyc
Binary file not shown.
Binary file added Jarvis/__pycache__/jarvis_GUI.cpython-312.pyc
Binary file not shown.
Binary file added Jarvis/__pycache__/jarvis_actions.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file added Jarvis/__pycache__/jarvis_news.cpython-312.pyc
Binary file not shown.
Binary file added Jarvis/__pycache__/listen.cpython-312.pyc
Binary file not shown.
176 changes: 176 additions & 0 deletions Jarvis/evaluate_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#import dependencies
import pyttsx3
import pywin32_system32
import datetime
import speech_recognition as sr
import wikipedia
import webbrowser as wb
import os
import random
import pyautogui

#import jarvis actions
from jarvis_actions import speak
from jarvis_actions import time
from jarvis_actions import date
from jarvis_actions import wishme
from jarvis_actions import screenshot
from jarvis_actions import takecommand

#import newsreader
from jarvis_news import read_headlines

#import email function
from jarvis_email import scan_inbox

#import spotify functionality
from jarvis_spotify import play_song


#####################-functions-#####################
def evaluate_query(query, gender):
print(query)
#if the user mentions the time, report what time it is
if "time" in query:
time()

#if the user mentions the date, report what the date is
elif "date" in query:
date()

#if the user asks for information about the personal assistant, it is provided
elif "who are you" in query:
speak("I'm JARVIS created by Mr. Kishan and I'm a desktop voice assistant.", gender)
print("I'm JARVIS created by Mr. Kishan and I'm a desktop voice assistant.")

#if the user asks the assistant how they are, an appropriate response is given
elif "how are you" in query:
speak("I'm fine sir, What about you?", gender)
print("I'm fine sir, What about you?")

#if the user says that they are fine, then an appropriate response is given
elif "fine" in query:
speak("Glad to hear that sir!!", gender)
print("Glad to hear that sir!!")

#if the user says that they are good, an appropriate response is given
elif "good" in query:
speak("Glad to hear that sir!!", gender)
print("Glad to hear that sir!!")

#if the user wishes to recieve a wikipedia summary
elif "wikipedia" in query:
try:
#feedback to let the user know that the assistant is working on it
speak("Ok wait sir, I'm searching...", gender)

#remove the word wikipedia from the query and produce a result
query = query.replace("wikipedia", "")
result = wikipedia.summary(query, sentences=2)

#output result
print(result)
speak(result, gender)
except:
#if unsuccessful, inform the user
speak("Can't find this page sir, please ask something else", gender)

#open youtube.com in default browser
elif "open youtube" in query:
wb.open("youtube.com")

#open google.com in default browser
elif "open google" in query:
wb.open("google.com")

#open stack overflow in default browser
elif "open stack overflow" in query:
wb.open("stackoverflow.com")

#play music from a playlist
elif "play music" in query:
song_dir = os.path.expanduser("~\\Music")
songs = os.listdir(song_dir)
print(songs)
x = len(songs)
y = random.randint(0, x)
os.startfile(os.path.join(song_dir, songs[y]))

#open the chrome app
elif "open chrome" in query:
#FileNotFoundError causes termination - that is not where chrome is stored on my computer
try:
chromePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
os.startfile(chromePath)

#FileNotFoundError - cannot find chrome in specified location
except FileNotFoundError:
speak("Could not find Chrome on your computer", gender)
print("Could not find Chrome on your computer")

#open a chrome tab with a google search
elif "search on chrome" in query:
try:
speak("What should I search?")
print("What should I search?")
chromePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
search = takecommand()
wb.get(chromePath).open_new_tab(search)
print(search)

##FileNotFoundError - cannot find chrome in specified location
except FileNotFoundError:
speak("Could not find Chrome on your computer", gender)
print("Could not find Chrome on your computer")

except Exception as e:
speak("Can't open now, please try again later.", gender)
print("Can't open now, please try again later.")

#transcribe a note
elif "remember that" in query:
speak("What should I remember", gender)
data = takecommand()
speak("You said me to remember that" + data, gender)
print("You said me to remember that " + str(data))
remember = open("data.txt", "w")
remember.write(data)
remember.close()

#read out transcribed notes
elif "do you remember anything" in query:
remember = open("data.txt", "r")
speak("You told me to remember that" + remember.read(), gender)
print("You told me to remember that " + str(remember))

#perform a screesnhsot
elif "screenshot" in query:
screenshot()
speak("I've taken screenshot, please check it", gender)

#read headlines
elif "headline" in query:
read_headlines(gender)

elif "headline" not in query:
if "news" in query:
read_headlines(gender)

#read emails
elif "email" in query:
scan_inbox(gender)

#play song on spotify
elif "spotify" in query:
print("What song would you like to play?")
speak("What song would you like to play?", gender)

song = takecommand()
print("Playing", song)
speak(f"Playing {song}", gender)

play_song(song)

#end the program
elif "offline" in query:
quit()
180 changes: 10 additions & 170 deletions Jarvis/jarvis.py
Original file line number Diff line number Diff line change
@@ -1,175 +1,15 @@
import pyttsx3
import pywin32_system32
import datetime
import speech_recognition as sr
import wikipedia
import webbrowser as wb
import os
import random
import pyautogui
#import jarvis wishme action
from jarvis_actions import wishme

engine = pyttsx3.init()


def speak(audio):
engine.say(audio)
engine.runAndWait()


def time():
Time = datetime.datetime.now().strftime("%I:%M:%S")
speak("the current time is")
speak(Time)
print("The current time is ", Time)


def date():
day = int(datetime.datetime.now().day)
month = int(datetime.datetime.now().month)
year = int(datetime.datetime.now().year)
speak("the current date is")
speak(day)
speak(month)
speak(year)
print("The current date is " + str(day) + "/" + str(month) + "/" + str(year))


def wishme():
print("Welcome back sir!!")
speak("Welcome back sir!!")

hour = datetime.datetime.now().hour
if 4 <= hour < 12:
speak("Good Morning Sir!!")
print("Good Morning Sir!!")
elif 12 <= hour < 16:
speak("Good Afternoon Sir!!")
print("Good Afternoon Sir!!")
elif 16 <= hour < 24:
speak("Good Evening Sir!!")
print("Good Evening Sir!!")
else:
speak("Good Night Sir, See You Tommorrow")

speak("Jarvis at your service sir, please tell me how may I help you.")
print("Jarvis at your service sir, please tell me how may I help you.")


def screenshot():
img = pyautogui.screenshot()
img_path = os.path.expanduser("~\\Pictures\\ss.png")
img.save(img_path)


def takecommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)

try:
print("Recognizing...")
query = r.recognize_google(audio, language="en-in")
print(query)

except Exception as e:
print(e)
speak("Please say that again")
return "Try Again"

return query
#import jarvis gui
import jarvis_GUI


#start program
if __name__ == "__main__":
wishme()
while True:
query = takecommand().lower()
if "time" in query:
time()

elif "date" in query:
date()

elif "who are you" in query:
speak("I'm JARVIS created by Mr. Kishan and I'm a desktop voice assistant.")
print("I'm JARVIS created by Mr. Kishan and I'm a desktop voice assistant.")

elif "how are you" in query:
speak("I'm fine sir, What about you?")
print("I'm fine sir, What about you?")

elif "fine" in query:
speak("Glad to hear that sir!!")
print("Glad to hear that sir!!")

elif "good" in query:
speak("Glad to hear that sir!!")
print("Glad to hear that sir!!")

elif "wikipedia" in query:
try:
speak("Ok wait sir, I'm searching...")
query = query.replace("wikipedia", "")
result = wikipedia.summary(query, sentences=2)
print(result)
speak(result)
except:
speak("Can't find this page sir, please ask something else")

elif "open youtube" in query:
wb.open("youtube.com")

elif "open google" in query:
wb.open("google.com")

elif "open stack overflow" in query:
wb.open("stackoverflow.com")

elif "play music" in query:
song_dir = os.path.expanduser("~\\Music")
songs = os.listdir(song_dir)
print(songs)
x = len(songs)
y = random.randint(0, x)
os.startfile(os.path.join(song_dir, songs[y]))

elif "open chrome" in query:
chromePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
os.startfile(chromePath)

elif "search on chrome" in query:
try:
speak("What should I search?")
print("What should I search?")
chromePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
search = takecommand()
wb.get(chromePath).open_new_tab(search)
print(search)

except Exception as e:
speak("Can't open now, please try again later.")
print("Can't open now, please try again later.")


elif "remember that" in query:
speak("What should I remember")
data = takecommand()
speak("You said me to remember that" + data)
print("You said me to remember that " + str(data))
remember = open("data.txt", "w")
remember.write(data)
remember.close()

elif "do you remember anything" in query:
remember = open("data.txt", "r")
speak("You told me to remember that" + remember.read())
print("You told me to remember that " + str(remember))

elif "screenshot" in query:
screenshot()
speak("I've taken screenshot, please check it")

#greet user
#wishme()

elif "offline" in query:
quit()
#instantiate and launch gui window
app = jarvis_GUI.App()
app.mainloop()
Loading