├── .gitignore
├── Other Files
├── Basics
│ ├── Google GEMINI.py
│ └── HuggingFace MISTRAL.py
├── Model App(s)
│ ├── assistant Gemini.py
│ ├── assistant Mistral.py
│ └── assistant without unwanted GEMINI.py
└── temp.py
├── README.md
├── app.py
└── requirements.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | /.venv
--------------------------------------------------------------------------------
/Other Files/Basics/Google GEMINI.py:
--------------------------------------------------------------------------------
1 | import google.generativeai as genai
2 |
3 | genai.configure(api_key="AIzaSyDGD5HB6mAH-jnAiXTcibvXNMIt7kaz8q4")
4 |
5 | # Set up the model
6 | generation_config = {
7 | "temperature": 0.9,
8 | "top_p": 1,
9 | "top_k": 1,
10 | "max_output_tokens": 2048,
11 | }
12 |
13 | safety_settings = [
14 | {
15 | "category": "HARM_CATEGORY_HARASSMENT",
16 | "threshold": "BLOCK_MEDIUM_AND_ABOVE"
17 | },
18 | {
19 | "category": "HARM_CATEGORY_HATE_SPEECH",
20 | "threshold": "BLOCK_MEDIUM_AND_ABOVE"
21 | },
22 | {
23 | "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
24 | "threshold": "BLOCK_MEDIUM_AND_ABOVE"
25 | },
26 | {
27 | "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
28 | "threshold": "BLOCK_MEDIUM_AND_ABOVE"
29 | }
30 | ]
31 |
32 | model = genai.GenerativeModel(model_name="gemini-pro",
33 | generation_config=generation_config,
34 | safety_settings=safety_settings)
35 |
36 | inp = ''
37 | while inp!='bye':
38 | inp = input('input: ')
39 | print(model.generate_content(inp).text)
--------------------------------------------------------------------------------
/Other Files/Basics/HuggingFace MISTRAL.py:
--------------------------------------------------------------------------------
1 | from huggingface_hub import InferenceClient
2 |
3 | def format_prompt(message, history):
4 | prompt = ""
5 | for user_prompt, bot_response in history:
6 | prompt += f"[INST] {user_prompt} [/INST]"
7 | prompt += f" {bot_response} "
8 | prompt += f"[INST] {message} [/INST]"
9 | return prompt
10 |
11 | def generate(prompt, history, temperature=0.9, max_new_tokens=1024, top_p=0.95, repetition_penalty=1.0):
12 | temperature = float(temperature)
13 | if temperature < 1e-2:
14 | temperature = 1e-2
15 | top_p = float(top_p)
16 |
17 | generate_kwargs = dict(
18 | temperature=temperature,
19 | max_new_tokens=max_new_tokens,
20 | top_p=top_p,
21 | repetition_penalty=repetition_penalty,
22 | do_sample=True,
23 | seed=42,
24 | )
25 |
26 | formatted_prompt = format_prompt(prompt, history)
27 |
28 | client = InferenceClient(model= "mistralai/Mixtral-8x7B-Instruct-v0.1", token='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')
29 | stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
30 | output = ""
31 |
32 | for response in stream:
33 | output += response.token.text
34 |
35 | output = output.replace("", "").replace("", "")
36 |
37 | yield output
38 | return output
39 |
40 |
41 | history = []
42 | while True:
43 | user_input = input("You: ")
44 | if user_input.lower() == "off":
45 | break
46 | history.append((user_input, ""))
47 | for response in generate(user_input, history):
48 | print("Bot:", response)
49 |
--------------------------------------------------------------------------------
/Other Files/Model App(s)/assistant Gemini.py:
--------------------------------------------------------------------------------
1 | import subprocess
2 | import wolframalpha
3 | import pyttsx3
4 | import tkinter
5 | import json
6 | import random
7 | import operator
8 | import speech_recognition as sr
9 | import datetime
10 | import wikipedia
11 | import webbrowser
12 | import os
13 | import winshell
14 | import pyjokes
15 | import feedparser
16 | import smtplib
17 | import ctypes
18 | import time
19 | import requests
20 | import shutil
21 | from twilio.rest import Client
22 | from clint.textui import progress
23 | from ecapture import ecapture as ec
24 | from bs4 import BeautifulSoup
25 | import win32com.client as wincl
26 |
27 | import google.generativeai as genai
28 | import pyautogui
29 |
30 | # Set up the model
31 | genai.configure(api_key="AIzaSyCBXDRml2-v-qT7zzfyq4YqfviSVPcOI6s")
32 | generation_config = {
33 | "temperature": 0.9,
34 | "top_p": 1,
35 | "top_k": 1,
36 | "max_output_tokens": 2048,
37 | }
38 | safety_settings = [
39 | {
40 | "category": "HARM_CATEGORY_HARASSMENT",
41 | "threshold": "BLOCK_MEDIUM_AND_ABOVE"
42 | },
43 | {
44 | "category": "HARM_CATEGORY_HATE_SPEECH",
45 | "threshold": "BLOCK_MEDIUM_AND_ABOVE"
46 | },
47 | {
48 | "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
49 | "threshold": "BLOCK_MEDIUM_AND_ABOVE"
50 | },
51 | {
52 | "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
53 | "threshold": "BLOCK_MEDIUM_AND_ABOVE"
54 | }
55 | ]
56 | model = genai.GenerativeModel(model_name="gemini-pro", generation_config=generation_config, safety_settings=safety_settings)
57 |
58 | def gai(query):
59 | return model.generate_content(query).text
60 |
61 | engine = pyttsx3.init('sapi5')
62 | voices = engine.getProperty('voices')
63 |
64 | def speak(audio):
65 | engine.setProperty('voice', voices[1].id)
66 | engine.say(audio)
67 | engine.runAndWait()
68 |
69 | def wishMe():
70 | hour = int(datetime.datetime.now().hour)
71 | if hour >= 0 and hour < 12:
72 | speak("Good Morning Sir !")
73 | elif hour >= 12 and hour < 18:
74 | speak("Good Afternoon Sir !")
75 | else:
76 | speak("Good Evening Sir !")
77 | assname = "Jarvis 1 point o"
78 | speak("I am your Assistant")
79 | speak(assname)
80 |
81 | def username():
82 | speak("What should i call you sir")
83 | uname = takeCommand()
84 | speak("Welcome Mister")
85 | speak(uname)
86 | columns = shutil.get_terminal_size().columns
87 | print("#####################".center(columns))
88 | print("Welcome Mr.", uname.center(columns))
89 | print("#####################".center(columns))
90 | speak("How can i Help you, Sir")
91 |
92 | def takeCommand():
93 | r = sr.Recognizer()
94 | with sr.Microphone() as source:
95 | print("Listening...")
96 | r.pause_threshold = 1
97 | audio = r.listen(source)
98 | try:
99 | print("Recognizing...")
100 | query = r.recognize_google(audio, language='en-in')
101 | print(f"User said: {query}\n")
102 | except Exception as e:
103 | print(e)
104 | print("Unable to Recognize your voice.")
105 | return "None"
106 | return query
107 |
108 | def sendEmail(to, content):
109 | server = smtplib.SMTP('smtp.gmail.com', 587)
110 | server.starttls()
111 | server.login('your email id', 'your email password')
112 | server.sendmail('your email id', to, content)
113 | server.close()
114 |
115 | if __name__ == '__main__':
116 | clear = lambda: os.system('cls')
117 | clear()
118 | wishMe()
119 | username()
120 |
121 | while True:
122 | query = takeCommand().lower()
123 | if 'open youtube' in query:
124 | speak("Here you go to Youtube\n")
125 | webbrowser.open("youtube.com")
126 | elif 'open google' in query:
127 | speak("Here you go to Google\n")
128 | webbrowser.open("google.com")
129 | elif 'play music' in query or "play song" in query:
130 | speak("Here you go with music")
131 | music_dir = "C:\\Users\\GAURAV\\Music"
132 | songs = os.listdir(music_dir)
133 | random.choice(songs)
134 | os.startfile(os.path.join(music_dir, songs[1]))
135 | elif 'what is the time' in query:
136 | strTime = datetime.datetime.now().strftime("% H:% M:% S")
137 | speak(f"Sir, the time is {strTime}")
138 | elif 'send a mail' in query:
139 | try:
140 | speak("What should I say?")
141 | content = takeCommand()
142 | speak("whome should i send")
143 | to = input()
144 | sendEmail(to, content)
145 | speak("Email has been sent !")
146 | except Exception as e:
147 | print(e)
148 | speak("I am not able to send this email")
149 | elif 'how are you' in query:
150 | speak("I am fine, Thank you")
151 | speak("How are you, Sir")
152 | elif "change my name to" in query:
153 | query = query.replace("change my name to", "")
154 | assname = query
155 | elif "change name" in query:
156 | speak("What would you like to call me, Sir ")
157 | assname = takeCommand()
158 | speak("Thanks for naming me")
159 | elif "what's your name" in query or "What is your name" in query:
160 | speak("My friends call me")
161 | speak(assname)
162 | print("My friends call me", assname)
163 | elif 'exit' in query:
164 | speak("Thanks for giving me your time")
165 | exit()
166 | elif "who made you" in query or "who created you" in query:
167 | speak("I have been created by Nafis Rayan.")
168 | elif 'tell me a joke' in query:
169 | speak(pyjokes.get_joke())
170 | elif 'search' in query or 'play' in query:
171 | query = query.replace("search", "")
172 | query = query.replace("play", "")
173 | webbrowser.open(query)
174 |
175 | elif "search in google" in query:
176 | query = query.replace("search in google", "")
177 | search = query
178 | speak("User asked for google to search")
179 | speak(search)
180 | webbrowser.open("https://www.google.com/search?q=" + search + "")
181 |
182 | elif "don't listen" in query or "stop listening" in query:
183 | speak("for how much time you want to stop jarvis from listening commands")
184 | a = int(takeCommand())
185 | time.sleep(a)
186 | print(a)
187 | elif "where is" in query:
188 | query = query.replace("where is", "")
189 | location = query
190 | speak("User asked to Locate")
191 | speak(location)
192 | webbrowser.open("https://www.google.com/maps/place/" + location + "")
193 |
194 | elif "camera" in query or "take a photo" in query:
195 | ec.capture(0, "Jarvis Camera ", "img.jpg")
196 | elif "take a screenshot" in query:
197 | img = pyautogui.screenshot()
198 | img.save("screenshot.png")
199 | elif "write a note" in query:
200 | speak("What should i write, sir")
201 | note = takeCommand()
202 | file = open('jarvis.txt', 'w')
203 | speak("Sir, Should i include date and time")
204 | snfm = takeCommand()
205 | if 'yes' in snfm or 'sure' in snfm:
206 | strTime = datetime.datetime.now().strftime("% H:% M:% S")
207 | file.write(strTime)
208 | file.write(" :- ")
209 | file.write(note)
210 | else:
211 | file.write(note)
212 | elif "show note" in query:
213 | speak("Showing Notes")
214 | file = open("jarvis.txt", "r")
215 | print(file.read())
216 | speak(file.read(6))
217 | elif "jarvis" in query:
218 | wishMe()
219 | speak("Jarvis 1 point o in your service Mister")
220 | speak(assname)
221 | elif "weather" in query:
222 | query = query.replace("weather","")
223 | # result = weather.weather_report(query)
224 | # speak(result)
225 | print(result)
226 | elif "search in wikipedia" in query:
227 | speak("Searching Wikipedia...")
228 | query = query.replace("search in wikipedia", "")
229 | results = wikipedia.summary(query, sentences = 3)
230 | speak("According to Wikipedia")
231 | speak(results)
232 | # webbrowser.open("wikipedia.com")
233 | elif "how are you" in query:
234 | speak("I'm fine, glad you me that")
235 | elif "i love you" in query:
236 | speak("thank you, smily face")
237 | elif "ask ai" in query:
238 | speak("Got it")
239 | query = query.replace("ask ai", "")
240 | output = gai(query).replace("*", "")
241 | print(output)
242 | speak(output)
243 |
244 |
245 | #-----------------------------------------------Main Code Execution Ends Here ------------------------------------------
246 |
--------------------------------------------------------------------------------
/Other Files/Model App(s)/assistant Mistral.py:
--------------------------------------------------------------------------------
1 | import subprocess
2 | import wolframalpha
3 | import pyttsx3
4 | import tkinter
5 | import json
6 | import random
7 | import operator
8 | import speech_recognition as sr
9 | import datetime
10 | import wikipedia
11 | import webbrowser
12 | import os
13 | import winshell
14 | import pyjokes
15 | import feedparser
16 | import smtplib
17 | import ctypes
18 | import time
19 | import requests
20 | import shutil
21 | from twilio.rest import Client
22 | from clint.textui import progress
23 | from ecapture import ecapture as ec
24 | from bs4 import BeautifulSoup
25 | import win32com.client as wincl
26 | import pyautogui
27 |
28 | # Set up the model
29 | from huggingface_hub import InferenceClient
30 |
31 | def format_prompt(message, history):
32 | prompt = ""
33 | for user_prompt, bot_response in history:
34 | prompt += f"[INST] {user_prompt} [/INST]"
35 | prompt += f" {bot_response} "
36 | prompt += f"[INST] {message} [/INST]"
37 | return prompt
38 |
39 | def generate(prompt, history=[], temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
40 | temperature = float(temperature)
41 | if temperature < 1e-2:
42 | temperature = 1e-2
43 | top_p = float(top_p)
44 |
45 | generate_kwargs = dict(
46 | temperature=temperature,
47 | max_new_tokens=max_new_tokens,
48 | top_p=top_p,
49 | repetition_penalty=repetition_penalty,
50 | do_sample=True,
51 | seed=42,
52 | )
53 |
54 | formatted_prompt = format_prompt(prompt, history)
55 |
56 | client = InferenceClient(model="mistralai/Mixtral-8x7B-Instruct-v0.1", token='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')
57 | stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
58 | output = ""
59 |
60 | for response in stream:
61 | output += response.token.text
62 | output = output.replace("", "").replace("", "")
63 |
64 | yield output
65 | return output
66 |
67 |
68 | def gai(query):
69 | x=''
70 | for response in generate(query):
71 | x+=response
72 | return x
73 |
74 | engine = pyttsx3.init('sapi5')
75 | voices = engine.getProperty('voices')
76 |
77 | def speak(audio):
78 | engine.setProperty('voice', voices[1].id)
79 | engine.say(audio)
80 | engine.runAndWait()
81 |
82 | def wishMe():
83 | hour = int(datetime.datetime.now().hour)
84 | if hour >= 0 and hour < 12:
85 | speak("Good Morning Sir !")
86 | elif hour >= 12 and hour < 18:
87 | speak("Good Afternoon Sir !")
88 | else:
89 | speak("Good Evening Sir !")
90 | assname = "Jarvis 1 point o"
91 | speak("I am your Assistant")
92 | speak(assname)
93 |
94 | def username():
95 | speak("What should i call you sir")
96 | uname = takeCommand()
97 | speak("Welcome Mister")
98 | speak(uname)
99 | columns = shutil.get_terminal_size().columns
100 | print("#####################".center(columns))
101 | print("Welcome Mr.", uname.center(columns))
102 | print("#####################".center(columns))
103 | speak("How can i Help you, Sir")
104 |
105 | def takeCommand():
106 | r = sr.Recognizer()
107 | with sr.Microphone() as source:
108 | print("Listening...")
109 | r.pause_threshold = 1
110 | audio = r.listen(source)
111 | try:
112 | print("Recognizing...")
113 | query = r.recognize_google(audio, language='en-in')
114 | print(f"User said: {query}\n")
115 | except Exception as e:
116 | print(e)
117 | print("Unable to Recognize your voice.")
118 | return "None"
119 | return query
120 |
121 | def sendEmail(to, content):
122 | server = smtplib.SMTP('smtp.gmail.com', 587)
123 | server.starttls()
124 | server.login('your email id', 'your email password')
125 | server.sendmail('your email id', to, content)
126 | server.close()
127 |
128 | if __name__ == '__main__':
129 | clear = lambda: os.system('cls')
130 | clear()
131 | wishMe()
132 | username()
133 |
134 | while True:
135 | query = takeCommand().lower()
136 | if 'open youtube' in query:
137 | speak("Here you go to Youtube\n")
138 | webbrowser.open("youtube.com")
139 | elif 'open google' in query:
140 | speak("Here you go to Google\n")
141 | webbrowser.open("google.com")
142 | elif 'play music' in query or "play song" in query:
143 | speak("Here you go with music")
144 | music_dir = "C:\\Users\\GAURAV\\Music"
145 | songs = os.listdir(music_dir)
146 | random.choice(songs)
147 | os.startfile(os.path.join(music_dir, songs[1]))
148 | elif 'what is the time' in query:
149 | strTime = datetime.datetime.now().strftime("% H:% M:% S")
150 | speak(f"Sir, the time is {strTime}")
151 | elif 'send a mail' in query:
152 | try:
153 | speak("What should I say?")
154 | content = takeCommand()
155 | speak("whome should i send")
156 | to = input()
157 | sendEmail(to, content)
158 | speak("Email has been sent !")
159 | except Exception as e:
160 | print(e)
161 | speak("I am not able to send this email")
162 | elif 'how are you' in query:
163 | speak("I am fine, Thank you")
164 | speak("How are you, Sir")
165 | elif "change my name to" in query:
166 | query = query.replace("change my name to", "")
167 | assname = query
168 | elif "change name" in query:
169 | speak("What would you like to call me, Sir ")
170 | assname = takeCommand()
171 | speak("Thanks for naming me")
172 | elif "what's your name" in query or "What is your name" in query:
173 | speak("My friends call me")
174 | speak(assname)
175 | print("My friends call me", assname)
176 | elif 'exit' in query:
177 | speak("Thanks for giving me your time")
178 | exit()
179 | elif "who made you" in query or "who created you" in query:
180 | speak("I have been created by Nafis Rayan.")
181 | elif 'tell me a joke' in query:
182 | speak(pyjokes.get_joke())
183 | elif 'search' in query or 'play' in query:
184 | query = query.replace("search", "")
185 | query = query.replace("play", "")
186 | webbrowser.open(query)
187 |
188 | elif "search in google" in query:
189 | query = query.replace("search in google", "")
190 | search = query
191 | speak("User asked for google to search")
192 | speak(search)
193 | webbrowser.open("https://www.google.com/search?q=" + search + "")
194 |
195 | elif "don't listen" in query or "stop listening" in query:
196 | speak("for how much time you want to stop jarvis from listening commands")
197 | a = int(takeCommand())
198 | time.sleep(a)
199 | print(a)
200 | elif "where is" in query:
201 | query = query.replace("where is", "")
202 | location = query
203 | speak("User asked to Locate")
204 | speak(location)
205 | webbrowser.open("https://www.google.com/maps/place/" + location + "")
206 |
207 | elif "camera" in query or "take a photo" in query:
208 | ec.capture(0, "Jarvis Camera ", "img.jpg")
209 | elif "take a screenshot" in query:
210 | img = pyautogui.screenshot()
211 | img.save("screenshot.png")
212 | elif "write a note" in query:
213 | speak("What should i write, sir")
214 | note = takeCommand()
215 | file = open('jarvis.txt', 'w')
216 | speak("Sir, Should i include date and time")
217 | snfm = takeCommand()
218 | if 'yes' in snfm or 'sure' in snfm:
219 | strTime = datetime.datetime.now().strftime("% H:% M:% S")
220 | file.write(strTime)
221 | file.write(" :- ")
222 | file.write(note)
223 | else:
224 | file.write(note)
225 | elif "show note" in query:
226 | speak("Showing Notes")
227 | file = open("jarvis.txt", "r")
228 | print(file.read())
229 | speak(file.read(6))
230 | elif "jarvis" in query:
231 | wishMe()
232 | speak("Jarvis 1 point o in your service Mister")
233 | speak(assname)
234 | elif "weather" in query:
235 | query = query.replace("weather","")
236 | # result = weather.weather_report(query)
237 | # speak(result)
238 | print(result)
239 | elif "search in wikipedia" in query:
240 | speak("Searching Wikipedia...")
241 | query = query.replace("search in wikipedia", "")
242 | results = wikipedia.summary(query, sentences = 3)
243 | speak("According to Wikipedia")
244 | speak(results)
245 | # webbrowser.open("wikipedia.com")
246 | elif "how are you" in query:
247 | speak("I'm fine, glad you me that")
248 | elif "i love you" in query:
249 | speak("thank you, smily face")
250 | elif "ask ai" in query:
251 | speak("Got it")
252 | query = query.replace("ask ai", "")
253 | output = gai(query).replace("", "")
254 | print(output)
255 | speak(output)
256 |
257 |
258 | #-----------------------------------------------Main Code Execution Ends Here ------------------------------------------
259 |
--------------------------------------------------------------------------------
/Other Files/Model App(s)/assistant without unwanted GEMINI.py:
--------------------------------------------------------------------------------
1 | import subprocess
2 | import wolframalpha
3 | import pyttsx3
4 | import tkinter
5 | import json
6 | import random
7 | import operator
8 | import speech_recognition as sr
9 | import datetime
10 | import wikipedia
11 | import webbrowser
12 | import os
13 | import winshell
14 | import pyjokes
15 | import feedparser
16 | import smtplib
17 | import ctypes
18 | import time
19 | import requests
20 | import shutil
21 | from twilio.rest import Client
22 | from clint.textui import progress
23 | from ecapture import ecapture as ec
24 | from bs4 import BeautifulSoup
25 | import win32com.client as wincl
26 | import pyautogui
27 |
28 | # Set up the model
29 | from huggingface_hub import InferenceClient
30 |
31 | def format_prompt(message, history):
32 | prompt = ""
33 | for user_prompt, bot_response in history:
34 | prompt += f"[INST] {user_prompt} [/INST]"
35 | prompt += f" {bot_response} "
36 | prompt += f"[INST] {message} [/INST]"
37 | return prompt
38 |
39 | def generate(prompt, history=[], temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
40 | temperature = float(temperature)
41 | if temperature < 1e-2:
42 | temperature = 1e-2
43 | top_p = float(top_p)
44 |
45 | generate_kwargs = dict(
46 | temperature=temperature,
47 | max_new_tokens=max_new_tokens,
48 | top_p=top_p,
49 | repetition_penalty=repetition_penalty,
50 | do_sample=True,
51 | seed=42,
52 | )
53 |
54 | formatted_prompt = format_prompt(prompt, history)
55 |
56 | client = InferenceClient(model="mistralai/Mixtral-8x7B-Instruct-v0.1", token='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')
57 | stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
58 | output = ""
59 |
60 | for response in stream:
61 | output += response.token.text
62 | output = output.replace("", "").replace("", "")
63 |
64 | yield output
65 | return output
66 |
67 |
68 | def gai(query):
69 | x=''
70 | for response in generate(query):
71 | x+=response
72 | return x
73 |
74 | engine = pyttsx3.init('sapi5')
75 | voices = engine.getProperty('voices')
76 |
77 | def speak(audio):
78 | engine.setProperty('voice', voices[1].id)
79 | engine.say(audio)
80 | engine.runAndWait()
81 |
82 | def wishMe():
83 | hour = int(datetime.datetime.now().hour)
84 | if hour >= 0 and hour < 12:
85 | speak("Good Morning Sir !")
86 | elif hour >= 12 and hour < 18:
87 | speak("Good Afternoon Sir !")
88 | else:
89 | speak("Good Evening Sir !")
90 | assname = "Jarvis 1 point o"
91 | speak("I am your Assistant")
92 | speak(assname)
93 |
94 | def takeCommand():
95 | r = sr.Recognizer()
96 | with sr.Microphone() as source:
97 | print("Listening...")
98 | r.pause_threshold = 1
99 | audio = r.listen(source)
100 | try:
101 | print("Recognizing...")
102 | query = r.recognize_google(audio, language='en-in')
103 | print(f"User said: {query}\n")
104 | except Exception as e:
105 | print(e)
106 | print("Unable to Recognize your voice.")
107 | return "None"
108 | return query
109 |
110 | if __name__ == '__main__':
111 | clear = lambda: os.system('cls')
112 | clear()
113 | wishMe()
114 |
115 | while True:
116 | assname = "Jarvis 1 point o"
117 | query = takeCommand().lower()
118 | if 'open youtube' in query:
119 | speak("Here you go to Youtube\n")
120 | webbrowser.open("youtube.com")
121 | elif 'open google' in query:
122 | speak("Here you go to Google\n")
123 | webbrowser.open("google.com")
124 |
125 | elif 'what is the time' in query:
126 | strTime = datetime.datetime.now().strftime("% H:% M:% S")
127 | speak(f"Sir, the time is {strTime}")
128 |
129 | elif 'how are you' in query:
130 | speak("I am fine, Thank you")
131 | speak("How are you, Sir")
132 |
133 | elif "what's your name" in query or "What is your name" in query:
134 | speak("My friends call me")
135 | speak(assname)
136 | print("My friends call me", assname)
137 |
138 | elif 'exit' in query:
139 | speak("Thanks for giving me your time")
140 | exit()
141 |
142 | elif "who made you" in query or "who created you" in query:
143 | speak("I have been created by Nafis Rayan.")
144 |
145 | elif 'search' in query or 'play' in query:
146 | query = query.replace("search", "")
147 | query = query.replace("play", "")
148 | webbrowser.open(query)
149 |
150 | elif "search in google" in query:
151 | query = query.replace("search in google", "")
152 | search = query
153 | speak("User asked for google to search")
154 | speak(search)
155 | webbrowser.open("https://www.google.com/search?q=" + search + "")
156 |
157 | elif "don't listen" in query or "stop listening" in query:
158 | speak("for how much time you want to stop jarvis from listening commands")
159 | a = int(takeCommand())
160 | time.sleep(a)
161 | print(a)
162 | speak("jarvis is now online again")
163 |
164 | elif "where is" in query:
165 | query = query.replace("where is", "")
166 | location = query
167 | speak("User asked to Locate")
168 | speak(location)
169 | webbrowser.open("https://www.google.com/maps/place/" + location + "")
170 |
171 | elif "camera" in query or "take a photo" in query:
172 | ec.capture(0, "Jarvis Camera ", "img.jpg")
173 |
174 | elif "take a screenshot" in query:
175 | img = pyautogui.screenshot()
176 | img.save("screenshot.png")
177 |
178 | elif "jarvis" in query:
179 | wishMe()
180 | speak("Jarvis 1 point o in your service Mister")
181 | speak(assname)
182 |
183 | # elif "weather" in query:
184 | # query = query.replace("weather","")
185 | # # result = weather.weather_report(query)
186 | # # speak(result)
187 | # print(result)
188 |
189 | elif "search in wikipedia" in query:
190 | speak("Searching Wikipedia...")
191 | query = query.replace("search in wikipedia", "")
192 | results = wikipedia.summary(query, sentences = 3)
193 | speak("According to Wikipedia")
194 | speak(results)
195 | # webbrowser.open("wikipedia.com")
196 |
197 | elif "how are you" in query:
198 | speak("I'm fine, glad you me that")
199 |
200 | elif "i love you" in query:
201 | speak("thank you, smily face")
202 |
203 | elif "ask ai" in query:
204 | speak("Got it")
205 | query = query.replace("ask ai", "")
206 | output = gai(query).replace("", "")
207 | print(output)
208 | speak(output)
209 |
210 |
211 | #-----------------------------------------------Main Code Execution Ends Here ------------------------------------------
212 |
--------------------------------------------------------------------------------
/Other Files/temp.py:
--------------------------------------------------------------------------------
1 | import subprocess
2 | import wolframalpha
3 | import pyttsx3
4 | import tkinter
5 | import json
6 | import random
7 | import operator
8 | import speech_recognition as sr
9 | import datetime
10 | import wikipedia
11 | import webbrowser
12 | import os
13 | import winshell
14 | import pyjokes
15 | import feedparser
16 | import smtplib
17 | import ctypes
18 | import time
19 | import requests
20 | import shutil
21 | from twilio.rest import Client
22 | from clint.textui import progress
23 | from ecapture import ecapture as ec
24 | from bs4 import BeautifulSoup
25 | import win32com.client as wincl
26 | import pyautogui
27 |
28 | # Set up the model
29 | from huggingface_hub import InferenceClient
30 |
31 | def format_prompt(message, history):
32 | prompt = ""
33 | for user_prompt, bot_response in history:
34 | prompt += f"[INST] {user_prompt} [/INST]"
35 | prompt += f" {bot_response} "
36 | prompt += f"[INST] {message} [/INST]"
37 | return prompt
38 |
39 | def generate(prompt, history=[], temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
40 | temperature = float(temperature)
41 | if temperature < 1e-2:
42 | temperature = 1e-2
43 | top_p = float(top_p)
44 |
45 | generate_kwargs = dict(
46 | temperature=temperature,
47 | max_new_tokens=max_new_tokens,
48 | top_p=top_p,
49 | repetition_penalty=repetition_penalty,
50 | do_sample=True,
51 | seed=42,
52 | )
53 |
54 | formatted_prompt = format_prompt(prompt, history)
55 |
56 | client = InferenceClient(model="mistralai/Mixtral-8x7B-Instruct-v0.1", token='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')
57 | stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
58 | output = ""
59 |
60 | for response in stream:
61 | output += response.token.text
62 | output = output.replace("", "").replace("", "")
63 |
64 | yield output
65 | return output
66 |
67 |
68 | def gai(query):
69 | x=''
70 | for response in generate(query):
71 | x+=response
72 | return x
73 |
74 | engine = pyttsx3.init('sapi5')
75 | voices = engine.getProperty('voices')
76 |
77 | def speak(audio):
78 | engine.setProperty('voice', voices[1].id)
79 | engine.say(audio)
80 | engine.runAndWait()
81 |
82 | def takeCommand():
83 | r = sr.Recognizer()
84 | with sr.Microphone() as source:
85 | speak("Listening...")
86 | print("Listening...")
87 | r.pause_threshold = 1
88 | audio = r.listen(source)
89 | try:
90 | print("Recognizing...")
91 | query = r.recognize_google(audio, language='en-in')
92 | print(f"User said: {query}\n")
93 | except Exception as e:
94 | print(e)
95 | print("Unable to Recognize your voice.")
96 | return "None"
97 | return query
98 |
99 | if __name__ == '__main__':
100 | clear = lambda: os.system('cls')
101 | clear()
102 |
103 | while True:
104 | assname = "VAU 1 point o"
105 | query = takeCommand().lower()
106 |
107 | if "ask ai" in query:
108 | speak("Got it")
109 | query = query.replace("ask ai", "")
110 | output = gai(query).replace("", "")
111 | print(output)
112 | speak(output)
113 |
114 | #########################################################################################################
115 |
116 | elif "VAU" in query:
117 | speak(f"{assname} in your service Mister")
118 |
119 | elif "how are you" in query:
120 | speak("I'm fine, glad you asked me that")
121 |
122 | elif "i love you" in query:
123 | speak("thank you, smily face")
124 |
125 | elif "who made you" in query or "who created you" in query:
126 | speak("I have been created by Nafis Rayan.")
127 |
128 | elif "what's your name" in query or "What is your name" in query:
129 | speak("My friends call me")
130 | speak(assname)
131 | print("My friends call me", assname)
132 |
133 | #########################################################################################################
134 |
135 | elif "don't listen" in query or "stop listening" in query:
136 | speak("for how much time you want to stop VAU from listening commands")
137 | a = int(takeCommand())
138 | time.sleep(a)
139 | print(a)
140 | speak("VAU is now online again")
141 |
142 | elif 'exit' in query:
143 | speak("Thanks for giving me your time")
144 | exit()
145 |
146 | #########################################################################################################
147 |
148 | elif "search in google" in query:
149 | query = query.replace("search in google", "")
150 | search = query
151 | speak("User asked for google to search")
152 | speak(search)
153 | webbrowser.open("https://www.google.com/search?q=" + search + "")
154 |
155 | elif "search in wikipedia" in query:
156 | speak("Searching Wikipedia...")
157 | query = query.replace("search in wikipedia", "")
158 | results = wikipedia.summary(query, sentences = 3)
159 | speak("According to Wikipedia")
160 | speak(results)
161 | # webbrowser.open("wikipedia.com")
162 |
163 | #########################################################################################################
164 |
165 |
166 | #-----------------------------------------------Main Code Execution Ends Here ------------------------------------------
167 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AI-Voice-Assistant
2 | AI voice assistant made with python and powered by GEMINI and MISTRAL.
3 |
4 | # Virtual Assistant Python Project
5 |
6 | This is a virtual assistant application built in Python that can understand voice commands and complete tasks like opening websites, playing music, telling the time, sending emails, searching Wikipedia, and more.
7 |
8 | ## Features
9 |
10 | - Voice recognition using SpeechRecognition
11 | - Text-to-speech using pyttsx3
12 | - Opening websites like YouTube, Google
13 | - Playing music
14 | - Telling the time
15 | - Sending emails
16 | - Making Google searches
17 | - Telling jokes
18 | - Searching Wikipedia
19 | - Taking screenshots
20 | - Writing notes
21 | - Getting weather information
22 | - Integrated with Google's generative AI models
23 | - Integrated with HuggingFace's Mistral AI model
24 |
25 | ## Requirements
26 |
27 | - python 3.x
28 | - pyaudio
29 | - pyttsx3
30 | - speechRecognition
31 | - wikipedia
32 | - webbrowser
33 | - smtplib
34 | - pyjokes
35 | - datetime
36 | - wolframalpha
37 | - os
38 | - pyautogui
39 | - google.generativeai
40 | - huggingface_hub
41 |
42 | And other common Python libraries listed in requirements.txt
43 |
44 | ## Usage
45 |
46 | Run `python assistant {model_name}.py` to start the virtual assistant. Just run it to activate it. Other example voice commands:
47 |
48 | - "What time is it?"
49 | - "Search YouTube for funny videos"
50 | - "Send an email to nafisrayan123@gmail.com"
51 | - "Take a screenshot"
52 |
53 | See the code comments for full documentation of features.
54 |
55 | ## Contributing
56 |
57 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
--------------------------------------------------------------------------------
/app.py:
--------------------------------------------------------------------------------
1 | import streamlit as st
2 | import speech_recognition as sr
3 | import pyttsx3
4 | import winshell
5 | import google.generativeai as genai
6 | import wikipedia
7 | import webbrowser
8 | import time
9 | from huggingface_hub import InferenceClient
10 |
11 |
12 | # Set the background image
13 | bg_image = """
14 |
20 | """
21 |
22 | st.markdown(bg_image, unsafe_allow_html=True)
23 |
24 | st.title("AI Voice Assistant")
25 |
26 | Model = st.selectbox("Select your prefered model:", ["GEMINI", "MISTRAL8X", "PHI-3", "Custom Models"])
27 |
28 | if Model == "GEMINI":
29 | tkey = st.text_input("Gemenai API key here:", "")
30 |
31 | # Set up the model
32 | generation_config = {
33 | "temperature": 0.9,
34 | "top_p": 1,
35 | "top_k": 1,
36 | "max_output_tokens": 2048,
37 | }
38 |
39 | safety_settings = [
40 | {
41 | "category": "HARM_CATEGORY_HARASSMENT",
42 | "threshold": "BLOCK_MEDIUM_AND_ABOVE",
43 | },
44 | {
45 | "category": "HARM_CATEGORY_HATE_SPEECH",
46 | "threshold": "BLOCK_MEDIUM_AND_ABOVE",
47 | },
48 | {
49 | "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
50 | "threshold": "BLOCK_MEDIUM_AND_ABOVE",
51 | },
52 | {
53 | "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
54 | "threshold": "BLOCK_MEDIUM_AND_ABOVE",
55 | },
56 | ]
57 |
58 | model = genai.GenerativeModel(model_name="gemini-pro",
59 | generation_config=generation_config,
60 | safety_settings=safety_settings)
61 |
62 | genai.configure(api_key=tkey)
63 |
64 | def gai(inp):
65 | return model.generate_content(inp).text
66 |
67 | ################################################################################################################
68 |
69 | else:
70 | tkey = st.text_input("HuggingFace token here:", "")
71 |
72 | if Model == "MISTRAL8X":
73 | mkey= "mistralai/Mixtral-8x7B-Instruct-v0.1"
74 | elif Model == "PHI-3":
75 | mkey = "microsoft/Phi-3-mini-4k-instruct"
76 | else:
77 | mkey = st.text_input("Your HuggingFace Model String here:", "")
78 |
79 | def format_prompt(message, history):
80 | prompt = ""
81 | for user_prompt, bot_response in history:
82 | prompt += f"[INST] {user_prompt} [/INST]"
83 | prompt += f" {bot_response} "
84 | prompt += f"[INST] {message} [/INST]"
85 | return prompt
86 |
87 | def generate(prompt, history=[], temperature=0.9, max_new_tokens=1024, top_p=0.95, repetition_penalty=1.0):
88 | temperature = float(temperature)
89 | if temperature < 1e-2:
90 | temperature = 1e-2
91 | top_p = float(top_p)
92 |
93 | generate_kwargs = dict(
94 | temperature=temperature,
95 | max_new_tokens=max_new_tokens,
96 | top_p=top_p,
97 | repetition_penalty=repetition_penalty,
98 | do_sample=True,
99 | seed=42,
100 | )
101 |
102 | formatted_prompt = format_prompt(prompt, history)
103 |
104 | client = InferenceClient(model= mkey, token=tkey)
105 | stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
106 | output = ""
107 |
108 | for response in stream:
109 | output += response.token.text
110 |
111 | output = output.replace("", "").replace("", "")
112 |
113 | yield output
114 | return output
115 |
116 |
117 | # history = []
118 | # while True:
119 | # user_input = input("You: ")
120 | # if user_input.lower() == "off":
121 | # break
122 | # history.append((user_input, ""))
123 | # for response in generate(user_input, history):
124 | # print("Bot:", response)
125 |
126 | def gai(query):
127 | x=''
128 | for response in generate(query):
129 | x+=response
130 | return x
131 |
132 | ############################################################################################
133 |
134 | show_commands = st.checkbox("Show Available Commands")
135 |
136 | # List of commands
137 | commands = [
138 | '"Ask AI [query]"',
139 | '"VAU in your service Mister"',
140 | '"How are you"',
141 | '"I love you"',
142 | '"Who made you"',
143 | '"What\'s your name"',
144 | '"Search in Google [query]"',
145 | '"Search in Wikipedia [query]"',
146 | '"Don\'t listen"',
147 | '"Exit"'
148 | ]
149 |
150 | # Conditionally display the list of commands based on the checkbox state
151 | if show_commands:
152 | st.header("Available Commands")
153 | st.write(commands)
154 |
155 | ############################################################################################
156 |
157 | def speak(audio):
158 | engine = pyttsx3.init('sapi5')
159 | voices = engine.getProperty('voices')
160 |
161 | engine.setProperty('voice', voices[1].id)
162 | engine.say(audio)
163 | engine.runAndWait()
164 |
165 | # Create a speech recognition object
166 | r = sr.Recognizer()
167 |
168 | # Create a microphone object
169 | mic = sr.Microphone()
170 |
171 | st.write("Click the button and start speaking.")
172 | button = st.button("Start")
173 |
174 | # Define the function to transcribe the speech
175 | def transcribe(audio):
176 | # recognize speech using Google Speech Recognition API
177 | try:
178 | text = r.recognize_google(audio)
179 | return text
180 | except sr.RequestError:
181 | return "API unavailable"
182 | except sr.UnknownValueError:
183 | return "Unable to recognize speech"
184 |
185 | stop_button = st.button("Stop")
186 | # Run the streamlit app
187 | if button and not stop_button:
188 | with mic as source:
189 | # wait for a second to let the user adjust their microphone
190 | st.write("Adjusting microphone...")
191 | r.adjust_for_ambient_noise(source)
192 | st.write("Speak now!")
193 | speak("Speak now!")
194 |
195 | # start recording
196 | audio = r.listen(source)
197 |
198 | # transcribe the audio
199 | text = transcribe(audio)
200 | st.write(f"You said: {text}")
201 |
202 | speak(f"You said: {text}")
203 | speak(f"Give me a second.")
204 |
205 | assname = "VAU 1 point o"
206 | query = text.lower()
207 |
208 |
209 | if "ask ai" in query:
210 | speak("Got it")
211 | query = query.replace("ask ai", "")
212 | reply = gai(query)
213 | print(reply)
214 |
215 | st.write(f"Your reply:\n{reply}")
216 | reply = reply.replace('*','')
217 | speak(f"Your reply: {reply}")
218 |
219 | #########################################################################################################
220 |
221 | elif "VAU" in query:
222 | speak(f"{assname} in your service Mister")
223 | st.write(f"{assname} in your service Mister")
224 |
225 | elif "how are you" in query:
226 | speak("I'm fine, glad you asked me that")
227 | st.write("I'm fine, glad you asked me that")
228 |
229 | elif "i love you" in query:
230 | st.write("thank you, smily face")
231 |
232 |
233 | elif "who made you" in query or "who created you" in query:
234 | speak("I have been made by Nafis Rayan.")
235 | st.write("I have been made by Nafis Rayan.")
236 |
237 | elif "what's your name" in query or "what is your name" in query:
238 | speak("My friends call me")
239 | speak(assname)
240 | print("My friends call me", assname)
241 |
242 | #########################################################################################################
243 |
244 | elif "search in google" in query:
245 | query = query.replace("search in google", "")
246 | search = query
247 | speak("User asked for google to search")
248 | speak(search)
249 | webbrowser.open("https://www.google.com/search?q=" + search + "")
250 |
251 | elif "search in wikipedia" in query:
252 | speak("Searching Wikipedia...")
253 | query = query.replace("search in wikipedia", "")
254 | results = wikipedia.summary(query, sentences = 3)
255 | speak("According to Wikipedia")
256 | speak(results)
257 | # webbrowser.open("wikipedia.com")
258 |
259 | #########################################################################################################
260 |
261 | elif "don't listen" in query or "stop listening" in query:
262 | speak("for how much time you want to stop VAU from listening commands")
263 | audio = r.listen(source)
264 | a = int(transcribe(audio))
265 | time.sleep(a)
266 | print(a)
267 | speak("VAU is now online again")
268 |
269 | elif 'exit' in query:
270 | speak("Thanks for giving me your time")
271 | exit()
272 |
273 | else:
274 | speak("I did not get that, please try again")
275 |
276 | #########################################################################################################
277 |
278 |
279 | #-----------------------------------------------Main Code Execution Ends Here ------------------------------------------
280 |
281 |
282 |
283 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | pyttsx3
2 | pyaudio
3 | speechrecognition
4 | wikipedia
5 | pyjokes
6 | datetime
7 | wolframalpha
8 | PyAutoGUI
9 | google-generativeai
10 | requests
11 | beautifulsoup4
12 | pygame
13 | pywhatkit
14 | PyPDF2
15 | pyinstaller
16 | keyboard
17 | opencv-python
18 | huggingface_hub
19 | streamlit
20 | winshell
21 |
--------------------------------------------------------------------------------