├── Untitled-1.py ├── application_tasks.py ├── chromedriver.exe ├── data.pth ├── data_analyzer.py ├── data_new.pth ├── json_dataset.json ├── json_dataset_new.json ├── pre_analyse.py ├── recognize_speech.py ├── recognize_speech_2.py ├── tasks.py ├── tasks_backup.py ├── temp.json ├── tkinter_test.ipynb └── yes_no.pth /Untitled-1.py: -------------------------------------------------------------------------------- 1 | import tasks 2 | import time 3 | 4 | tasks.search_google("hello") 5 | 6 | 7 | while True: 8 | time.sleep(10) 9 | pass -------------------------------------------------------------------------------- /application_tasks.py: -------------------------------------------------------------------------------- 1 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 2 | from selenium.webdriver.common.action_chains import ActionChains 3 | from selenium.webdriver.chrome.options import Options 4 | from selenium.webdriver.common.keys import Keys 5 | from selenium.webdriver.common.by import By 6 | from pynput.keyboard import Key, Listener 7 | from selenium import webdriver 8 | from threading import Thread 9 | import subprocess 10 | import pyautogui 11 | import pyttsx3 12 | import time 13 | 14 | def speak(content,slow = False , voice = 1): 15 | 16 | engine = pyttsx3.init() 17 | if slow == True: 18 | rate = engine.getProperty('rate') 19 | engine.setProperty('rate', 150) 20 | voices = engine.getProperty('voices') 21 | engine.setProperty('voice', voices[voice].id) 22 | 23 | engine.say(content) 24 | engine.runAndWait() 25 | 26 | class file_explorer: 27 | 28 | def new_folder(self): 29 | pyautogui.hotkey('ctrl','shift','n') 30 | 31 | def file_rename(self): 32 | pyautogui.press('f2') 33 | 34 | 35 | 36 | class chrome: 37 | global driver 38 | def __init__(self): 39 | global driver 40 | chrome_options = webdriver.ChromeOptions(); 41 | chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']) 42 | capabilities = DesiredCapabilities.CHROME 43 | capabilities["goog:loggingPrefs"] = {"performance": "ALL"} 44 | driver = webdriver.Chrome(r"./chromedriver",desired_capabilities=capabilities,options=chrome_options) 45 | 46 | def search(self,url): 47 | driver.get(url = url) 48 | def maximize(self): 49 | driver.maximize_window() 50 | class youtube: 51 | def play_video_by_count(self,value): 52 | try: 53 | if value == 1: 54 | video = driver.find_element(By.XPATH,"/html/body/ytd-app/div[1]/ytd-page-manager/ytd-browse/ytd-two-column-browse-results-renderer/div[1]/ytd-rich-grid-renderer/div[6]/ytd-rich-grid-row[1]/div/ytd-rich-item-renderer[1]/div/ytd-rich-grid-media/div[1]/ytd-thumbnail/a/yt-image/img") 55 | video.click() 56 | elif value == 2: 57 | video = driver.find_element(By.XPATH,"/html/body/ytd-app/div[1]/ytd-page-manager/ytd-browse/ytd-two-column-browse-results-renderer/div[1]/ytd-rich-grid-renderer/div[6]/ytd-rich-grid-row[1]/div/ytd-rich-item-renderer[2]/div/ytd-rich-grid-media/div[1]/ytd-thumbnail/a/yt-image/img") 58 | video.click() 59 | elif value == 3: 60 | video = driver.find_element(By.XPATH,"/html/body/ytd-app/div[1]/ytd-page-manager/ytd-browse/ytd-two-column-browse-results-renderer/div[1]/ytd-rich-grid-renderer/div[6]/ytd-rich-grid-row[1]/div/ytd-rich-item-renderer[3]/div/ytd-rich-grid-media/div[1]/ytd-thumbnail/a/yt-image/img") 61 | video.click() 62 | elif value == 4: 63 | video = driver.find_element(By.XPATH,"/html/body/ytd-app/div[1]/ytd-page-manager/ytd-browse/ytd-two-column-browse-results-renderer/div[1]/ytd-rich-grid-renderer/div[6]/ytd-rich-grid-row[1]/div/ytd-rich-item-renderer[4]/div/ytd-rich-grid-media/div[1]/ytd-thumbnail/a/yt-image/img") 64 | video.click() 65 | speak("playing the video") 66 | except: 67 | print("error while clicking video") 68 | 69 | def play_pause(self): 70 | try: 71 | ActionChains(driver).send_keys('k').perform() 72 | except: 73 | speak("sorry there was an error while pausing the video") 74 | 75 | def next_video(self): 76 | pyautogui.hotkey('shift','n') 77 | speak("playing next video") 78 | 79 | def previous_video(self): 80 | pyautogui.hotkey('altleft','left') 81 | speak("going to previous page") 82 | 83 | def like_video(self): 84 | try: 85 | like = driver.find_element(By.XPATH,'//*[@id="segmented-like-button"]/ytd-toggle-button-renderer/yt-button-shape/button/yt-touch-feedback-shape/div/div[2]') 86 | like.click() 87 | speak("liked the video") 88 | except Exception as e: 89 | print(e) 90 | 91 | def dislike_video(self): 92 | try: 93 | dislike = driver.find_element(By.XPATH,'//*[@id="segmented-dislike-button"]/ytd-toggle-button-renderer/yt-button-shape/button/yt-touch-feedback-shape/div/div[2]') 94 | dislike.click() 95 | speak("disliked the video") 96 | except Exception as e: 97 | print(e) 98 | 99 | def share_video(self): 100 | pass 101 | 102 | def subscribe(self): 103 | try: 104 | sub = driver.find_element(By.XPATH,'//*[@id="subscribe-button"]/ytd-subscribe-button-renderer/yt-button-shape/button/yt-touch-feedback-shape/div/div[2]') 105 | sub.click() 106 | speak("subscribed") 107 | except Exception as e: 108 | print(e) 109 | 110 | def unsubscribe(self): 111 | try: 112 | unsub = driver.find_element(By.XPATH,'//*[@id="subscribe-button"]/ytd-subscribe-button-renderer/yt-button-shape/button/yt-touch-feedback-shape/div/div[2]') 113 | unsub.click() 114 | speak("unsubscribed") 115 | except Exception as e: 116 | print(e) 117 | 118 | def turn_on_notification(self): 119 | pass 120 | def save_to_watchlater(self): 121 | pass 122 | def report_video(self): 123 | pass 124 | 125 | class gmail: 126 | def write_mail(self): 127 | pass 128 | def open_first_mail(self): 129 | pass 130 | def reply(self): 131 | pass 132 | def forward_mail(self): 133 | pass 134 | def delete_mail(self): 135 | pass 136 | 137 | 138 | -------------------------------------------------------------------------------- /chromedriver.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dewadharshan/Virtual-Assistant/d9b15b898aa9e4ff9182dd4fb1691befdb0b8c5a/chromedriver.exe -------------------------------------------------------------------------------- /data.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dewadharshan/Virtual-Assistant/d9b15b898aa9e4ff9182dd4fb1691befdb0b8c5a/data.pth -------------------------------------------------------------------------------- /data_analyzer.py: -------------------------------------------------------------------------------- 1 | import nltk 2 | from nltk.stem.porter import PorterStemmer 3 | import json 4 | import numpy as np 5 | import torch 6 | import torch.nn as nn 7 | from torch.utils.data import Dataset,DataLoader 8 | 9 | 10 | def tokenize(sentence): 11 | print("sentence",sentence,type(sentence)) 12 | return nltk.word_tokenize(sentence['text']) 13 | 14 | def stem(word): 15 | return stemmer.stem(word) 16 | 17 | def bag_of_words(tokenized_sentence,all_words): 18 | bag = np.zeros(len(all_words),dtype=np.float32) 19 | for idx,w in enumerate(all_words): 20 | if w in tokenized_sentence: 21 | bag[idx] = 1.0 22 | return bag 23 | 24 | 25 | class neuralnet(nn.Module): 26 | 27 | def __init__(self,input_size,hidden_size,num_classes): 28 | super(neuralnet, self).__init__() 29 | self.l1 = nn.Linear(input_size, hidden_size) 30 | self.l2 = nn.Linear(hidden_size, hidden_size) 31 | self.l3 = nn.Linear(hidden_size, num_classes) 32 | self.relu = nn.ReLU() 33 | 34 | def forward(self, x): 35 | out = self.l1(x) 36 | out = self.relu(out) 37 | out = self.l2(out) 38 | out = self.relu(out) 39 | out = self.l3(out) 40 | return out 41 | 42 | 43 | 44 | stemmer = PorterStemmer() 45 | FILE = 'D:\\mini_project\\model_creating\\data_new.pth' 46 | data = torch.load(FILE) 47 | 48 | input_size = data["input_size"] 49 | hidden_size = data["hidden_size"] 50 | output_size = data["output_size"] 51 | all_words = data['all_words'] 52 | tags = data['tags'] 53 | model_state = data["model_state"] 54 | 55 | device = torch.device('cpu' if torch.cuda.is_available() else 'cpu') 56 | model = neuralnet(input_size, hidden_size, output_size).to(device) 57 | model.load_state_dict(model_state) 58 | model.eval() 59 | 60 | with open("json_dataset_new.json",'r') as file: 61 | intents = json.load(file) 62 | 63 | 64 | 65 | def analyze_command(sentence): 66 | 67 | sentence = tokenize(sentence) 68 | 69 | for i,word in enumerate(sentence): 70 | sentence[i] = stem(word) 71 | print(sentence) 72 | 73 | X = bag_of_words(sentence, all_words) 74 | X = X.reshape(1,X.shape[0]) 75 | X = torch.from_numpy(X) 76 | 77 | output = model(X) 78 | 79 | _, predicted = torch.max(output,dim=1) 80 | prob_softmax = torch.softmax(output, dim=1) 81 | prob = prob_softmax[0][predicted.item()] 82 | print('final prob = ',prob.item()) 83 | tag = tags[predicted.item()] 84 | 85 | for intent in intents['intents']: 86 | if tag == intent['description']: 87 | print(intent['description']) 88 | print("function",intent['functions']) 89 | print("function",prob.item()) 90 | if prob.item() >= 0.95: 91 | 92 | return intent['functions'] 93 | else: 94 | print("can't find command") 95 | return None 96 | -------------------------------------------------------------------------------- /data_new.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dewadharshan/Virtual-Assistant/d9b15b898aa9e4ff9182dd4fb1691befdb0b8c5a/data_new.pth -------------------------------------------------------------------------------- /json_dataset.json: -------------------------------------------------------------------------------- 1 | { 2 | "intents": [ 3 | { 4 | "description": "stop the process", 5 | "patterns": [ 6 | "stop", 7 | "stop now", 8 | "stop the process", 9 | "stop speaking", 10 | "stop yelling", 11 | "enough", 12 | "ok stop", 13 | "okay stop" 14 | ], 15 | "functions": null 16 | }, 17 | { 18 | "description": "volume increase", 19 | "patterns": [ 20 | "volume up", 21 | "increase the volume", 22 | "increase volume", 23 | "raise the volume", 24 | "set the volume to" 25 | ], 26 | "functions": "volume(1)" 27 | }, 28 | { 29 | "description": "volume decrease", 30 | "patterns": [ 31 | "volume down", 32 | "decrease the volume", 33 | "reduce the volume", 34 | "lower the volume", 35 | "set the volume to" 36 | ], 37 | "functions": "volume(0)" 38 | }, 39 | { 40 | "description": "brightness increase", 41 | "patterns": [ 42 | "brightness up", 43 | "increase the brightness", 44 | "increase brightness", 45 | "raise the brightness", 46 | "set the brightness to" 47 | ], 48 | "functions": null 49 | }, 50 | { 51 | "description": "brightness decrease", 52 | "patterns": [ 53 | "brightness down", 54 | "decrease the brightness", 55 | "reduce the brightness", 56 | "lower the brightness", 57 | "set the brightness to" 58 | ], 59 | "functions": null 60 | }, 61 | { 62 | "description": "mute the volume", 63 | "patterns": [ 64 | "mute the volume", 65 | "mute volume", 66 | "volume mute", 67 | "mute the sound", 68 | "muting the volume" 69 | ], 70 | "functions": "mute_volume()" 71 | }, 72 | { 73 | "description": "keep as sleep mode", 74 | "patterns": [ 75 | "sleep", 76 | "put the computer to sleep", 77 | "turn on sleep", 78 | "sleep the computer", 79 | "put the laptop to sleep" 80 | ], 81 | "functions": "sleep_computer()" 82 | }, 83 | { 84 | "description": "shut down", 85 | "patterns": [ 86 | "shutdown", 87 | "shutdown the computer", 88 | "shutdown yourself", 89 | "turn off yourself", 90 | "turn off", 91 | "shutdoen the laptop" 92 | ], 93 | "functions": "shutdown_computer()" 94 | }, 95 | { 96 | "description": "restart", 97 | "patterns": [ 98 | "restart", 99 | "restart the computer", 100 | "restart yourself", 101 | "restart the laptop", 102 | "put computer to restart" 103 | ], 104 | "functions": "restart_computer()" 105 | }, 106 | { 107 | "description": "keep as hibernate", 108 | "patterns": [ 109 | "hibernate", 110 | "hibernate the computer", 111 | "hibernate the laptop" 112 | ], 113 | "functions": "hibernate_computer()" 114 | }, 115 | { 116 | "description": "turn on wifi", 117 | "patterns": [ 118 | "turn on the wifi", 119 | "turn on wifi", 120 | "wifi on" 121 | ], 122 | "functions": "wifi_on_and_off(1)" 123 | }, 124 | { 125 | "description": "turn off wifi", 126 | "patterns": [ 127 | "turn off the wifi", 128 | "turn off wifi", 129 | "wifi off" 130 | ], 131 | "functions": "wifi_on_and_off(0)" 132 | }, 133 | { 134 | "description": "turn on hotspot", 135 | "patterns": [ 136 | "turn on the hotspot", 137 | "turn on mobile hotspot", 138 | "on mobile hotspot", 139 | "on hotspot", 140 | "hotspot on" 141 | ], 142 | "functions": "mobile_hotspot(1)" 143 | }, 144 | { 145 | "description": "turn off hotspot", 146 | "patterns": [ 147 | "turn off the hotspot", 148 | "turn off mobile hotspot", 149 | "off mobile hotspot", 150 | "off hotspot", 151 | "hotspot off" 152 | ], 153 | "functions": "mobile_hotspot(0)" 154 | }, 155 | { 156 | "description": "turn on Bluetooth", 157 | "patterns": [ 158 | "turn on the bluetooth", 159 | "turn on mobile bluetooth", 160 | "on mobile bluetooth", 161 | "on bluetooth", 162 | "bluetooth on" 163 | ], 164 | "functions": "bluetooth(1)" 165 | }, 166 | { 167 | "description": "turn off Bluetooth", 168 | "patterns": [ 169 | "turn off the bluetooth", 170 | "turn off mobile bluetooth", 171 | "off mobile bluetooth", 172 | "off bluetooth", 173 | "bluetooth off" 174 | ], 175 | "functions": "bluetooth(0)" 176 | }, 177 | { 178 | "description": "minimising", 179 | "patterns": [ 180 | "minimise", 181 | "minimize", 182 | "minimize the window", 183 | "minimise the tab", 184 | "minimize the current window" 185 | ], 186 | "functions": null 187 | }, 188 | { 189 | "description": "minimise all tab", 190 | "patterns": [ 191 | "minimize all window", 192 | "minimize all the tab", 193 | "minimize all the window", 194 | "all window minimize", 195 | "minimise all window", 196 | "minimise all the tab", 197 | "minimise all the window", 198 | "all window minimise" 199 | ], 200 | "functions": "show_desktop()" 201 | }, 202 | { 203 | "description": "maximising", 204 | "patterns": [ 205 | "maximize", 206 | "maximize the window", 207 | "maximize current the window", 208 | "maximize the tab", 209 | "minimize the current window" 210 | ], 211 | "functions": null 212 | }, 213 | 214 | { 215 | "description": "refresh", 216 | "patterns": [ 217 | "refresh", 218 | "refresh the page", 219 | "refresh the window", 220 | "reload", 221 | "reload the page", 222 | "reload the window", 223 | "refresh page", 224 | "reload page" 225 | ], 226 | "functions": "refresh()" 227 | }, 228 | { 229 | "description": "close the current tab", 230 | "patterns": [ 231 | "close the current tab", 232 | "close current tab", 233 | "close current", 234 | "close this tab" 235 | ], 236 | "functions": "close_current_tab()" 237 | }, 238 | { 239 | "description": "scroll down", 240 | "patterns": [ 241 | "scroll", 242 | "scroll down", 243 | "down scroll", 244 | "scroll that down" 245 | ], 246 | "functions": "scroll_down()" 247 | }, 248 | { 249 | "description": "scroll up", 250 | "patterns": [ 251 | "scroll up", 252 | "scroll that up", 253 | "up scroll" 254 | ], 255 | "functions": "scroll_up()" 256 | }, 257 | { 258 | "description": "zoom in", 259 | "patterns": [ 260 | "zoom", 261 | "zoom in", 262 | "zoom that in" 263 | ], 264 | "functions": "zoom_in()" 265 | }, 266 | { 267 | "description": "zoom out", 268 | "patterns": [ 269 | "zoom out", 270 | "zoom that out", 271 | "zoom out that" 272 | ], 273 | "functions": "zoom_out()" 274 | }, 275 | { 276 | "description": "take a photo", 277 | "patterns": [ 278 | "take a photo", 279 | "take me a photo", 280 | "take a photo of that", 281 | "capture that", 282 | "capture me" 283 | ], 284 | "functions": "take_photo()" 285 | }, 286 | { 287 | "description": "record video", 288 | "patterns": [ 289 | "record", 290 | "record this ", 291 | "take a video", 292 | "record me as a video", 293 | "record this as video", 294 | "capture a video" 295 | ], 296 | "functions": "record_video()" 297 | }, 298 | { 299 | "description": "weather", 300 | "patterns": [ 301 | ], 302 | "functions": null 303 | }, 304 | { 305 | "description": "turn on batterysaver", 306 | "patterns": [ 307 | "turn on battery saver", 308 | "battery saver", 309 | "battery saver on" 310 | ], 311 | "functions": "battery_saver(1)" 312 | }, 313 | { 314 | "description": "turn off batterysaver", 315 | "patterns": [ 316 | "turn off battery saver", 317 | "off the battery saver", 318 | "battery saver off" 319 | ], 320 | "functions": "battery_saver(0)" 321 | }, 322 | { 323 | "description": "turn on performance", 324 | "patterns": [ 325 | "turn on performance mode", 326 | "on performance mode", 327 | "turn on performance" 328 | ], 329 | "functions": null 330 | }, 331 | { 332 | "description": "turn off performance", 333 | "patterns": [ 334 | "turn off performance mode", 335 | "off performance mode", 336 | "turn off performance" 337 | ], 338 | "functions": null 339 | }, 340 | { 341 | "description": "screenshot", 342 | "patterns": [ 343 | "take a screenshot", 344 | "capture the screen", 345 | "screenshot", 346 | "screenshot this" 347 | ], 348 | "functions": "take_screenshot()" 349 | }, 350 | { 351 | "description": "screen record", 352 | "patterns": [ 353 | "record the screen", 354 | "record screen", 355 | "screen record" 356 | ], 357 | "functions": null 358 | }, 359 | { 360 | "description": "undo/come backward", 361 | "patterns": [ 362 | "undo", 363 | "undo that", 364 | "comeback", 365 | "okay comeback", 366 | "okay undo that", 367 | "stop undo that" 368 | ], 369 | "functions": "undo()" 370 | }, 371 | { 372 | "description": "redo/come frontwaed", 373 | "patterns": [ 374 | "redo", 375 | "redo that" 376 | ], 377 | "functions": "redo()" 378 | }, 379 | { 380 | "description": "time", 381 | "patterns": [ 382 | "what is the time now", 383 | "tell me the time", 384 | "what the time", 385 | "time" 386 | ], 387 | "functions": "get_date_and_time(time=True)" 388 | }, 389 | { 390 | "description": "date", 391 | "patterns": [ 392 | "what is today's date", 393 | "tell me the date", 394 | "date" 395 | ], 396 | "functions": "get_date_and_time(date=True)" 397 | }, 398 | { 399 | "description": "time and date", 400 | "patterns": [ 401 | "what is the time and date", 402 | "time and date", 403 | "time and date today", 404 | "what is the date and time now", 405 | "what is the date and time " 406 | ], 407 | "functions": "get_date_and_time(date_time=True)" 408 | }, 409 | { 410 | "description": "turn on darkmode", 411 | "patterns": [ 412 | ], 413 | "functions": null 414 | }, 415 | { 416 | "description": "turn off darkmode", 417 | "patterns": [ 418 | ], 419 | "functions": null 420 | }, 421 | { 422 | "description": "turn on airplane mode", 423 | "patterns": [ 424 | "turn on airplane mode", 425 | "airplane mode", 426 | "airoplane mode", 427 | "airplane mode on", 428 | "airoplane mode on" 429 | ], 430 | "functions": "airplane_mode(1)" 431 | }, 432 | { 433 | "description": "turn off airplane mode", 434 | "patterns": [ 435 | "turn off airplane mode", 436 | "airplane mode off", 437 | "airoplane mode off" 438 | ], 439 | "functions": "airplane_mode(0)" 440 | }, 441 | { 442 | "description": "turn on location", 443 | "patterns": [ 444 | ], 445 | "functions": null 446 | }, 447 | { 448 | "description": "turn off", 449 | "patterns": [ 450 | ], 451 | "functions": null 452 | }, 453 | { 454 | "description": "new folder", 455 | "patterns": [ 456 | ], 457 | "functions": null 458 | }, 459 | { 460 | "description": "come to desktop", 461 | "patterns": [ 462 | "come to the desktop", 463 | "desktop", 464 | "show desktop", 465 | "peek to desktop", 466 | "peak to tesktop" 467 | ], 468 | "functions": "show_desktop()" 469 | }, 470 | { 471 | "description": "right click", 472 | "patterns": [ 473 | "right click", 474 | "click right button on the mouse", 475 | "click right button", 476 | "click on the right key" 477 | ], 478 | "functions": "mouse_right_click()" 479 | }, 480 | { 481 | "description": "left click", 482 | "patterns": [ 483 | "left click", 484 | "click left button on the mouse", 485 | "click left button", 486 | "click on the left key" 487 | ], 488 | "functions": "mouse_left_click()" 489 | }, 490 | { 491 | "description": "turn on microphone", 492 | "patterns": [ 493 | ], 494 | "functions": null 495 | }, 496 | { 497 | "description": "introduction", 498 | "patterns": [ 499 | "ok introduce yourself", 500 | "hey introduce yourself", 501 | "introduce yourself", 502 | "hello introduce yourself", 503 | "introduce you", 504 | "give intro of you" 505 | ], 506 | "functions": "introduction()" 507 | }, 508 | { 509 | "description": "open chrome", 510 | "patterns": [ 511 | "open chrome", 512 | "open google chrome", 513 | "google chrome" 514 | ], 515 | "functions": "open_chrome()" 516 | }, 517 | { 518 | "description": "open youtube", 519 | "patterns": [ 520 | "open youtube", 521 | "go to youtube", 522 | "proceed to youtube", 523 | "go to youtube com" 524 | ], 525 | "functions": "open_youtube()" 526 | }, 527 | { 528 | "description": "click first video", 529 | "patterns": [ 530 | "click on the first video", 531 | "first video", 532 | "open the first video", 533 | "go to first video", 534 | "1" 535 | ], 536 | "functions": "play_video_by_count(1)" 537 | }, 538 | { 539 | "description": "click_second_video", 540 | "patterns": [ 541 | "click on the second video", 542 | "second video", 543 | "open the second video", 544 | "go to second video", 545 | "2" 546 | ], 547 | "functions": "play_video_by_count(2)" 548 | }, 549 | { 550 | "description": "click_third_video", 551 | "patterns": [ 552 | "click on the third video", 553 | "third video", 554 | "open the third video", 555 | "go to third video", 556 | "3" 557 | ], 558 | "functions": "play_video_by_count(3)" 559 | }, 560 | { 561 | "description": "click_fourth_video", 562 | "patterns": [ 563 | "click on the fourth video", 564 | "fourth video", 565 | "open the fourth video", 566 | "go to fourth video", 567 | "4" 568 | ], 569 | "functions": "play_video_by_count(4)" 570 | }, 571 | { 572 | "description": "pause/play", 573 | "patterns": [ 574 | "ok pause", 575 | "pause the video", 576 | "play video", 577 | "play" 578 | ], 579 | "functions": "pause_play()" 580 | }, 581 | { 582 | "description": "login to tel", 583 | "patterns": [ 584 | "login to my college website", 585 | "login to my tel curricula", 586 | "login to my college portal", 587 | "go to my college portal" 588 | ], 589 | "functions": "login_to_tel()" 590 | } 591 | ] 592 | 593 | } -------------------------------------------------------------------------------- /json_dataset_new.json: -------------------------------------------------------------------------------- 1 | { 2 | "intents": [ 3 | { 4 | "description": "greeting", 5 | "patterns": [ 6 | "hello how are you", 7 | "hi voice assistant", 8 | "hello", 9 | "hi", 10 | "hey" 11 | ], 12 | "functions": "greeting()" 13 | }, 14 | { 15 | "description": "stop the process", 16 | "patterns": [ 17 | "stop", 18 | "stop now", 19 | "stop the process", 20 | "stop speaking", 21 | "stop yelling", 22 | "enough", 23 | "ok stop", 24 | "okay stop" 25 | ], 26 | "functions": null 27 | }, 28 | { 29 | "description": "volume increase", 30 | "patterns": [ 31 | "volume up", 32 | "increase the volume", 33 | "increase volume", 34 | "raise the volume" 35 | ], 36 | "functions": "volume(1)" 37 | }, 38 | { 39 | "description": "volume decrease", 40 | "patterns": [ 41 | "volume down", 42 | "decrease the volume", 43 | "reduce the volume", 44 | "lower the volume" 45 | ], 46 | "functions": "volume(0)" 47 | }, 48 | { 49 | "description": "brightness increase", 50 | "patterns": [ 51 | "brightness up", 52 | "increase the brightness", 53 | "increase brightness", 54 | "raise the brightness", 55 | "set the brightness to" 56 | ], 57 | "functions": "brightness(1)" 58 | }, 59 | { 60 | "description": "brightness decrease", 61 | "patterns": [ 62 | "brightness down", 63 | "decrease the brightness", 64 | "reduce the brightness", 65 | "lower the brightness", 66 | "set the brightness to" 67 | ], 68 | "functions": "brightness(0)" 69 | }, 70 | { 71 | "description": "mute the volume", 72 | "patterns": [ 73 | "mute the volume", 74 | "mute volume", 75 | "volume mute", 76 | "mute the sound", 77 | "muting the volume" 78 | ], 79 | "functions": "mute_volume()" 80 | }, 81 | { 82 | "description": "keep as sleep mode", 83 | "patterns": [ 84 | "sleep", 85 | "put the computer to sleep", 86 | "turn on sleep", 87 | "sleep the computer", 88 | "put the laptop to sleep" 89 | ], 90 | "functions": "sleep_computer()" 91 | }, 92 | { 93 | "description": "shut down", 94 | "patterns": [ 95 | "shutdown", 96 | "shutdown the computer", 97 | "shutdown yourself", 98 | "turn off yourself", 99 | "shutdown the laptop" 100 | ], 101 | "functions": "shutdown_computer()" 102 | }, 103 | { 104 | "description": "restart", 105 | "patterns": [ 106 | "restart", 107 | "restart the computer", 108 | "restart yourself", 109 | "restart the laptop", 110 | "put computer to restart" 111 | ], 112 | "functions": "restart_computer()" 113 | }, 114 | { 115 | "description": "keep as hibernate", 116 | "patterns": [ 117 | "hibernate", 118 | "hibernate the computer", 119 | "hibernate the laptop" 120 | ], 121 | "functions": "hibernate_computer()" 122 | }, 123 | { 124 | "description": "turn on wifi", 125 | "patterns": [ 126 | "turn on the wifi", 127 | "turn on wifi", 128 | "wifi on" 129 | ], 130 | "functions": "wifi_on_and_off(1)" 131 | }, 132 | { 133 | "description": "turn off wifi", 134 | "patterns": [ 135 | "turn off the wifi", 136 | "turn off wifi", 137 | "wifi off" 138 | ], 139 | "functions": "wifi_on_and_off(0)" 140 | }, 141 | { 142 | "description": "turn on hotspot", 143 | "patterns": [ 144 | "turn on the hotspot", 145 | "turn on mobile hotspot", 146 | "on mobile hotspot", 147 | "on hotspot" 148 | ], 149 | "functions": "mobile_hotspot(1)" 150 | }, 151 | { 152 | "description": "turn off hotspot", 153 | "patterns": [ 154 | "turn off the hotspot", 155 | "turn off mobile hotspot", 156 | "off mobile hotspot", 157 | "off hotspot" 158 | ], 159 | "functions": "mobile_hotspot(0)" 160 | }, 161 | { 162 | "description": "turn on Bluetooth", 163 | "patterns": [ 164 | "turn on the bluetooth", 165 | "turn on mobile bluetooth", 166 | "on mobile bluetooth", 167 | "on bluetooth", 168 | "bluetooth on" 169 | ], 170 | "functions": "bluetooth(1)" 171 | }, 172 | { 173 | "description": "turn off Bluetooth", 174 | "patterns": [ 175 | "turn off the bluetooth", 176 | "turn off mobile bluetooth", 177 | "off mobile bluetooth", 178 | "off bluetooth", 179 | "bluetooth off" 180 | ], 181 | "functions": "bluetooth(0)" 182 | }, 183 | { 184 | "description": "minimise all tab", 185 | "patterns": [ 186 | "minimize", 187 | "minimize window", 188 | "minimize all the tab", 189 | "minimize all the window", 190 | "all window minimize", 191 | "minimise all window", 192 | "minimise all the tab", 193 | "minimise all the window", 194 | "all window minimise" 195 | ], 196 | "functions": "show_desktop()" 197 | }, 198 | { 199 | "description": "maximising", 200 | "patterns": [ 201 | "maximize", 202 | "maximize the window", 203 | "maximize current the window", 204 | "maximize the tab", 205 | "maximize the current window" 206 | ], 207 | "functions": "maximize()" 208 | }, 209 | 210 | { 211 | "description": "refresh", 212 | "patterns": [ 213 | "refresh", 214 | "refresh the page", 215 | "refresh the window", 216 | "reload", 217 | "reload the page", 218 | "reload the window", 219 | "refresh page", 220 | "reload page" 221 | ], 222 | "functions": "refresh()" 223 | }, 224 | { 225 | "description": "close the current tab", 226 | "patterns": [ 227 | "close the current tab", 228 | "close current tab", 229 | "close current", 230 | "close this tab", 231 | "close the window" 232 | ], 233 | "functions": "close_current_tab()" 234 | }, 235 | { 236 | "description": "scroll down", 237 | "patterns": [ 238 | "scroll", 239 | "scroll down", 240 | "down scroll", 241 | "scroll that down" 242 | ], 243 | "functions": "scroll_down()" 244 | }, 245 | { 246 | "description": "scroll up", 247 | "patterns": [ 248 | "scroll up", 249 | "scroll that up", 250 | "up scroll" 251 | ], 252 | "functions": "scroll_up()" 253 | }, 254 | { 255 | "description": "zoom in", 256 | "patterns": [ 257 | "zoom", 258 | "zoom in", 259 | "zoom that in" 260 | ], 261 | "functions": "zoom_in()" 262 | }, 263 | { 264 | "description": "zoom out", 265 | "patterns": [ 266 | "zoom out", 267 | "zoom that out", 268 | "zoom out that" 269 | ], 270 | "functions": "zoom_out()" 271 | }, 272 | { 273 | "description": "take a photo", 274 | "patterns": [ 275 | "take a photo", 276 | "take me a photo", 277 | "take a photo of that", 278 | "capture that", 279 | "capture me" 280 | ], 281 | "functions": "take_photo()" 282 | }, 283 | { 284 | "description": "record video", 285 | "patterns": [ 286 | "record", 287 | "record this ", 288 | "take a video", 289 | "record me as a video", 290 | "record this as video", 291 | "capture a video" 292 | ], 293 | "functions": "record_video()" 294 | }, 295 | { 296 | "description": "weather", 297 | "patterns": [ 298 | "tell about the weather", 299 | "how is the weather now", 300 | "how was the wheather", 301 | "open weather data", 302 | "what is the weather now" 303 | ], 304 | "functions": "weather()" 305 | }, 306 | { 307 | "description": "turn on batterysaver", 308 | "patterns": [ 309 | "turn on battery saver", 310 | "battery saver", 311 | "turn on the batterysaver", 312 | "battery saver on" 313 | ], 314 | "functions": "battery_saver(1)" 315 | }, 316 | { 317 | "description": "turn off batterysaver", 318 | "patterns": [ 319 | "turn off battery saver", 320 | "off the battery saver", 321 | "turn off the batterysaver", 322 | "battery saver off" 323 | ], 324 | "functions": "battery_saver(0)" 325 | }, 326 | { 327 | "description": "screenshot", 328 | "patterns": [ 329 | "take a screenshot", 330 | "capture the screen", 331 | "screenshot", 332 | "screenshot this" 333 | ], 334 | "functions": "take_screenshot()" 335 | }, 336 | { 337 | "description": "screen record", 338 | "patterns": [ 339 | "record the screen", 340 | "record screen", 341 | "screen record", 342 | "start screen recording", 343 | "stop screen recording" 344 | ], 345 | "functions": "screen_record()" 346 | }, 347 | { 348 | "description": "undo/come backward", 349 | "patterns": [ 350 | "undo", 351 | "undo that", 352 | "comeback", 353 | "okay comeback", 354 | "okay undo that", 355 | "stop undo that" 356 | ], 357 | "functions": "undo()" 358 | }, 359 | { 360 | "description": "redo/come frontwaed", 361 | "patterns": [ 362 | "redo", 363 | "redo that" 364 | ], 365 | "functions": "redo()" 366 | }, 367 | { 368 | "description": "time", 369 | "patterns": [ 370 | "what is the time now", 371 | "tell me the time", 372 | "what the time", 373 | "what is the current time", 374 | "time" 375 | ], 376 | "functions": "get_date_and_time(time=True)" 377 | }, 378 | { 379 | "description": "date", 380 | "patterns": [ 381 | "what is today's date", 382 | "tell me the date", 383 | "what is todays date", 384 | "date" 385 | ], 386 | "functions": "get_date_and_time(date=True)" 387 | }, 388 | { 389 | "description": "time and date", 390 | "patterns": [ 391 | "what is the time and date", 392 | "time and date", 393 | "time and date today", 394 | "what is the date and time now", 395 | "what is the date and time " 396 | ], 397 | "functions": "get_date_and_time(date_time=True)" 398 | }, 399 | { 400 | "description": "turn on airplane mode", 401 | "patterns": [ 402 | "turn on airplane mode", 403 | "airplane mode", 404 | "airoplane mode", 405 | "airplane mode on", 406 | "airoplane mode on" 407 | ], 408 | "functions": "airplane_mode(1)" 409 | }, 410 | { 411 | "description": "turn off airplane mode", 412 | "patterns": [ 413 | "turn off airplane mode", 414 | "airplane mode off", 415 | "airoplane mode off" 416 | ], 417 | "functions": "airplane_mode(0)" 418 | }, 419 | { 420 | "description": "turn on location", 421 | "patterns": [ 422 | "turn off location", 423 | "location off", 424 | "location on" 425 | ], 426 | "functions": "location()" 427 | }, 428 | { 429 | "description": "come to desktop", 430 | "patterns": [ 431 | "come to the desktop", 432 | "desktop", 433 | "show desktop", 434 | "peek to desktop", 435 | "peak to tesktop" 436 | ], 437 | "functions": "show_desktop()" 438 | }, 439 | { 440 | "description": "right click", 441 | "patterns": [ 442 | "right click", 443 | "click right button on the mouse", 444 | "click right button", 445 | "click on the right key" 446 | ], 447 | "functions": "mouse_right_click()" 448 | }, 449 | { 450 | "description": "left click", 451 | "patterns": [ 452 | "left click", 453 | "click left button on the mouse", 454 | "click left button", 455 | "click on the left key" 456 | ], 457 | "functions": "mouse_left_click()" 458 | }, 459 | 460 | { 461 | "description": "introduction", 462 | "patterns": [ 463 | "ok introduce yourself", 464 | "hey introduce yourself", 465 | "introduce yourself", 466 | "introduce yourself", 467 | "introduce you", 468 | "introduce", 469 | "introduction", 470 | "give intro of you" 471 | ], 472 | "functions": "introduction()" 473 | }, 474 | { 475 | "description": "open chrome", 476 | "patterns": [ 477 | "open chrome", 478 | "open google chrome", 479 | "google chrome" 480 | ], 481 | "functions": "open_chrome()" 482 | }, 483 | { 484 | "description": "open youtube", 485 | "patterns": [ 486 | "open youtube", 487 | "go to youtube", 488 | "proceed to youtube", 489 | "go to youtube com" 490 | ], 491 | "functions": "open_youtube()" 492 | }, 493 | { 494 | "description": "click first video", 495 | "patterns": [ 496 | "play the first video", 497 | "click on the first video", 498 | "first video", 499 | "open the first video", 500 | "go to first video", 501 | "1" 502 | ], 503 | "functions": "play_video_by_count(1)" 504 | }, 505 | { 506 | "description": "click_second_video", 507 | "patterns": [ 508 | "play the second video", 509 | "click on the second video", 510 | "second video", 511 | "open the second video", 512 | "go to second video", 513 | "2" 514 | ], 515 | "functions": "play_video_by_count(2)" 516 | }, 517 | { 518 | "description": "click_third_video", 519 | "patterns": [ 520 | "play the third video", 521 | "click on the third video", 522 | "third video", 523 | "open the third video", 524 | "go to third video", 525 | "3" 526 | ], 527 | "functions": "play_video_by_count(3)" 528 | }, 529 | { 530 | "description": "click_fourth_video", 531 | "patterns": [ 532 | "play the fourth video", 533 | "click on the fourth video", 534 | "fourth video", 535 | "open the fourth video", 536 | "go to fourth video", 537 | "4" 538 | ], 539 | "functions": "play_video_by_count(4)" 540 | }, 541 | { 542 | "description": "pause/play", 543 | "patterns": [ 544 | "ok pause", 545 | "pause the video", 546 | "play video", 547 | "play" 548 | ], 549 | "functions": "pause_play()" 550 | }, 551 | { 552 | "description": "login to tel", 553 | "patterns": [ 554 | "login to my college website", 555 | "login to my tel curricula", 556 | "login to my college portal", 557 | "go to my college portal", 558 | "open my college website" 559 | ], 560 | "functions": "login_to_tel()" 561 | }, 562 | { 563 | "description": "news", 564 | "patterns": [ 565 | "what is the current news", 566 | "show me some news", 567 | "get me some news", 568 | "what is the current trend", 569 | "what is the current affairs", 570 | "show some current affairs" 571 | ], 572 | "functions": "get_news()" 573 | }, 574 | { 575 | "description": "take notes", 576 | "patterns": [ 577 | "take note", 578 | "take a note", 579 | "type what I say", 580 | "take some notes", 581 | "note what I am saying", 582 | "note down" 583 | ], 584 | "functions": "take_notes()" 585 | } 586 | 587 | ] 588 | 589 | } -------------------------------------------------------------------------------- /pre_analyse.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | def pre_analyse_command(sentence): 4 | sentence = sentence.lower() 5 | if "open" in sentence: 6 | index = sentence.find('open') 7 | application = sentence[index+4:] 8 | if len(application) < 4: 9 | return None 10 | else: 11 | return 'open_application("'+application+'")' 12 | 13 | elif ("click on" in sentence or "clickon" in sentence) and 'video' not in sentence: 14 | index = sentence.find('on') 15 | click_word = sentence[index+2:] 16 | if len(click_word) < 3: 17 | return None 18 | else: 19 | return 'find_text_on_screen("'+click_word+'")' 20 | 21 | elif ("select" in sentence) and 'video' not in sentence: 22 | index = sentence.find('select') 23 | click_word = sentence[index+6:] 24 | if len(click_word) < 3: 25 | return None 26 | else: 27 | return 'find_text_on_screen("'+click_word+'")' 28 | 29 | elif 'search' in sentence: 30 | index = sentence.find('search') 31 | search_text = sentence[index+6:] 32 | if len(search_text) < 4: 33 | return None 34 | else: 35 | return 'search_google("'+search_text+'")' -------------------------------------------------------------------------------- /recognize_speech.py: -------------------------------------------------------------------------------- 1 | from pydub.silence import split_on_silence 2 | import speech_recognition as sr 3 | from pydub import AudioSegment 4 | import whisper 5 | import tempfile 6 | import torch 7 | import numpy as np 8 | import time 9 | import whisper 10 | import threading 11 | import keyboard 12 | import data_analyzer 13 | import tasks 14 | import os 15 | import io 16 | 17 | 18 | whisper_model = whisper.load_model('small.en') 19 | listening_status = "None" 20 | transcribed_text = "" 21 | 22 | def speech_to_text(): 23 | 24 | r = sr.Recognizer() 25 | global listening_status 26 | listening_status = "None" 27 | 28 | def callback(recognizer,audio): 29 | global listening_status 30 | global transcribed_text 31 | 32 | stop_listening(wait_for_stop=False) 33 | listening_status = "processing" 34 | print("processing") 35 | save_path = "D:\\mini_project\\model_creating\\audio_listen_in_background.mp3" 36 | data = io.BytesIO(audio.get_wav_data()) 37 | audio_clip = AudioSegment.from_file(data) 38 | audio_clip.export(save_path, format="mp3") 39 | #start_time = time.time() 40 | #sound = AudioSegment.from_file(save_path, format = "mp3") 41 | 42 | #audio_chunks = split_on_silence(sound 43 | # ,min_silence_len = 100 44 | # ,silence_thresh = -45 45 | # ,keep_silence = 50 46 | # ) 47 | #combined = AudioSegment.empty() 48 | #for chunk in audio_chunks: 49 | # combined += chunk 50 | 51 | #combined.export(save_path, format = "mp3") 52 | transcribed_text = whisper_model.transcribe(save_path,language = "en") 53 | #transcribed_text['text'] = "what is the time now" 54 | #print(time.time()-start_time) 55 | listening_status = "completed" 56 | 57 | 58 | 59 | def stop_listen(): 60 | global listening_status 61 | while True: 62 | key_input = keyboard.read_key() 63 | if key_input == "alt": 64 | stop_listening(wait_for_stop=False) 65 | listening_status = "interrupted" 66 | break 67 | 68 | 69 | 70 | 71 | 72 | 73 | print("started") 74 | m = sr.Microphone() 75 | with m as source: 76 | r.adjust_for_ambient_noise(source) 77 | 78 | while True: 79 | key_input = None 80 | key_input = keyboard.read_key() 81 | if key_input == 'ctrl': 82 | listening_status = "listening" 83 | print("listening") 84 | stop_listening = r.listen_in_background(m,callback) 85 | stop_listen_thread = threading.Thread(target=stop_listen) 86 | stop_listen_thread.daemon = True 87 | stop_listen_thread.start() 88 | break 89 | 90 | 91 | while True: 92 | if listening_status == "completed" or listening_status == "interrupted": 93 | return transcribed_text 94 | 95 | time.sleep(1) 96 | 97 | print("listening stopped") 98 | 99 | while True: 100 | 101 | transcribed_text = speech_to_text() 102 | print(transcribed_text['text']) 103 | 104 | 105 | command = data_analyzer.analyze_command(transcribed_text) 106 | print("command = ",command) 107 | if command != None: 108 | exec("tasks."+command) 109 | tasks.speak("command executed") 110 | 111 | -------------------------------------------------------------------------------- /recognize_speech_2.py: -------------------------------------------------------------------------------- 1 | from pydub.silence import split_on_silence 2 | import speech_recognition as sr 3 | from pydub import AudioSegment 4 | import tkinter as tk 5 | import pyautogui 6 | import whisper 7 | import tempfile 8 | import torch 9 | import numpy as np 10 | import pre_analyse 11 | import time 12 | import threading 13 | import keyboard 14 | import data_analyzer 15 | import tasks 16 | import os 17 | import io 18 | 19 | listening_status = "None" 20 | transcribed_text = {} 21 | 22 | def speech_to_text(initiate): 23 | 24 | if initiate: 25 | window.lift() 26 | time.sleep(0.1) 27 | pyautogui.moveTo(20,1050) 28 | pyautogui.click() 29 | 30 | pyautogui.hotkey('win','h') 31 | 32 | text = text_entry.get() 33 | 34 | transcribed_text = {"text":text} 35 | 36 | return transcribed_text 37 | 38 | def reset(): 39 | text_entry.delete(0,"end") 40 | pyautogui.press('esc') 41 | 42 | 43 | def execute_command(): 44 | global is_listening 45 | print("started") 46 | while True: 47 | key_input = None 48 | key_input = keyboard.read_key() 49 | 50 | print("------------iteration----------") 51 | 52 | if key_input == 'ctrl': 53 | if not is_listening: 54 | is_listening = True 55 | speech_to_text(initiate = True) 56 | while is_listening: 57 | 58 | transcribed_text = speech_to_text(initiate=False) 59 | print("transcribed_text",transcribed_text['text']) 60 | 61 | pre_analyse_command = data_analyzer.analyze_command(transcribed_text) 62 | print("data analyse command",pre_analyse_command) 63 | if pre_analyse_command != None: 64 | command = pre_analyse_command 65 | 66 | else: 67 | command = pre_analyse.pre_analyse_command(transcribed_text['text']) 68 | 69 | print("command = ",command) 70 | if command != None: 71 | reset() 72 | is_listening = False 73 | exec("tasks."+command) 74 | #tasks.speak("command executed") 75 | 76 | 77 | time.sleep(0.5) 78 | 79 | 80 | 81 | 82 | 83 | def monitor(): 84 | global is_listening 85 | while True: 86 | key_input = None 87 | key_input = keyboard.read_key() 88 | if key_input == 'alt': 89 | is_listening = False 90 | reset() 91 | 92 | 93 | 94 | window = tk.Tk() 95 | window.geometry(f"{400}x{30}+{0}+{1040}") 96 | window.attributes('-topmost', True) 97 | window.overrideredirect(True) 98 | window.configure(bg="#202020") 99 | window.geometry("400x150") 100 | 101 | 102 | text_entry = tk.Entry(window,width=300,font=("Helvetica", 15),bg='#202020',fg='white') 103 | text_entry.grid(row=0, column=0) 104 | 105 | is_listening = False 106 | 107 | 108 | command_execution_thread = threading.Thread(target=execute_command) 109 | command_execution_thread.start() 110 | monitor_execution_thread = threading.Thread(target=monitor) 111 | monitor_execution_thread.start() 112 | 113 | window.mainloop() 114 | 115 | 116 | -------------------------------------------------------------------------------- /tasks.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | import comtypes 4 | import subprocess 5 | import time 6 | from datetime import datetime 7 | import cv2 8 | import PIL.Image 9 | import pyautogui 10 | import pytesseract 11 | import pyttsx3 12 | import threading 13 | from PIL import Image, ImageOps, ImageEnhance 14 | from bs4 import BeautifulSoup 15 | import spacy 16 | from gtts import gTTS 17 | from openpyxl import Workbook, load_workbook 18 | from pynput.keyboard import Controller, Key 19 | from pytesseract import Output 20 | import AppOpener 21 | import requests 22 | import application_tasks 23 | from bs4 import BeautifulSoup 24 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 25 | from selenium.webdriver.common.action_chains import ActionChains 26 | from selenium.webdriver.chrome.options import Options 27 | from selenium.webdriver.common.keys import Keys 28 | from selenium.webdriver.common.by import By 29 | from pynput.keyboard import Key, Listener 30 | from selenium import webdriver 31 | 32 | pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe' 33 | global nlp 34 | driver = "temp" 35 | #nlp = spacy.load("en_core_web_lg") 36 | def speak_2(content,slow = False , voice = 1, needed_thread = True): 37 | print(content) 38 | try: 39 | def speak_thread(): 40 | engine = pyttsx3.init() 41 | if slow == True: 42 | rate = engine.getProperty('rate') 43 | engine.setProperty('rate', 150) 44 | voices = engine.getProperty('voices') 45 | engine.setProperty('voice', voices[voice].id) 46 | 47 | engine.say(content) 48 | engine.runAndWait() 49 | if needed_thread: 50 | thread = threading.Thread(target=speak_thread) 51 | thread.start() 52 | else: 53 | speak_thread() 54 | except: 55 | print("error while speaking") 56 | 57 | 58 | def speak(content, slow=False, voice=1, needed_thread=True): 59 | def speak_thread(): 60 | # Initialize COM 61 | comtypes.CoInitialize() 62 | try: 63 | engine = pyttsx3.init() 64 | if slow: 65 | rate = engine.getProperty('rate') 66 | engine.setProperty('rate', 150) 67 | voices = engine.getProperty('voices') 68 | engine.setProperty('voice', voices[voice].id) 69 | 70 | engine.say(content) 71 | engine.runAndWait() 72 | except: 73 | print("some error BS") 74 | 75 | finally: 76 | # Uninitialize COM 77 | comtypes.CoUninitialize() 78 | 79 | if needed_thread: 80 | thread = threading.Thread(target=speak_thread) 81 | thread.start() 82 | else: 83 | speak_thread() 84 | 85 | 86 | 87 | def speak_google(content, slow = False): 88 | 89 | audio = myobj = gTTS(text=content, lang='en', slow=slow) 90 | audio.save("D:\\mini_project\\temp\\welcome.mp3") 91 | from playsound import playsound 92 | playsound('D:\\mini_project\\temp\\welcome.mp3') 93 | os.remove('D:\\mini_project\\temp\\welcome.mp3') 94 | 95 | def open_application(app, speak_needed = True): 96 | 97 | if True: 98 | open_app = None 99 | open_app_arr = [] 100 | dict1 = dict() 101 | temp = "" 102 | tot_application = AppOpener.give_appnames() 103 | #print(tot_application) 104 | for i in tot_application: 105 | if app.strip() == i: 106 | open_app = i 107 | break 108 | elif app.strip() in i: 109 | open_app_arr.append(i) 110 | 111 | if open_app_arr != [] and len(open_app_arr) >1: 112 | print(open_app_arr) 113 | speak("which one do you want to open") 114 | for i in open_app_arr: 115 | temp += i+" " 116 | speak(temp) 117 | app = input() #needs to be changed to voice input 118 | for i in open_app_arr: 119 | dict1[i] = nlp(i).similarity(nlp(app)) 120 | print(dict1) 121 | index_app = list(dict1.values()).index(max(dict1.values())) 122 | 123 | if list(dict1.values())[index_app] >=0.5: 124 | open_app = open_app_arr[index_app] 125 | 126 | 127 | 128 | elif len(open_app_arr) == 1: 129 | open_app = open_app_arr[0] 130 | 131 | 132 | if open_app != None: 133 | if speak_needed: 134 | speak("opening"+open_app) 135 | AppOpener.open(open_app) 136 | else: 137 | speak("sorry ! "+app+" is not installed") 138 | print("not installed") 139 | 140 | def find_text_on_screen(text): 141 | 142 | def invert_image_if_needed(image): 143 | avg_color = ImageOps.exif_transpose(image).convert("RGB").resize((1, 1)).getpixel((0, 0)) 144 | is_dark_background = sum(avg_color) / 3 < 128 145 | 146 | if is_dark_background: 147 | inverted_image = ImageOps.invert(image) 148 | else: 149 | inverted_image = image 150 | 151 | inverted_image = inverted_image.convert("L") 152 | 153 | enhancer = ImageEnhance.Contrast(inverted_image) 154 | enhanced_image = enhancer.enhance(1.2) 155 | 156 | return enhanced_image 157 | 158 | 159 | 160 | 161 | text = text.lower().strip() 162 | myscreenshot=pyautogui.screenshot() 163 | inverted_image = invert_image_if_needed(myscreenshot) 164 | inverted_image.save(r"D:\\mini_project\\temp\\screenshot.png") 165 | 166 | data = pytesseract.image_to_data(PIL.Image.open("D:\\mini_project\\temp\\screenshot.png"),output_type = Output.DICT) 167 | 168 | for i,value in enumerate(data['text']): 169 | data['text'][i] = data['text'][i].lower() 170 | 171 | with open("temp.json",'w') as f: 172 | f.write(json.dumps(data)) 173 | try: 174 | x,y,width,height = data['left'][data['text'].index(text)], data['top'][data['text'].index(text)], data['width'][data['text'].index(text)], data['height'][data['text'].index(text)] 175 | pyautogui.moveTo(x+width/2, y+height/2) 176 | pyautogui.click() 177 | speak("clicking "+text) 178 | print(x+width/2,y+height/2) 179 | except: 180 | print("cannot find",text,"on the screen") 181 | speak("Sorry. Cannot find",text,"on the screen") 182 | return str("cannot find"+text+"on the screen") , False 183 | 184 | def wifi_on_and_off(value): 185 | 186 | if value == 1: 187 | MyWish = subprocess.run (['netsh', 'interface', 'set', 'interface', "wi-fi", "ENABLED"]) 188 | speak ("The wifi has been turned on") 189 | elif value == 0: 190 | MyWish = subprocess.run (['netsh', 'interface', 'set', 'interface', "wi-fi", "DISABLED"]) 191 | speak( "The wifi has been turned off") 192 | else: 193 | return "sorry ! some error occured during the process" 194 | 195 | def wifi_connect(): 196 | pyautogui.moveTo(1766,1047) 197 | pyautogui.click() 198 | time.sleep(0.5) 199 | pyautogui.moveTo(1573,454) 200 | pyautogui.click() 201 | network_name = 'student' 202 | temp = 10 203 | while temp: 204 | try: 205 | for i in range(0,10): 206 | x,y = find_text_on_screen(network_name) 207 | if y != False: 208 | break 209 | 210 | if y != False: 211 | pyautogui.moveTo(x,y) 212 | pyautogui.click() 213 | time.sleep(0.8) 214 | for i in range(0,5): 215 | x,y = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\wifi_connect.png',confidence = 0.9) 216 | if x != None: 217 | break 218 | pyautogui.moveTo(x,y) 219 | pyautogui.click() 220 | else: 221 | print('cannot find the network') 222 | break 223 | except: 224 | temp-=1 225 | 226 | def pause_play(): 227 | pyautogui.press("playpause") 228 | 229 | def mute_volume(): 230 | keyboard = Controller() 231 | try: 232 | speak("The volume has been muted",needed_thread=False) 233 | keyboard.press(Key.media_volume_mute) 234 | except: 235 | speak("Sorry ! there was a problem while muting the volume") 236 | time.sleep(0.1) 237 | 238 | def sleep_computer(): 239 | speak("turning computer to sleep") 240 | try: 241 | os.system('cmd /c "powercfg -H off" ') 242 | os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0") 243 | 244 | except: 245 | speak("sorry ! there was a problem while turning the computer to sleep") 246 | 247 | def hibernate_computer(): 248 | speak("turning computer to hibernate") 249 | try: 250 | os.system('cmd /c "powercfg -H on" ') 251 | os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0") 252 | 253 | except: 254 | speak("sorry ! there was a problem while turning the computer to hibernate") 255 | 256 | def shutdown_computer(): 257 | speak('do you want to shutdown your computer') 258 | response = input() 259 | if "yes" in response: 260 | speak('shutting down the computer') 261 | try: 262 | os.system("shutdown /s /t 1") 263 | except: 264 | speak('sorry ! there was a problem while shutting down the computer') 265 | else: 266 | speak('ok exitting from shutdown ') 267 | 268 | def restart_computer(): 269 | speak('do you want to restart your computer') 270 | response = input() 271 | if "yes" in response: 272 | speak('restarting the computer') 273 | try: 274 | os.system("shutdown /r /t 1") 275 | except: 276 | speak('sorry ! there was a problem while restarting the computer') 277 | else: 278 | speak('ok exitting from restart ') 279 | 280 | def take_photo(): 281 | AppOpener.open("camera") 282 | speak("ready ?",needed_thread=False) 283 | pyautogui.moveTo(960,540) 284 | pyautogui.click() 285 | speak("say chheeeeeese",slow = 1,needed_thread=False) 286 | pyautogui.press("space") 287 | 288 | def record_video(): 289 | cap= cv2.VideoCapture(0) 290 | 291 | width= int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) 292 | height= int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) 293 | writer= cv2.VideoWriter('D:\\mini_project\\files_by_assistant\\recoded_video_.mp4', cv2.VideoWriter_fourcc(*'DIVX'), 20, (width,height)) 294 | 295 | 296 | while True: 297 | ret,frame= cap.read() 298 | 299 | writer.write(frame) 300 | 301 | cv2.imshow('frame', frame) 302 | 303 | if cv2.waitKey(1) & 0xFF == 27: 304 | break 305 | 306 | 307 | cap.release() 308 | writer.release() 309 | cv2.destroyAllWindows() 310 | 311 | def scroll_down(): 312 | pyautogui.moveTo(960,540) 313 | for i in range(20): 314 | pyautogui.scroll(-30) 315 | 316 | def scroll_up(): 317 | pyautogui.moveTo(960,540) 318 | for i in range(20): 319 | pyautogui.scroll(30) 320 | 321 | def zoom_in(): 322 | pyautogui.hotkey('alt','tab') 323 | for i in range(0,3): 324 | pyautogui.hotkey('ctrl','+') 325 | 326 | def zoom_out(): 327 | pyautogui.hotkey('alt','tab') 328 | for i in range(0,3): 329 | pyautogui.hotkey('ctrl','-') 330 | 331 | def refresh(): 332 | pyautogui.hotkey('alt','tab') 333 | pyautogui.press('f5') 334 | pyautogui.hotkey('ctrl','r') 335 | 336 | def take_screenshot(): 337 | 338 | pyautogui.hotkey('win','printscreen') 339 | speak("done") 340 | 341 | def screen_record(): 342 | pyautogui.keyDown('win') 343 | pyautogui.keyDown('alt') 344 | pyautogui.keyDown('r') 345 | 346 | pyautogui.keyUp('r') 347 | pyautogui.keyUp('alt') 348 | pyautogui.keyUp('win') 349 | speak("screen record has been started") 350 | 351 | def undo(): 352 | pyautogui.hotkey('alt','tab') 353 | time.sleep(0.1) 354 | pyautogui.hotkey('ctrl','z') 355 | 356 | def redo(): 357 | pyautogui.hotkey('alt','tab') 358 | time.sleep(0.1) 359 | pyautogui.hotkey('ctrl','y') 360 | 361 | def type(content): 362 | pyautogui.typewrite(content) 363 | 364 | def press(key): 365 | pyautogui.press(key) 366 | 367 | def volume(value): 368 | if value == 0: 369 | for temp_i in range(20): 370 | pyautogui.press("volumedown") 371 | if value == 1: 372 | for temp_i in range(20): 373 | pyautogui.press("volumeup") 374 | 375 | def brightness(value): 376 | 377 | brightness_value = subprocess.run('powershell -Command "Get-Ciminstance -Namespace root/WMI -ClassName WmiMonitorBrightness | Select -ExpandProperty "CurrentBrightness""',capture_output=True) 378 | if value == 1: 379 | subprocess.run('powershell (Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1,'+str(int(brightness_value.stdout)+30)+')') 380 | speak("brightness increased") 381 | if value == 0: 382 | subprocess.run('powershell (Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1,'+str(int(brightness_value.stdout)-30)+')') 383 | speak("brightness decreased") 384 | 385 | def show_desktop(): 386 | speak('showing desktop') 387 | pyautogui.hotkey('win','d') 388 | 389 | def maximize(): 390 | pyautogui.hotkey('win','tab') 391 | time.sleep(0.2) 392 | pyautogui.press('enter') 393 | 394 | def get_date_and_time(time = False, date = False, date_time = True): 395 | 396 | day = str(datetime.now().day) 397 | month = str(datetime.now().month) 398 | year = str(datetime.now().year) 399 | date_now = str(day+" "+month+" "+year) 400 | 401 | hour = int(datetime.now().hour) 402 | minute = str(datetime.now().minute) 403 | if hour > 12: 404 | meridiem = "PM" 405 | hour = str(hour - 12) 406 | else: 407 | meridiem = "AM" 408 | hour = str(hour) 409 | time_now = hour+" "+minute+" "+meridiem 410 | if time: 411 | speak("the time is "+time_now,slow = True) 412 | return time_now 413 | elif date: 414 | speak("today's date is "+date_now,slow = True) 415 | else: 416 | speak("today's date is "+date_now+" and the time is "+time_now, slow = True) 417 | 418 | def mouse_left_click(): 419 | speak("clicked") 420 | pyautogui.hotkey('alt','tab') 421 | pyautogui.click() 422 | 423 | def mouse_right_click(): 424 | speak("clicked") 425 | pyautogui.hotkey('alt','tab') 426 | pyautogui.click(button='right') 427 | 428 | def airplane_mode(value): 429 | 430 | pyautogui.moveTo(1791,1057) 431 | pyautogui.click() 432 | start_time = time.perf_counter() 433 | status = 'init' 434 | while(time.perf_counter() - start_time <3): 435 | coor_off = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\airplane_mode_off.png', confidence=0.9) 436 | coor_on = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\airplane_mode_on.png', confidence=0.9) 437 | coor_on2 = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\airplane_mode_on_2.png', confidence=0.9) 438 | if coor_off: 439 | status = 0 440 | break 441 | elif coor_on: 442 | status = 1 443 | break 444 | elif coor_on2: 445 | status = 1 446 | break 447 | 448 | if status == 'init': 449 | speak('sorry there was an error occured while turning the airplane mode on or off') 450 | pyautogui.press('esc') 451 | elif value and status: 452 | speak('airplane mode is already turned on') 453 | pyautogui.press('esc') 454 | elif value == 0 and status == 0: 455 | speak('airplane mode is already turned off') 456 | pyautogui.press('esc') 457 | elif value == 1: 458 | pyautogui.moveTo(coor_off) 459 | pyautogui.click() 460 | pyautogui.press('esc') 461 | speak('airplane mode has been turned on') 462 | elif value == 0: 463 | pyautogui.moveTo(coor_on) 464 | pyautogui.click() 465 | pyautogui.press('esc') 466 | speak('airplane mode has been turned off') 467 | 468 | def mobile_hotspot(value): 469 | pyautogui.moveTo(1791,1057) 470 | pyautogui.click() 471 | start_time = time.perf_counter() 472 | status = 'init' 473 | while(time.perf_counter() - start_time <3): 474 | coor_off2 = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\mobile_hotspot_cannot_on.png', confidence=0.95) 475 | if coor_off2: 476 | status = 'cannot' 477 | break 478 | 479 | coor_off = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\mobile_hotspot_off.png', confidence=0.95) 480 | if coor_off: 481 | status = 0 482 | break 483 | 484 | coor_on = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\mobile_hotspot_on.png', confidence=0.95) 485 | if coor_on: 486 | status = 1 487 | break 488 | 489 | coor_on2 = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\mobile_hotspot_on_2.png', confidence=0.95) 490 | if coor_on2: 491 | status = 1 492 | break 493 | 494 | 495 | if status == 'init': 496 | speak('sorry there was an error occured while turning the airplane mode on or off') 497 | pyautogui.press('esc') 498 | elif status == 'cannot': 499 | speak('sorry you need internet connection to turn on mobile hotspot') 500 | pyautogui,press('esc') 501 | elif value and status: 502 | speak('mobile hotspot is already turned on') 503 | pyautogui.press('esc') 504 | elif value == 0 and status == 0: 505 | speak('mobile hotspot is already turned off') 506 | pyautogui.press('esc') 507 | elif value == 1: 508 | pyautogui.moveTo(coor_off) 509 | pyautogui.click() 510 | pyautogui.press('esc') 511 | speak('mobile hotspot has been turned on') 512 | elif value == 0: 513 | pyautogui.moveTo(coor_on) 514 | pyautogui.click() 515 | pyautogui.press('esc') 516 | speak('mobile hotspot has been turned off') 517 | 518 | def bluetooth(value): 519 | 520 | pyautogui.moveTo(1791,1057) 521 | pyautogui.click() 522 | start_time = time.perf_counter() 523 | status = 'init' 524 | while(time.perf_counter() - start_time <3): 525 | coor_off = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\bluetooth_off.png') 526 | if coor_off: 527 | status = 0 528 | break 529 | 530 | coor_on = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\bluetooth_on.png') 531 | if coor_on: 532 | status = 1 533 | break 534 | 535 | 536 | if status == 'init': 537 | speak('sorry there was an error occured while turning the bluetooth on or off') 538 | pyautogui.press('esc') 539 | elif value and status: 540 | speak('bluetooth is already turned on') 541 | pyautogui.press('esc') 542 | elif value == 0 and status == 0: 543 | speak('bluetooth is already turned off') 544 | pyautogui.press('esc') 545 | elif value == 1: 546 | x,y = coor_off 547 | pyautogui.moveTo(x-30,y) 548 | pyautogui.click() 549 | pyautogui.press('esc') 550 | speak('bluetooth has been turned on') 551 | elif value == 0: 552 | x,y = coor_on 553 | pyautogui.moveTo(x-30,y) 554 | pyautogui.click() 555 | pyautogui.press('esc') 556 | speak('bluetooth has been turned off') 557 | 558 | def battery_saver(value): 559 | pyautogui.moveTo(1791,1057) 560 | pyautogui.click() 561 | start_time = time.perf_counter() 562 | status = 'init' 563 | while(time.perf_counter() - start_time <3): 564 | coor_off = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\battery_saver_off.png',confidence=0.95) 565 | if coor_off: 566 | status = 0 567 | break 568 | coor_off = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\battery_saver_cannot_on.png') 569 | if coor_off: 570 | status = 'cannot' 571 | break 572 | coor_on = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\battery_saver_on.png') 573 | if coor_on: 574 | status = 1 575 | break 576 | 577 | 578 | if status == 'init': 579 | speak('sorry there was an error occured while turning the battery saver on or off') 580 | pyautogui.press('esc') 581 | elif status == 'cannot': 582 | speak('sorry cannot turn on or off battery saver while plugged in') 583 | pyautogui.press('esc') 584 | elif value and status: 585 | speak('battery saver is already turned on') 586 | pyautogui.press('esc') 587 | elif value == 0 and status == 0: 588 | speak('battery saver is already turned off') 589 | pyautogui.press('esc') 590 | elif value == 1: 591 | x,y = coor_off 592 | pyautogui.moveTo(x,y) 593 | pyautogui.click() 594 | pyautogui.press('esc') 595 | speak('battery saver has been turned on') 596 | elif value == 0: 597 | x,y = coor_on 598 | pyautogui.moveTo(x,y) 599 | pyautogui.click() 600 | pyautogui.press('esc') 601 | speak('battery saver has been turned off') 602 | 603 | def location(): 604 | speak("sorry! there no location service on your computer") 605 | 606 | def greeting(): 607 | speak("hello! How can I help you today?") 608 | 609 | def open_chrome(): 610 | global driver 611 | speak("opening chrome") 612 | chrome_options = webdriver.ChromeOptions(); 613 | chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']) 614 | capabilities = DesiredCapabilities.CHROME 615 | capabilities["goog:loggingPrefs"] = {"performance": "ALL"} 616 | driver = webdriver.Chrome(r"./chromedriver",desired_capabilities=capabilities,options=chrome_options) 617 | driver.maximize_window() 618 | 619 | def open_youtube(): 620 | 621 | try: 622 | speak("going to youtube") 623 | driver.get("https://www.youtube.com") 624 | except: 625 | print("error opening youtube") 626 | speak("sorry. The was an error opening youtube") 627 | 628 | def introduction(): 629 | speak("hello. I am a voice assistant specifically available on windows",needed_thread=False) 630 | speak("I can do anything you do on your computer",needed_thread=False) 631 | speak("you just need to command me ",needed_thread=False) 632 | speak("and I will do the rest",needed_thread=False) 633 | 634 | def close_current_tab(): 635 | #pyautogui.hotkey("alt","f4") 636 | pyautogui.moveTo(1900,20) 637 | pyautogui.click() 638 | speak("closed") 639 | 640 | def play_video_by_count(value): 641 | if True:#try: 642 | if value == 1: 643 | video = driver.find_element(By.XPATH,"/html/body/ytd-app/div[1]/ytd-page-manager/ytd-browse/ytd-two-column-browse-results-renderer/div[1]/ytd-rich-grid-renderer/div[6]/ytd-rich-grid-row[1]/div/ytd-rich-item-renderer[1]/div/ytd-rich-grid-media/div[1]/div[1]/ytd-thumbnail/a/yt-image/img") 644 | video.click() 645 | elif value == 2: 646 | video = driver.find_element(By.XPATH,"/html/body/ytd-app/div[1]/ytd-page-manager/ytd-browse/ytd-two-column-browse-results-renderer/div[1]/ytd-rich-grid-renderer/div[6]/ytd-rich-grid-row[1]/div/ytd-rich-item-renderer[2]/div/ytd-rich-grid-media/div[1]/div[1]/ytd-thumbnail/a/yt-image/img") 647 | video.click() 648 | elif value == 3: 649 | video = driver.find_element(By.XPATH,"/html/body/ytd-app/div[1]/ytd-page-manager/ytd-browse/ytd-two-column-browse-results-renderer/div[1]/ytd-rich-grid-renderer/div[6]/ytd-rich-grid-row[1]/div/ytd-rich-item-renderer[3]/div/ytd-rich-grid-media/div[1]/div[1]/ytd-thumbnail/a/yt-image/img") 650 | video.click() 651 | elif value == 4: 652 | video = driver.find_element(By.XPATH,"/html/body/ytd-app/div[1]/ytd-page-manager/ytd-browse/ytd-two-column-browse-results-renderer/div[1]/ytd-rich-grid-renderer/div[6]/ytd-rich-grid-row[1]/div/ytd-rich-item-renderer[4]/div/ytd-rich-grid-media/div[1]/div[1]/ytd-thumbnail/a/yt-image/img") 653 | video.click() 654 | speak("playing the video") 655 | else:#except: 656 | print("error while clicking video") 657 | 658 | def login_to_tel(): 659 | global driver 660 | capabilities = DesiredCapabilities.CHROME 661 | capabilities["goog:loggingPrefs"] = {"performance": "ALL"} 662 | chrome_options = webdriver.ChromeOptions(); 663 | chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']) 664 | 665 | driver = webdriver.Chrome(r"./chromedriver",desired_capabilities=capabilities,options=chrome_options) 666 | driver.page_load_strategy = 'eager' 667 | 668 | driver.maximize_window() 669 | while True: 670 | try: 671 | driver.get("https://tlc.krgi.in/#/") 672 | break 673 | except: 674 | x=input("Network Error press ENTER to try again") 675 | tel=driver.find_element(By.XPATH,'//*[@id="mainArc-TELCURRICULA"]') 676 | tel.click() 677 | ug=driver.find_element(By.XPATH,'//*[@id="root"]/section/main[2]/div/div/div[4]/div/div[1]/div[2]/div/div/div[1]') 678 | ug.click() 679 | p=driver.current_window_handle 680 | test=driver.window_handles[0] 681 | test2=driver.window_handles[1] 682 | driver.switch_to.window(test2) 683 | time.sleep(2) 684 | start=driver.find_element(By.XPATH,'//*[@id="root"]/div/section/section/main[1]/div/div/div/div[1]/button') 685 | start.click() 686 | username=driver.find_element(By.XPATH,'//*[@id="Username1"]') 687 | username.send_keys("459437942815") 688 | time.sleep(0.5) 689 | password=driver.find_element(By.XPATH,'//*[@id="Password"]') 690 | password.click() 691 | password.send_keys("Rajeswari") 692 | time.sleep(0.5) 693 | enter=driver.find_element(By.XPATH,"/html/body/div[3]/div/div[2]/div/div[2]/div/div/div/div/div[3]/div[2]/div[3]/button") 694 | enter.click() 695 | #print("clicking sem2") 696 | try: 697 | sem2=driver.find_element(By.XPATH,'//*[@id="root"]/div/div/section/main/div/div[2]/div[2]/div/button[2]/div/img') 698 | sem2.click() 699 | except: 700 | pass 701 | speak("opened") 702 | 703 | def like_video(self): 704 | try: 705 | like = driver.find_element(By.XPATH,'//*[@id="segmented-like-button"]/ytd-toggle-button-renderer/yt-button-shape/button/yt-touch-feedback-shape/div/div[2]') 706 | like.click() 707 | speak("liked the video") 708 | except Exception as e: 709 | speak("sorry. There was an error") 710 | 711 | def like_video(self): 712 | 713 | 714 | try: 715 | dislike = driver.find_element(By.XPATH,'//*[@id="segmented-dislike-button"]/ytd-toggle-button-renderer/yt-button-shape/button/yt-touch-feedback-shape/div/div[2]') 716 | dislike.click() 717 | speak("disliked the video") 718 | except Exception as e: 719 | speak("sorry. There was an error") 720 | 721 | def weather(): 722 | speak("checking weather data") 723 | chrome = application_tasks.chrome() 724 | chrome.maximize() 725 | 726 | city = "karur" 727 | 728 | url = "https://www.google.com/search?q="+"weather"+city 729 | html = requests.get(url).content 730 | 731 | soup = BeautifulSoup(html, 'html.parser') 732 | temp = soup.find('div', attrs={'class': 'BNeawe iBp4i AP7Wnd'}).text 733 | strdata = soup.find('div', attrs={'class': 'BNeawe tAd8D AP7Wnd'}).text 734 | 735 | data = strdata.split('\n') 736 | time = data[0] 737 | sky = data[1] 738 | 739 | listdiv = soup.findAll('div', attrs={'class': 'BNeawe s3v9rd AP7Wnd'}) 740 | strd = listdiv[5].text 741 | 742 | pos = strd.find('Wind') 743 | 744 | speak("The temperature now is "+str(temp)+"\n The Sky is "+str(sky)+"\nThe Time is "+str(time)) 745 | 746 | chrome.search("https://www.google.com/search?q="+"weather"+"karur") 747 | 748 | def get_news(): 749 | 750 | speak("here some current news for you") 751 | chrome = application_tasks.chrome() 752 | chrome.maximize() 753 | 754 | chrome.search("https://www.msn.com/en-in/news") 755 | 756 | def search_google(text): 757 | 758 | speak("searching"+text) 759 | chrome = application_tasks.chrome() 760 | chrome.maximize() 761 | 762 | chrome.search("https://www.google.com/search?q="+text) 763 | 764 | def take_notes(): 765 | speak('taking notes') 766 | open_application('notepad',speak_needed=False) 767 | time.sleep(0.7) 768 | pyautogui.hotkey('win','h') -------------------------------------------------------------------------------- /tasks_backup.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | import subprocess 4 | import time 5 | from datetime import datetime 6 | import cv2 7 | import PIL.Image 8 | import pyautogui 9 | import pytesseract 10 | import pyttsx3 11 | import spacy 12 | from gtts import gTTS 13 | from openpyxl import Workbook, load_workbook 14 | from pynput.keyboard import Controller, Key 15 | from pytesseract import Output 16 | import AppOpener 17 | import requests 18 | import application_tasks 19 | from bs4 import BeautifulSoup 20 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 21 | from selenium.webdriver.common.action_chains import ActionChains 22 | from selenium.webdriver.chrome.options import Options 23 | from selenium.webdriver.common.keys import Keys 24 | from selenium.webdriver.common.by import By 25 | from pynput.keyboard import Key, Listener 26 | from selenium import webdriver 27 | 28 | pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe' 29 | global nlp 30 | driver = "temp" 31 | #nlp = spacy.load("en_core_web_lg") 32 | def speak(content,slow = False , voice = 1): 33 | 34 | engine = pyttsx3.init() 35 | if slow == True: 36 | rate = engine.getProperty('rate') 37 | engine.setProperty('rate', 150) 38 | voices = engine.getProperty('voices') 39 | engine.setProperty('voice', voices[voice].id) 40 | 41 | engine.say(content) 42 | engine.runAndWait() 43 | 44 | def speak_google(content, slow = False): 45 | 46 | audio = myobj = gTTS(text=content, lang='en', slow=slow) 47 | audio.save("D:\\mini_project\\temp\\welcome.mp3") 48 | from playsound import playsound 49 | playsound('D:\\mini_project\\temp\\welcome.mp3') 50 | os.remove('D:\\mini_project\\temp\\welcome.mp3') 51 | 52 | def open_application(app): 53 | 54 | if True: 55 | open_app = None 56 | open_app_arr = [] 57 | dict1 = dict() 58 | temp = "" 59 | tot_application = AppOpener.give_appnames() 60 | #print(tot_application) 61 | for i in tot_application: 62 | if app == i: 63 | open_app = i 64 | break 65 | elif app in i: 66 | open_app_arr.append(i) 67 | 68 | if open_app_arr != [] and len(open_app_arr) >1: 69 | print(open_app_arr) 70 | speak("which one do you want to open") 71 | for i in open_app_arr: 72 | temp += i+" " 73 | speak(temp) 74 | app = input() #needs to be changed to voice input 75 | for i in open_app_arr: 76 | dict1[i] = nlp(i).similarity(nlp(app)) 77 | print(dict1) 78 | index_app = list(dict1.values()).index(max(dict1.values())) 79 | 80 | if list(dict1.values())[index_app] >=0.5: 81 | open_app = open_app_arr[index_app] 82 | 83 | 84 | 85 | elif len(open_app_arr) == 1: 86 | open_app = open_app_arr[0] 87 | 88 | 89 | if open_app != None: 90 | speak("opening"+open_app) 91 | AppOpener.open(open_app) 92 | else: 93 | speak("sorry ! "+app+" is not installed") 94 | print("not installed") 95 | 96 | def find_text_on_screen(text): 97 | text = text.lower() 98 | myscreenshot=pyautogui.screenshot() 99 | myscreenshot.save(r"D:\\mini_project\\temp\\screenshot.png") 100 | data = pytesseract.image_to_data(PIL.Image.open("D:\\mini_project\\temp\\screenshot.png"),output_type = Output.DICT) 101 | 102 | for i,value in enumerate(data['text']): 103 | data['text'][i] = data['text'][i].lower() 104 | 105 | with open("temp.json",'w') as f: 106 | f.write(json.dumps(data)) 107 | try: 108 | x,y,width,height = data['left'][data['text'].index(text)], data['top'][data['text'].index(text)], data['width'][data['text'].index(text)], data['height'][data['text'].index(text)] 109 | pyautogui.moveTo(x+width/2, y+height/2) 110 | pyautogui.click() 111 | return x+width/2,y+height/2 112 | except: 113 | print("cannot find",text,"on the screen") 114 | return str("cannot find"+text+"on the screen") , False 115 | 116 | def wifi_on_and_off(value): 117 | 118 | if value == 1: 119 | MyWish = subprocess.run (['netsh', 'interface', 'set', 'interface', "wi-fi", "ENABLED"]) 120 | speak ("The wifi has been turned on") 121 | elif value == 0: 122 | MyWish = subprocess.run (['netsh', 'interface', 'set', 'interface', "wi-fi", "DISABLED"]) 123 | speak( "The wifi has been turned off") 124 | else: 125 | return "sorry ! some error occured during the process" 126 | 127 | def wifi_connect(): 128 | pyautogui.moveTo(1766,1047) 129 | pyautogui.click() 130 | time.sleep(0.5) 131 | pyautogui.moveTo(1573,454) 132 | pyautogui.click() 133 | network_name = 'student' 134 | temp = 10 135 | while temp: 136 | try: 137 | for i in range(0,10): 138 | x,y = find_text_on_screen(network_name) 139 | if y != False: 140 | break 141 | 142 | if y != False: 143 | pyautogui.moveTo(x,y) 144 | pyautogui.click() 145 | time.sleep(0.8) 146 | for i in range(0,5): 147 | x,y = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\wifi_connect.png',confidence = 0.9) 148 | if x != None: 149 | break 150 | pyautogui.moveTo(x,y) 151 | pyautogui.click() 152 | else: 153 | print('cannot find the network') 154 | break 155 | except: 156 | temp-=1 157 | 158 | def pause_play(): 159 | pyautogui.press("playpause") 160 | 161 | def mute_volume(): 162 | keyboard = Controller() 163 | try: 164 | speak("The volume has been muted") 165 | keyboard.press(Key.media_volume_mute) 166 | except: 167 | speak("Sorry ! there was a problem while muting the volume") 168 | time.sleep(0.1) 169 | 170 | def sleep_computer(): 171 | speak("turning computer to sleep") 172 | try: 173 | os.system('cmd /c "powercfg -H off" ') 174 | os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0") 175 | 176 | except: 177 | speak("sorry ! there was a problem while turning the computer to sleep") 178 | 179 | def hibernate_computer(): 180 | speak("turning computer to hibernate") 181 | try: 182 | os.system('cmd /c "powercfg -H on" ') 183 | os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0") 184 | 185 | except: 186 | speak("sorry ! there was a problem while turning the computer to hibernate") 187 | 188 | def shutdown_computer(): 189 | speak('do you want to shutdown your computer') 190 | response = input() 191 | if "yes" in response: 192 | speak('shutting down the computer') 193 | try: 194 | os.system("shutdown /s /t 1") 195 | except: 196 | speak('sorry ! there was a problem while shutting down the computer') 197 | else: 198 | speak('ok exitting from shutdown ') 199 | 200 | def restart_computer(): 201 | speak('do you want to restart your computer') 202 | response = input() 203 | if "yes" in response: 204 | speak('restarting the computer') 205 | try: 206 | os.system("shutdown /r /t 1") 207 | except: 208 | speak('sorry ! there was a problem while restarting the computer') 209 | else: 210 | speak('ok exitting from restart ') 211 | 212 | def take_photo(): 213 | AppOpener.open("camera") 214 | speak("ready ?") 215 | 216 | speak("say chheeeeeese",slow = 1) 217 | pyautogui.press("space") 218 | 219 | def record_video(): 220 | cap= cv2.VideoCapture(0) 221 | 222 | width= int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) 223 | height= int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) 224 | writer= cv2.VideoWriter('D:\\mini_project\\files_by_assistant\\recoded_video_.mp4', cv2.VideoWriter_fourcc(*'DIVX'), 20, (width,height)) 225 | 226 | 227 | while True: 228 | ret,frame= cap.read() 229 | 230 | writer.write(frame) 231 | 232 | cv2.imshow('frame', frame) 233 | 234 | if cv2.waitKey(1) & 0xFF == 27: 235 | break 236 | 237 | 238 | cap.release() 239 | writer.release() 240 | cv2.destroyAllWindows() 241 | 242 | def scroll_down(): 243 | pyautogui.moveTo(960,540) 244 | for i in range(20): 245 | pyautogui.scroll(-30) 246 | 247 | def scroll_up(): 248 | pyautogui.moveTo(960,540) 249 | for i in range(20): 250 | pyautogui.scroll(30) 251 | 252 | def zoom_in(): 253 | for i in range(0,3): 254 | pyautogui.hotkey('ctrl','+') 255 | 256 | def zoom_out(): 257 | for i in range(0,3): 258 | pyautogui.hotkey('ctrl','+') 259 | 260 | def refresh(): 261 | pyautogui.press('f5') 262 | pyautogui.hotkey('ctrl','r') 263 | 264 | def take_screenshot(): 265 | pyautogui.hotkey('win','printscreen') 266 | 267 | def screen_record(): 268 | pyautogui.keyDown('win') 269 | pyautogui.keyDown('alt') 270 | pyautogui.keyDown('r') 271 | 272 | pyautogui.keyUp('r') 273 | pyautogui.keyUp('alt') 274 | pyautogui.keyUp('win') 275 | 276 | def undo(): 277 | pyautogui.hotkey('alt','tab') 278 | time.sleep(0.1) 279 | pyautogui.hotkey('ctrl','z') 280 | 281 | def redo(): 282 | pyautogui.hotkey('alt','tab') 283 | time.sleep(0.1) 284 | pyautogui.hotkey('ctrl','y') 285 | 286 | def type(content): 287 | pyautogui.typewrite(content) 288 | 289 | def press(key): 290 | pyautogui.press(key) 291 | 292 | def volume(value): 293 | if value == 0: 294 | for temp_i in range(20): 295 | pyautogui.press("volumedown") 296 | if value == 1: 297 | for temp_i in range(20): 298 | pyautogui.press("volumeup") 299 | 300 | def brightness(value): 301 | 302 | brightness_value = subprocess.run('powershell -Command "Get-Ciminstance -Namespace root/WMI -ClassName WmiMonitorBrightness | Select -ExpandProperty "CurrentBrightness""',capture_output=True) 303 | if value == 1: 304 | subprocess.run('powershell (Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1,'+str(int(brightness_value.stdout)+30)+')') 305 | speak("brightness increased") 306 | if value == 0: 307 | subprocess.run('powershell (Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1,'+str(int(brightness_value.stdout)-30)+')') 308 | speak("brightness decreased") 309 | 310 | def show_desktop(): 311 | speak('showing desktop') 312 | pyautogui.hotkey('win','d') 313 | 314 | def maximize(): 315 | pyautogui.hotkey('win','tab') 316 | time.sleep(0.2) 317 | pyautogui.press('enter') 318 | 319 | def get_date_and_time(time = False, date = False, date_time = True): 320 | 321 | day = str(datetime.now().day) 322 | month = str(datetime.now().month) 323 | year = str(datetime.now().year) 324 | date_now = str(day+" "+month+" "+year) 325 | 326 | hour = int(datetime.now().hour) 327 | minute = str(datetime.now().minute) 328 | if hour > 12: 329 | meridiem = "PM" 330 | hour = str(hour - 12) 331 | else: 332 | meridiem = "AM" 333 | hour = str(hour) 334 | time_now = hour+" "+minute+" "+meridiem 335 | if time: 336 | speak("the time is "+time_now,slow = True) 337 | return time_now 338 | elif date: 339 | speak("today's date is "+date_now,slow = True) 340 | else: 341 | speak("today's date is "+date_now+" and the time is "+time_now, slow = True) 342 | 343 | def mouse_left_click(): 344 | pyautogui.click() 345 | 346 | def mouse_right_click(): 347 | pyautogui.click(button='right') 348 | 349 | def airplane_mode(value): 350 | 351 | pyautogui.moveTo(1791,1057) 352 | pyautogui.click() 353 | start_time = time.perf_counter() 354 | status = 'init' 355 | while(time.perf_counter() - start_time <3): 356 | coor_off = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\airplane_mode_off.png', confidence=0.9) 357 | coor_on = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\airplane_mode_on.png', confidence=0.9) 358 | coor_on2 = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\airplane_mode_on_2.png', confidence=0.9) 359 | if coor_off: 360 | status = 0 361 | break 362 | elif coor_on: 363 | status = 1 364 | break 365 | elif coor_on2: 366 | status = 1 367 | break 368 | 369 | if status == 'init': 370 | speak('sorry there was an error occured while turning the airplane mode on or off') 371 | pyautogui.press('esc') 372 | elif value and status: 373 | speak('airplane mode is already turned on') 374 | pyautogui.press('esc') 375 | elif value == 0 and status == 0: 376 | speak('airplane mode is already turned off') 377 | pyautogui.press('esc') 378 | elif value == 1: 379 | pyautogui.moveTo(coor_off) 380 | pyautogui.click() 381 | pyautogui.press('esc') 382 | speak('airplane mode has been turned on') 383 | elif value == 0: 384 | pyautogui.moveTo(coor_on) 385 | pyautogui.click() 386 | pyautogui.press('esc') 387 | speak('airplane mode has been turned off') 388 | 389 | def mobile_hotspot(value): 390 | pyautogui.moveTo(1791,1057) 391 | pyautogui.click() 392 | start_time = time.perf_counter() 393 | status = 'init' 394 | while(time.perf_counter() - start_time <3): 395 | coor_off2 = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\mobile_hotspot_cannot_on.png', confidence=0.95) 396 | if coor_off2: 397 | status = 'cannot' 398 | break 399 | 400 | coor_off = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\mobile_hotspot_off.png', confidence=0.95) 401 | if coor_off: 402 | status = 0 403 | break 404 | 405 | coor_on = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\mobile_hotspot_on.png', confidence=0.95) 406 | if coor_on: 407 | status = 1 408 | break 409 | 410 | coor_on2 = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\mobile_hotspot_on_2.png', confidence=0.95) 411 | if coor_on2: 412 | status = 1 413 | break 414 | 415 | 416 | if status == 'init': 417 | speak('sorry there was an error occured while turning the airplane mode on or off') 418 | pyautogui.press('esc') 419 | elif status == 'cannot': 420 | speak('sorry you need internet connection to turn on mobile hotspot') 421 | pyautogui,press('esc') 422 | elif value and status: 423 | speak('mobile hotspot is already turned on') 424 | pyautogui.press('esc') 425 | elif value == 0 and status == 0: 426 | speak('mobile hotspot is already turned off') 427 | pyautogui.press('esc') 428 | elif value == 1: 429 | pyautogui.moveTo(coor_off) 430 | pyautogui.click() 431 | pyautogui.press('esc') 432 | speak('mobile hotspot has been turned on') 433 | elif value == 0: 434 | pyautogui.moveTo(coor_on) 435 | pyautogui.click() 436 | pyautogui.press('esc') 437 | speak('mobile hotspot has been turned off') 438 | 439 | def bluetooth(value): 440 | 441 | pyautogui.moveTo(1791,1057) 442 | pyautogui.click() 443 | start_time = time.perf_counter() 444 | status = 'init' 445 | while(time.perf_counter() - start_time <3): 446 | coor_off = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\bluetooth_off.png') 447 | if coor_off: 448 | status = 0 449 | break 450 | 451 | coor_on = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\bluetooth_on.png') 452 | if coor_on: 453 | status = 1 454 | break 455 | 456 | 457 | if status == 'init': 458 | speak('sorry there was an error occured while turning the bluetooth on or off') 459 | pyautogui.press('esc') 460 | elif value and status: 461 | speak('bluetooth is already turned on') 462 | pyautogui.press('esc') 463 | elif value == 0 and status == 0: 464 | speak('bluetooth is already turned off') 465 | pyautogui.press('esc') 466 | elif value == 1: 467 | x,y = coor_off 468 | pyautogui.moveTo(x-30,y) 469 | pyautogui.click() 470 | pyautogui.press('esc') 471 | speak('bluetooth has been turned on') 472 | elif value == 0: 473 | x,y = coor_on 474 | pyautogui.moveTo(x-30,y) 475 | pyautogui.click() 476 | pyautogui.press('esc') 477 | speak('bluetooth has been turned off') 478 | 479 | def battery_saver(value): 480 | pyautogui.moveTo(1791,1057) 481 | pyautogui.click() 482 | start_time = time.perf_counter() 483 | status = 'init' 484 | while(time.perf_counter() - start_time <3): 485 | coor_off = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\battery_saver_off.png',confidence=0.95) 486 | if coor_off: 487 | status = 0 488 | break 489 | coor_off = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\battery_saver_cannot_on.png') 490 | if coor_off: 491 | status = 'cannot' 492 | break 493 | coor_on = pyautogui.locateCenterOnScreen('D:\\mini_project\\dependency_images\\battery_saver_on.png') 494 | if coor_on: 495 | status = 1 496 | break 497 | 498 | 499 | if status == 'init': 500 | speak('sorry there was an error occured while turning the battery saver on or off') 501 | pyautogui.press('esc') 502 | elif status == 'cannot': 503 | speak('sorry cannot turn on or off battery saver while plugged in') 504 | pyautogui.press('esc') 505 | elif value and status: 506 | speak('battery saver is already turned on') 507 | pyautogui.press('esc') 508 | elif value == 0 and status == 0: 509 | speak('battery saver is already turned off') 510 | pyautogui.press('esc') 511 | elif value == 1: 512 | x,y = coor_off 513 | pyautogui.moveTo(x,y) 514 | pyautogui.click() 515 | pyautogui.press('esc') 516 | speak('battery saver has been turned on') 517 | elif value == 0: 518 | x,y = coor_on 519 | pyautogui.moveTo(x,y) 520 | pyautogui.click() 521 | pyautogui.press('esc') 522 | speak('battery saver has been turned off') 523 | 524 | def location(): 525 | speak("sorry! there no location service on your computer") 526 | 527 | def greeting(): 528 | speak("hello! How can I help you today?") 529 | 530 | def open_chrome(): 531 | global driver 532 | speak("opening chrome") 533 | chrome_options = webdriver.ChromeOptions(); 534 | chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']) 535 | capabilities = DesiredCapabilities.CHROME 536 | capabilities["goog:loggingPrefs"] = {"performance": "ALL"} 537 | driver = webdriver.Chrome(r"./chromedriver",desired_capabilities=capabilities,options=chrome_options) 538 | driver.maximize_window() 539 | 540 | def open_youtube(): 541 | 542 | try: 543 | speak("going to youtube") 544 | driver.get("https://www.youtube.com") 545 | except: 546 | print("error opening youtube") 547 | speak("sorry. The was an error opening youtube") 548 | 549 | def search(url): 550 | global driver 551 | try: 552 | speak("searching") 553 | driver.get(url) 554 | 555 | except: 556 | speak("searching") 557 | 558 | chrome_options = webdriver.ChromeOptions(); 559 | chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']) 560 | capabilities = DesiredCapabilities.CHROME 561 | capabilities["goog:loggingPrefs"] = {"performance": "ALL"} 562 | driver = webdriver.Chrome(r"./chromedriver",desired_capabilities=capabilities,options=chrome_options) 563 | driver.maximize_window() 564 | driver.get(url) 565 | 566 | def introduction(): 567 | speak("hello. I am a voice assistant specifically available on windows") 568 | speak("I can do anything you do on your computer") 569 | speak("you just need to command me ") 570 | speak("and I will do the rest") 571 | 572 | def close_current_tab(): 573 | #pyautogui.hotkey("alt","f4") 574 | pyautogui.moveTo(1900,20) 575 | pyautogui.click() 576 | speak("closed") 577 | 578 | def play_video_by_count(value): 579 | if True:#try: 580 | if value == 1: 581 | video = driver.find_element(By.XPATH,"/html/body/ytd-app/div[1]/ytd-page-manager/ytd-browse/ytd-two-column-browse-results-renderer/div[1]/ytd-rich-grid-renderer/div[6]/ytd-rich-grid-row[1]/div/ytd-rich-item-renderer[1]/div/ytd-rich-grid-media/div[1]/div[1]/ytd-thumbnail/a/yt-image/img") 582 | video.click() 583 | elif value == 2: 584 | video = driver.find_element(By.XPATH,"/html/body/ytd-app/div[1]/ytd-page-manager/ytd-browse/ytd-two-column-browse-results-renderer/div[1]/ytd-rich-grid-renderer/div[6]/ytd-rich-grid-row[1]/div/ytd-rich-item-renderer[2]/div/ytd-rich-grid-media/div[1]/div[1]/ytd-thumbnail/a/yt-image/img") 585 | video.click() 586 | elif value == 3: 587 | video = driver.find_element(By.XPATH,"/html/body/ytd-app/div[1]/ytd-page-manager/ytd-browse/ytd-two-column-browse-results-renderer/div[1]/ytd-rich-grid-renderer/div[6]/ytd-rich-grid-row[1]/div/ytd-rich-item-renderer[3]/div/ytd-rich-grid-media/div[1]/div[1]/ytd-thumbnail/a/yt-image/img") 588 | video.click() 589 | elif value == 4: 590 | video = driver.find_element(By.XPATH,"/html/body/ytd-app/div[1]/ytd-page-manager/ytd-browse/ytd-two-column-browse-results-renderer/div[1]/ytd-rich-grid-renderer/div[6]/ytd-rich-grid-row[1]/div/ytd-rich-item-renderer[4]/div/ytd-rich-grid-media/div[1]/div[1]/ytd-thumbnail/a/yt-image/img") 591 | video.click() 592 | speak("playing the video") 593 | else:#except: 594 | print("error while clicking video") 595 | 596 | def login_to_tel(): 597 | global driver 598 | capabilities = DesiredCapabilities.CHROME 599 | capabilities["goog:loggingPrefs"] = {"performance": "ALL"} 600 | chrome_options = webdriver.ChromeOptions(); 601 | chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']) 602 | 603 | driver = webdriver.Chrome(r"./chromedriver",desired_capabilities=capabilities,options=chrome_options) 604 | driver.page_load_strategy = 'eager' 605 | 606 | driver.maximize_window() 607 | while True: 608 | try: 609 | driver.get("https://tlc.krgi.in/#/") 610 | break 611 | except: 612 | x=input("Network Error press ENTER to try again") 613 | tel=driver.find_element(By.XPATH,'//*[@id="mainArc-TELCURRICULA"]') 614 | tel.click() 615 | ug=driver.find_element(By.XPATH,'//*[@id="root"]/section/main[2]/div/div/div[4]/div/div[1]/div[2]/div/div/div[1]') 616 | ug.click() 617 | p=driver.current_window_handle 618 | test=driver.window_handles[0] 619 | test2=driver.window_handles[1] 620 | driver.switch_to.window(test2) 621 | time.sleep(2) 622 | start=driver.find_element(By.XPATH,'//*[@id="root"]/div/section/section/main[1]/div/div/div/div[1]/button') 623 | start.click() 624 | username=driver.find_element(By.XPATH,'//*[@id="Username1"]') 625 | username.send_keys("459437942815") 626 | time.sleep(0.5) 627 | password=driver.find_element(By.XPATH,'//*[@id="Password"]') 628 | password.click() 629 | password.send_keys("Rajeswari") 630 | time.sleep(0.5) 631 | enter=driver.find_element(By.XPATH,"/html/body/div[3]/div/div[2]/div/div[2]/div/div/div/div/div[3]/div[2]/div[3]/button") 632 | enter.click() 633 | #print("clicking sem2") 634 | try: 635 | sem2=driver.find_element(By.XPATH,'//*[@id="root"]/div/div/section/main/div/div[2]/div[2]/div/button[2]/div/img') 636 | sem2.click() 637 | except: 638 | pass 639 | 640 | def like_video(self): 641 | try: 642 | like = driver.find_element(By.XPATH,'//*[@id="segmented-like-button"]/ytd-toggle-button-renderer/yt-button-shape/button/yt-touch-feedback-shape/div/div[2]') 643 | like.click() 644 | speak("liked the video") 645 | except Exception as e: 646 | speak("sorry. There was an error") 647 | 648 | def like_video(self): 649 | 650 | 651 | try: 652 | dislike = driver.find_element(By.XPATH,'//*[@id="segmented-dislike-button"]/ytd-toggle-button-renderer/yt-button-shape/button/yt-touch-feedback-shape/div/div[2]') 653 | dislike.click() 654 | speak("disliked the video") 655 | except Exception as e: 656 | speak("sorry. There was an error") 657 | 658 | def weather(): 659 | city = "karur" 660 | 661 | url = "https://www.google.com/search?q="+"weather"+city 662 | html = requests.get(url).content 663 | 664 | soup = BeautifulSoup(html, 'html.parser') 665 | temp = soup.find('div', attrs={'class': 'BNeawe iBp4i AP7Wnd'}).text 666 | str = soup.find('div', attrs={'class': 'BNeawe tAd8D AP7Wnd'}).text 667 | 668 | data = str.split('\n') 669 | time = data[0] 670 | sky = data[1] 671 | 672 | listdiv = soup.findAll('div', attrs={'class': 'BNeawe s3v9rd AP7Wnd'}) 673 | strd = listdiv[5].text 674 | 675 | pos = strd.find('Wind') 676 | other_data = strd[pos:] 677 | 678 | speak("The temperature now is", temp) 679 | speak("The Sky is ", sky) 680 | speak("Time now is ", time) 681 | 682 | -------------------------------------------------------------------------------- /temp.json: -------------------------------------------------------------------------------- 1 | {"level": [1, 2, 3, 4, 5, 5, 2, 3, 4, 5, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 2, 3, 4, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 2, 3, 4, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 2, 3, 4, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 2, 3, 4, 5, 5, 5, 5, 4, 5, 5, 5, 2, 3, 4, 5, 5, 5, 5, 5, 5, 2, 3, 4, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 2, 3, 4, 5, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 2, 3, 4, 5, 5, 5, 5, 2, 3, 4, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 2, 3, 4, 5, 5, 5, 5, 4, 5, 5, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 5, 5, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 3, 4, 5, 5, 5, 2, 3, 4, 5, 5, 5, 5, 5, 2, 3, 4, 5, 2, 3, 4, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 2, 3, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5], "page_num": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "block_num": [0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32], "par_num": [0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "line_num": [0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2], "word_num": [0, 0, 0, 0, 1, 2, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 0, 0, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 0, 0, 1, 2, 3, 4, 5, 6, 0, 0, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 0, 0, 0, 1, 2, 3, 0, 1, 2, 3, 4, 0, 1, 2, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 0, 0, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 3, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 0, 0, 1, 2, 3, 0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 1, 0, 0, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 0, 0, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5], "left": [0, 14, 14, 14, 14, 44, 4, 4, 4, 4, 18, 18, 16, 16, 16, 16, 12, 12, 12, 12, 74, 74, 74, 74, 86, 86, 86, 86, 105, 150, 167, 198, 210, 239, 76, 76, 76, 76, 70, 70, 70, 70, 74, 74, 74, 74, 86, 86, 86, 86, 131, 131, 131, 131, 135, 135, 135, 135, 173, 210, 244, 352, 384, 136, 136, 228, 240, 271, 307, 332, 341, 360, 136, 136, 136, 136, 177, 230, 241, 352, 384, 137, 137, 157, 175, 256, 287, 361, 370, 135, 135, 135, 135, 194, 218, 259, 352, 384, 136, 136, 154, 189, 212, 231, 136, 136, 136, 136, 153, 185, 221, 267, 352, 384, 136, 136, 181, 210, 229, 132, 132, 132, 132, 352, 386, 136, 136, 151, 171, 252, 284, 356, 366, 135, 135, 135, 135, 173, 352, 384, 136, 136, 218, 245, 135, 135, 135, 135, 188, 254, 275, 288, 352, 135, 135, 135, 135, 204, 222, 237, 260, 352, 135, 135, 163, 191, 224, 132, 135, 136, 136, 175, 352, 135, 135, 183, 202, 389, 132, 132, 352, 156, 156, 156, 156, 233, 251, 306, 136, 136, 136, 136, 180, 341, 136, 136, 157, 173, 212, 262, 326, 135, 135, 136, 136, 153, 190, 341, 135, 135, 193, 221, 0, 0, 0, 0, 813, 813, 813, 813, 1075, 1075, 1075, 1075, 1168, 1197, 954, 954, 978, 978, 1013, 1040, 1087, 1150, 1202, 1254, 1287, 1330, 954, 954, 980, 1049, 1069, 1088, 1105, 1117, 1158, 1207, 1235, 1246, 1289, 1304, 1328, 1364, 1097, 1097, 1097, 1097, 1116, 1190, 1560, 1560, 1560, 1560, 1581, 1647, 1836, 1873, 1560, 1560, 1560, 1560, 1620, 1620, 1621, 1621, 1670, 1696, 1734, 1747, 1772, 1621, 1621, 1670, 1697, 1734, 1748, 1800, 1814, 1621, 1621, 1701, 1720, 1751, 1784, 1814, 1840, 1620, 1620, 1647, 1687, 1628, 1628, 1631, 1631, 1693, 1827, 1862, 1628, 1628, 1741, 1786, 1815, 1833], "top": [0, 10, 10, 10, 10, 16, 63, 63, 63, 63, 103, 103, 143, 143, 143, 143, 995, 995, 995, 995, 65, 65, 65, 65, 116, 116, 116, 116, 117, 120, 118, 120, 120, 117, 136, 136, 136, 136, 162, 162, 162, 162, 882, 882, 882, 882, 969, 969, 969, 969, 839, 839, 839, 839, 172, 172, 172, 172, 172, 172, 172, 173, 173, 191, 191, 192, 193, 193, 193, 197, 193, 196, 244, 244, 244, 244, 244, 244, 244, 245, 245, 264, 266, 256, 265, 256, 265, 269, 265, 316, 316, 316, 316, 316, 316, 316, 317, 317, 337, 337, 337, 337, 337, 337, 386, 386, 386, 386, 388, 391, 388, 386, 389, 389, 409, 409, 409, 409, 409, 451, 451, 451, 451, 451, 461, 480, 481, 472, 481, 472, 481, 472, 481, 532, 532, 532, 532, 532, 533, 533, 553, 553, 553, 553, 602, 602, 602, 602, 604, 602, 602, 602, 605, 676, 676, 676, 676, 676, 676, 676, 676, 677, 697, 697, 697, 697, 697, 746, 746, 746, 748, 748, 749, 769, 769, 769, 769, 769, 811, 811, 821, 839, 839, 839, 841, 839, 839, 840, 892, 892, 892, 892, 892, 893, 913, 913, 913, 913, 914, 913, 913, 964, 964, 964, 964, 955, 955, 965, 985, 985, 985, 985, 1065, 1065, 1065, 1065, 1041, 1041, 1041, 1041, 533, 533, 533, 533, 533, 533, 567, 567, 567, 567, 567, 570, 570, 567, 567, 570, 567, 567, 587, 587, 587, 590, 590, 588, 587, 587, 587, 587, 587, 587, 588, 587, 590, 588, 970, 970, 970, 971, 970, 970, 891, 891, 891, 894, 892, 891, 895, 892, 931, 931, 931, 931, 927, 927, 927, 928, 928, 927, 927, 927, 927, 947, 947, 947, 947, 950, 950, 950, 947, 965, 966, 966, 965, 965, 965, 965, 965, 983, 984, 984, 983, 1044, 1044, 1044, 1048, 1045, 1044, 1044, 1048, 1056, 1048, 1044, 1060, 1049], "width": [1920, 86, 86, 86, 20, 56, 28, 28, 28, 28, 12, 12, 16, 16, 16, 16, 24, 24, 24, 24, 49, 49, 49, 49, 178, 178, 178, 11, 41, 13, 27, 7, 25, 25, 324, 324, 324, 324, 54, 54, 54, 54, 46, 46, 46, 46, 22, 22, 22, 22, 24, 24, 24, 24, 266, 266, 266, 34, 33, 30, 37, 28, 17, 248, 75, 5, 26, 31, 20, 3, 14, 24, 265, 265, 265, 35, 48, 7, 20, 28, 17, 240, 14, 5, 151, 27, 70, 4, 7, 266, 266, 266, 54, 20, 37, 69, 28, 17, 132, 14, 31, 18, 12, 37, 265, 265, 265, 12, 28, 32, 41, 50, 27, 17, 128, 40, 20, 13, 35, 269, 269, 269, 37, 28, 15, 247, 11, 8, 151, 25, 77, 4, 17, 266, 266, 266, 34, 30, 28, 17, 165, 77, 22, 56, 267, 267, 267, 49, 61, 12, 6, 12, 50, 267, 267, 267, 65, 13, 10, 19, 34, 50, 153, 23, 19, 28, 64, 271, 268, 266, 35, 61, 50, 268, 43, 12, 37, 14, 270, 49, 50, 226, 226, 226, 58, 13, 49, 76, 266, 266, 266, 39, 19, 61, 249, 15, 12, 34, 45, 60, 59, 267, 267, 266, 10, 30, 37, 61, 251, 53, 23, 165, 400, 400, 400, 400, 208, 208, 208, 208, 198, 198, 198, 87, 24, 76, 440, 440, 392, 29, 22, 42, 59, 47, 48, 28, 38, 40, 440, 22, 64, 14, 15, 12, 7, 35, 44, 22, 4, 38, 11, 20, 32, 30, 154, 154, 154, 8, 68, 61, 321, 321, 321, 8, 62, 29, 2, 8, 39, 39, 39, 39, 245, 245, 198, 45, 23, 33, 9, 20, 47, 213, 44, 23, 32, 9, 46, 9, 20, 244, 76, 14, 25, 29, 26, 21, 25, 93, 22, 35, 26, 271, 271, 245, 6, 22, 28, 14, 271, 12, 57, 13, 16, 66], "height": [1080, 20, 20, 20, 20, 12, 56, 56, 16, 16, 16, 16, 16, 16, 16, 16, 26, 26, 26, 26, 15, 15, 15, 15, 11, 11, 11, 11, 10, 7, 9, 7, 7, 10, 3, 3, 3, 3, 630, 630, 630, 630, 50, 50, 50, 50, 15, 15, 15, 15, 16, 16, 16, 16, 34, 34, 10, 10, 10, 10, 10, 9, 9, 15, 12, 12, 10, 12, 13, 3, 10, 10, 34, 34, 13, 10, 10, 10, 13, 9, 9, 14, 9, 29, 12, 29, 13, 3, 10, 34, 34, 10, 10, 10, 10, 10, 9, 9, 13, 10, 10, 10, 11, 13, 36, 36, 15, 11, 13, 7, 10, 12, 9, 9, 13, 13, 10, 10, 10, 43, 43, 29, 29, 29, 9, 14, 10, 29, 12, 29, 13, 29, 10, 34, 34, 13, 10, 13, 9, 9, 13, 10, 13, 13, 15, 15, 15, 15, 10, 11, 11, 11, 12, 34, 34, 13, 10, 10, 10, 10, 10, 12, 13, 10, 13, 10, 11, 94, 87, 15, 13, 10, 12, 13, 10, 11, 13, 12, 29, 29, 12, 15, 15, 15, 10, 12, 15, 11, 34, 34, 13, 10, 13, 9, 13, 10, 10, 13, 12, 10, 10, 34, 34, 10, 10, 29, 29, 9, 13, 13, 13, 13, 3, 3, 3, 3, 34, 34, 34, 34, 18, 18, 18, 18, 14, 14, 33, 33, 13, 10, 10, 7, 10, 10, 13, 10, 13, 10, 13, 10, 13, 7, 10, 9, 10, 10, 10, 10, 10, 13, 9, 10, 7, 9, 13, 13, 13, 9, 10, 13, 10, 10, 10, 7, 8, 9, 2, 8, 37, 37, 37, 37, 69, 69, 14, 10, 10, 11, 11, 11, 14, 13, 10, 10, 10, 7, 10, 7, 10, 14, 13, 10, 14, 14, 11, 11, 11, 13, 10, 10, 13, 24, 24, 15, 11, 8, 8, 8, 20, 8, 15, 35, 8, 19], "conf": [-1, -1, -1, -1, 0, 0, -1, -1, -1, 8, -1, 91, -1, -1, -1, 21, -1, -1, -1, 95, -1, -1, -1, 96, -1, -1, -1, 37, 96, 96, 90, 96, 96, 96, -1, -1, -1, 95, -1, -1, -1, 95, -1, -1, -1, 95, -1, -1, -1, 95, -1, -1, -1, 95, -1, -1, -1, 51, 94, 96, 96, 84, 85, -1, 26, 47, 93, 25, 25, 0, 96, 93, -1, -1, -1, 92, 96, 82, 82, 71, 73, -1, 57, 30, 37, 34, 34, 75, 96, -1, -1, -1, 68, 93, 96, 77, 59, 96, -1, 96, 96, 87, 88, 96, -1, -1, -1, 32, 85, 96, 93, 0, 51, 94, -1, 96, 94, 13, 95, -1, -1, -1, 96, 83, 88, -1, 22, 49, 43, 35, 35, 87, 88, -1, -1, -1, 68, 96, 81, 94, -1, 89, 91, 68, -1, -1, -1, 14, 90, 47, 0, 12, 75, -1, -1, -1, 91, 93, 93, 82, 82, 95, -1, 89, 85, 92, 72, -1, -1, -1, 92, 5, 95, -1, 92, 87, 96, 41, -1, 93, 95, -1, -1, -1, 88, 0, 0, 0, -1, -1, -1, 96, 87, 91, -1, 36, 36, 93, 93, 92, 91, -1, -1, -1, 16, 16, 35, 91, -1, 68, 87, 84, -1, -1, -1, 95, -1, -1, -1, 95, -1, -1, -1, 84, 96, 95, -1, -1, -1, 96, 96, 93, 94, 96, 95, 96, 96, 96, -1, 93, 92, 96, 96, 95, 95, 95, 95, 96, 95, 95, 96, 96, 96, 85, -1, -1, -1, 73, 73, 95, -1, -1, -1, 50, 26, 89, 25, 46, -1, -1, -1, 46, -1, -1, -1, 92, 90, 88, 88, 96, 96, -1, 92, 85, 94, 96, 96, 96, 96, -1, 95, 96, 95, 96, 96, 94, 95, -1, 96, 96, 96, -1, -1, -1, 22, 40, 68, 68, -1, 0, 17, 14, 11, 0], "text": ["", "", "", "", "@", "wrossep", "", "", "", "16", "", "&", "", "", "", "&", "", "", "", " ", "", "", "", "chats", "", "", "", "\u00a9", "search", "or", "start", "a", "new", "chat", "", "", "", " ", "", "", "", " ", "", "", "", " ", "", "", "", " ", "", "", "", " ", "", "", "", "aiml", "boys", "and", "girls", "09:48", "am", "", "~kavi@@g...:", "b", "daa", "(pdp)", "pdf", "-", "75", "pa...", "", "", "", "indhu", "prakash", "2", "cig", "09:32.", "am", "", "/", "\u00a9", "presentation", "first", "review.pptx", "-", "8.", "", "", "", "cheran", "8-f", "girls", "2023-2024", "09:19", "am", "", "kk", "class", "sir", "@", "image", "", "", "", "3%", "holy", "cross", "school", "mates#e", "02:01", "am", "", "ramya", "sch:", "oi!", "video", "", "", "", "deva", "07:56", "am", "", "y", "\u00a9", "presentation", "first", "review.pptx", "-", "8...", "", "", "", "aiml", "boyz", "07:36", "am", "", "keerthivasan", "clg:", "niggwatt", "", "", "", "child", "collection", "&", "%", "3", "yesterday", "", "", "", "2021-2025", "al", "&", "ml", "batch", "yesterday", "", "coa", "clg:", "dear", "students...", "", "", "", "dhiya", "collection", "yesterday", "", "abitha:", "@", "image", "cg", "", "karthik", "yesterday", "", "", "", "facebook", ")o)", "@\\b5s", "severe...", "", "", "", "rohan", "clg", "24-11-2023", "", "yw", "|d", "verify", "pannitu", "certificate", "eduthuko", "", "", "", "iil", "year", "aiml.", "24-11-2023", "", "cibirajan", "clg:", "https://docs.google.com/...", "", "", "", " ", "", "", "", " ", "", "", "", "whatsapp", "for", "windows", "", "", "", "send", "and", "receive", "messages", "without", "keeping", "your", "phone", "online.", "", "use", "whatsapp", "on", "up", "to", "4", "linked", "devices", "and", "1", "phone", "at", "the", "same", "time,", "", "", "", "8", "end-to-end", "encrypted", "", "", "", "@", "nvdiartx", "voice", "-", "xx", "", "", "", "@", "", "", "", "nvidia", "rtx", "voice", "is", "still", "running", "", "nvidia", "rtx", "voice", "is", "running", "in", "the", "", "background.", "to", "quit,", "right", "click", "this", "icon", "", "and", "select", "quit", "", "", "", "9", "ing", "1008", "am", "", "%", "pw)", "\u00ae", "ae", "s1-2003"]} -------------------------------------------------------------------------------- /tkinter_test.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "from pydub.silence import split_on_silence\n", 10 | "import speech_recognition as sr\n", 11 | "from pydub import AudioSegment\n", 12 | "import tkinter as tk\n", 13 | "import pyautogui\n", 14 | "import whisper\n", 15 | "import tempfile\n", 16 | "import torch\n", 17 | "import numpy as np\n", 18 | "import time\n", 19 | "import whisper\n", 20 | "import threading\n", 21 | "import keyboard\n", 22 | "import data_analyzer\n", 23 | "import tasks\n", 24 | "import os\n", 25 | "import io" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [ 33 | { 34 | "name": "stdout", 35 | "output_type": "stream", 36 | "text": [ 37 | "------------iteration----------\n", 38 | "transcribed_text {'text': ''}\n", 39 | "sentence {'text': ''} \n", 40 | "[]\n", 41 | "final prob = 0.5229412317276001\n", 42 | "can't find command\n", 43 | "command = None\n", 44 | "transcribed_text {'text': ''}\n", 45 | "sentence {'text': ''} \n", 46 | "[]\n", 47 | "final prob = 0.5229412317276001\n", 48 | "can't find command\n", 49 | "command = None\n", 50 | "transcribed_text {'text': ''}\n", 51 | "sentence {'text': ''} \n", 52 | "[]\n", 53 | "final prob = 0.5229412317276001\n", 54 | "can't find command\n", 55 | "command = None\n", 56 | "------------iteration----------\n", 57 | "------------iteration----------\n", 58 | "transcribed_text {'text': ''}\n", 59 | "sentence {'text': ''} \n", 60 | "[]\n", 61 | "final prob = 0.5229412317276001\n", 62 | "can't find command\n", 63 | "command = None\n", 64 | "transcribed_text {'text': ''}\n", 65 | "sentence {'text': ''} \n", 66 | "[]\n", 67 | "final prob = 0.5229412317276001\n", 68 | "can't find command\n", 69 | "command = None\n", 70 | "transcribed_text {'text': ''}\n", 71 | "sentence {'text': ''} \n", 72 | "[]\n", 73 | "final prob = 0.5229412317276001\n", 74 | "can't find command\n", 75 | "command = None\n", 76 | "transcribed_text {'text': ''}\n", 77 | "sentence {'text': ''} \n", 78 | "[]\n", 79 | "final prob = 0.5229412317276001\n", 80 | "can't find command\n", 81 | "command = None\n", 82 | "------------iteration----------\n", 83 | "------------iteration----------\n", 84 | "------------iteration----------\n", 85 | "------------iteration----------\n", 86 | "------------iteration----------\n", 87 | "------------iteration----------\n", 88 | "------------iteration----------\n", 89 | "------------iteration----------\n", 90 | "------------iteration----------\n", 91 | "------------iteration----------\n", 92 | "------------iteration----------\n", 93 | "------------iteration----------\n", 94 | "------------iteration----------\n", 95 | "------------iteration----------\n", 96 | "------------iteration----------\n", 97 | "------------iteration----------\n", 98 | "------------iteration----------\n", 99 | "------------iteration----------\n", 100 | "------------iteration----------\n", 101 | "------------iteration----------\n", 102 | "------------iteration----------\n", 103 | "------------iteration----------\n", 104 | "------------iteration----------\n", 105 | "------------iteration----------\n", 106 | "------------iteration----------\n", 107 | "------------iteration----------\n", 108 | "------------iteration----------\n", 109 | "------------iteration----------\n", 110 | "------------iteration----------\n", 111 | "------------iteration----------\n", 112 | "------------iteration----------\n", 113 | "------------iteration----------\n", 114 | "------------iteration----------\n", 115 | "------------iteration----------\n", 116 | "------------iteration----------\n", 117 | "------------iteration----------\n", 118 | "------------iteration----------\n", 119 | "------------iteration----------\n", 120 | "------------iteration----------\n", 121 | "------------iteration----------\n", 122 | "------------iteration----------\n", 123 | "------------iteration----------\n", 124 | "------------iteration----------\n", 125 | "------------iteration----------\n", 126 | "------------iteration----------\n", 127 | "------------iteration----------\n", 128 | "------------iteration----------\n", 129 | "------------iteration----------\n", 130 | "------------iteration----------\n", 131 | "------------iteration----------\n", 132 | "------------iteration----------\n", 133 | "------------iteration----------\n", 134 | "------------iteration----------\n", 135 | "------------iteration----------\n", 136 | "------------iteration----------\n", 137 | "------------iteration----------\n", 138 | "------------iteration----------\n", 139 | "------------iteration----------\n", 140 | "------------iteration----------\n", 141 | "------------iteration----------\n", 142 | "------------iteration----------\n", 143 | "------------iteration----------\n", 144 | "------------iteration----------\n", 145 | "------------iteration----------\n", 146 | "------------iteration----------\n", 147 | "------------iteration----------\n", 148 | "------------iteration----------\n", 149 | "------------iteration----------\n", 150 | "------------iteration----------\n", 151 | "------------iteration----------\n", 152 | "------------iteration----------\n", 153 | "------------iteration----------\n", 154 | "------------iteration----------\n", 155 | "------------iteration----------\n", 156 | "------------iteration----------\n", 157 | "------------iteration----------\n", 158 | "------------iteration----------\n", 159 | "------------iteration----------\n", 160 | "------------iteration----------\n", 161 | "------------iteration----------\n", 162 | "------------iteration----------\n", 163 | "transcribed_text {'text': 'increase the volume'}\n", 164 | "sentence {'text': 'increase the volume'} \n", 165 | "['increas', 'the', 'volum']\n", 166 | "final prob = 0.9764873385429382\n", 167 | "command found\n", 168 | "command = volume(1)\n" 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "listening_status = \"None\"\n", 174 | "transcribed_text = \"\"\n", 175 | "\n", 176 | "def speech_to_text(initiate):\n", 177 | " \n", 178 | " if initiate:\n", 179 | " window.lift()\n", 180 | " time.sleep(0.1)\n", 181 | " pyautogui.moveTo(20,1050)\n", 182 | " pyautogui.click()\n", 183 | "\n", 184 | " pyautogui.hotkey('win','h')\n", 185 | "\n", 186 | " text = text_entry.get()\n", 187 | "\n", 188 | " transcribed_text = {\"text\":text}\n", 189 | " \n", 190 | " return transcribed_text\n", 191 | " \n", 192 | "def reset():\n", 193 | " text_entry.delete(0,\"end\")\n", 194 | " pyautogui.press('esc')\n", 195 | "\n", 196 | "\n", 197 | "def execute_command():\n", 198 | " global is_listening\n", 199 | " \n", 200 | " while True:\n", 201 | " key_input = None\n", 202 | " key_input = keyboard.read_key()\n", 203 | "\n", 204 | " print(\"------------iteration----------\")\n", 205 | "\n", 206 | " if key_input == 'ctrl':\n", 207 | " if not is_listening:\n", 208 | " is_listening = True\n", 209 | " speech_to_text(initiate = True)\n", 210 | " while is_listening:\n", 211 | "\n", 212 | " transcribed_text = speech_to_text(initiate=False)\n", 213 | " print(\"transcribed_text\",transcribed_text)\n", 214 | "\n", 215 | " command = data_analyzer.analyze_command(transcribed_text)\n", 216 | " print(\"command = \",command)\n", 217 | "\n", 218 | " if command != None:\n", 219 | " exec(\"tasks.\"+command)\n", 220 | " tasks.speak(\"command executed\")\n", 221 | "\n", 222 | " reset()\n", 223 | " is_listening = False\n", 224 | " time.sleep(0.5)\n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | "\n", 230 | "def monitor():\n", 231 | " global is_listening\n", 232 | " while True:\n", 233 | " key_input = None\n", 234 | " key_input = keyboard.read_key()\n", 235 | " if key_input == 'alt':\n", 236 | " is_listening = False\n", 237 | " reset()\n", 238 | "\n", 239 | "\n", 240 | "\n", 241 | "window = tk.Tk()\n", 242 | "window.geometry(f\"{400}x{30}+{0}+{1040}\")\n", 243 | "window.attributes('-topmost', True)\n", 244 | "window.overrideredirect(True)\n", 245 | "window.configure(bg=\"#202020\")\n", 246 | "window.geometry(\"400x150\")\n", 247 | "\n", 248 | "\n", 249 | "text_entry = tk.Entry(window,width=300,font=(\"Helvetica\", 15),bg='#202020',fg='white')\n", 250 | "text_entry.grid(row=0, column=0)\n", 251 | "\n", 252 | "is_listening = False\n", 253 | "\n", 254 | "\n", 255 | "command_execution_thread = threading.Thread(target=execute_command)\n", 256 | "command_execution_thread.start()\n", 257 | "monitor_execution_thread = threading.Thread(target=monitor)\n", 258 | "monitor_execution_thread.start()\n", 259 | "\n", 260 | "window.mainloop()\n", 261 | "\n", 262 | "\n" 263 | ] 264 | }, 265 | { 266 | "cell_type": "code", 267 | "execution_count": 1, 268 | "metadata": {}, 269 | "outputs": [ 270 | { 271 | "ename": "SyntaxError", 272 | "evalue": "invalid syntax (461832017.py, line 11)", 273 | "output_type": "error", 274 | "traceback": [ 275 | "\u001b[1;36m File \u001b[1;32m\"C:\\Users\\Lenovo\\AppData\\Local\\Temp\\ipykernel_14240\\461832017.py\"\u001b[1;36m, line \u001b[1;32m11\u001b[0m\n\u001b[1;33m text_entry = tk.Entry(window)\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" 276 | ] 277 | } 278 | ], 279 | "source": [ 280 | "import tkinter as tk\n", 281 | "\n", 282 | "\n", 283 | "window = tk.Tk()\n", 284 | "window.geometry(f\"{400}x{30}+{760}+{750}\")\n", 285 | "window.overrideredirect(True)\n", 286 | "#window.config(bg = '#add123')\n", 287 | "#window.wm_attributes('-transparentcolor','#add123')\n", 288 | "\n", 289 | "\n", 290 | "text_entry = tk.Entry(window)\n", 291 | "text_entry.pack()\n", 292 | "\n", 293 | "\n", 294 | "\n", 295 | "\n", 296 | "window.mainloop()" 297 | ] 298 | }, 299 | { 300 | "cell_type": "code", 301 | "execution_count": 6, 302 | "metadata": {}, 303 | "outputs": [], 304 | "source": [ 305 | "import os\n", 306 | "import subprocess\n", 307 | "\n", 308 | "x = subprocess.run('powershell -Command \"Get-Ciminstance -Namespace root/WMI -ClassName WmiMonitorBrightness | Select -ExpandProperty \"CurrentBrightness\"\"',capture_output=True)" 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "execution_count": 40, 314 | "metadata": {}, 315 | "outputs": [ 316 | { 317 | "data": { 318 | "text/plain": [ 319 | "CompletedProcess(args='powershell (Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1,70)', returncode=0)" 320 | ] 321 | }, 322 | "execution_count": 40, 323 | "metadata": {}, 324 | "output_type": "execute_result" 325 | } 326 | ], 327 | "source": [ 328 | "\n", 329 | "brightness_value = subprocess.run('powershell -Command \"Get-Ciminstance -Namespace root/WMI -ClassName WmiMonitorBrightness | Select -ExpandProperty \"CurrentBrightness\"\"',capture_output=True)\n", 330 | "\n", 331 | "\n", 332 | "subprocess.run('powershell (Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1,'+str(int(brightness_value.stdout)+30)+')')" 333 | ] 334 | }, 335 | { 336 | "cell_type": "code", 337 | "execution_count": 2, 338 | "metadata": {}, 339 | "outputs": [ 340 | { 341 | "name": "stdout", 342 | "output_type": "stream", 343 | "text": [ 344 | "Temperature is 29°C\n", 345 | "Time: Sunday 11:35 am\n", 346 | "Sky Description: Mostly Cloudy\n", 347 | ".\n" 348 | ] 349 | } 350 | ], 351 | "source": [ 352 | "# importing library\n", 353 | "import requests\n", 354 | "from bs4 import BeautifulSoup\n", 355 | " \n", 356 | "# enter city name\n", 357 | "city = \"karur\"\n", 358 | " \n", 359 | "# creating url and requests instance\n", 360 | "url = \"https://www.google.com/search?q=\"+\"weather\"+city\n", 361 | "html = requests.get(url).content\n", 362 | " \n", 363 | "# getting raw data\n", 364 | "soup = BeautifulSoup(html, 'html.parser')\n", 365 | "temp = soup.find('div', attrs={'class': 'BNeawe iBp4i AP7Wnd'}).text\n", 366 | "str = soup.find('div', attrs={'class': 'BNeawe tAd8D AP7Wnd'}).text\n", 367 | " \n", 368 | "# formatting data\n", 369 | "data = str.split('\\n')\n", 370 | "time = data[0]\n", 371 | "sky = data[1]\n", 372 | " \n", 373 | "# getting all div tag\n", 374 | "listdiv = soup.findAll('div', attrs={'class': 'BNeawe s3v9rd AP7Wnd'})\n", 375 | "strd = listdiv[5].text\n", 376 | " \n", 377 | "# getting other required data\n", 378 | "pos = strd.find('Wind')\n", 379 | "other_data = strd[pos:]\n", 380 | " \n", 381 | "# printing all data\n", 382 | "print(\"Temperature is\", temp)\n", 383 | "print(\"Time: \", time)\n", 384 | "print(\"Sky Description: \", sky)\n", 385 | "print(other_data)" 386 | ] 387 | }, 388 | { 389 | "cell_type": "code", 390 | "execution_count": 4, 391 | "metadata": {}, 392 | "outputs": [ 393 | { 394 | "ename": "WebDriverException", 395 | "evalue": "Message: disconnected: not connected to DevTools\n (failed to check if window was closed: disconnected: not connected to DevTools)\n (Session info: chrome=119.0.6045.106)\nStacktrace:\n\tGetHandleVerifier [0x00007FF7E7A782B2+55298]\n\t(No symbol) [0x00007FF7E79E5E02]\n\t(No symbol) [0x00007FF7E78A05AB]\n\t(No symbol) [0x00007FF7E788D1AA]\n\t(No symbol) [0x00007FF7E788D9CE]\n\t(No symbol) [0x00007FF7E788D900]\n\t(No symbol) [0x00007FF7E78826EB]\n\t(No symbol) [0x00007FF7E7881250]\n\t(No symbol) [0x00007FF7E78809B6]\n\t(No symbol) [0x00007FF7E792E2E9]\n\t(No symbol) [0x00007FF7E79020AA]\n\t(No symbol) [0x00007FF7E791AAA4]\n\t(No symbol) [0x00007FF7E7901E83]\n\t(No symbol) [0x00007FF7E78D670A]\n\t(No symbol) [0x00007FF7E78D7964]\n\tGetHandleVerifier [0x00007FF7E7DF0AAB+3694587]\n\tGetHandleVerifier [0x00007FF7E7E4728E+4048862]\n\tGetHandleVerifier [0x00007FF7E7E3F173+4015811]\n\tGetHandleVerifier [0x00007FF7E7B147D6+695590]\n\t(No symbol) [0x00007FF7E79F0CE8]\n\t(No symbol) [0x00007FF7E79ECF34]\n\t(No symbol) [0x00007FF7E79ED062]\n\t(No symbol) [0x00007FF7E79DD3A3]\n\tBaseThreadInitThunk [0x00007FFE5D0E257D+29]\n\tRtlUserThreadStart [0x00007FFE5E4AAA78+40]\n", 396 | "output_type": "error", 397 | "traceback": [ 398 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 399 | "\u001b[1;31mWebDriverException\u001b[0m Traceback (most recent call last)", 400 | "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_17364\\1402014278.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mchrome\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mapplication_tasks\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mchrome\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mchrome\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmaximize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[0mchrome\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msearch\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"https://www.google.com/search?q=\"\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;34m\"weather\"\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;34m\"karur\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 401 | "\u001b[1;32md:\\mini_project\\application_tasks.py\u001b[0m in \u001b[0;36mmaximize\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 47\u001b[0m \u001b[0mdriver\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0murl\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 48\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mmaximize\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 49\u001b[1;33m \u001b[0mdriver\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmaximize_window\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 50\u001b[0m \u001b[1;32mclass\u001b[0m \u001b[0myoutube\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 51\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mplay_video_by_count\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mvalue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 402 | "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\selenium\\webdriver\\remote\\webdriver.py\u001b[0m in \u001b[0;36mmaximize_window\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 605\u001b[0m \"\"\"\n\u001b[0;32m 606\u001b[0m \u001b[0mcommand\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mCommand\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mW3C_MAXIMIZE_WINDOW\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 607\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcommand\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 608\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 609\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mfullscreen_window\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m->\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 403 | "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\selenium\\webdriver\\remote\\webdriver.py\u001b[0m in \u001b[0;36mexecute\u001b[1;34m(self, driver_command, params)\u001b[0m\n\u001b[0;32m 442\u001b[0m \u001b[0mresponse\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcommand_executor\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdriver_command\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 443\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mresponse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 444\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merror_handler\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcheck_response\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresponse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 445\u001b[0m \u001b[0mresponse\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"value\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_unwrap_value\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresponse\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"value\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 446\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mresponse\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 404 | "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\selenium\\webdriver\\remote\\errorhandler.py\u001b[0m in \u001b[0;36mcheck_response\u001b[1;34m(self, response)\u001b[0m\n\u001b[0;32m 247\u001b[0m \u001b[0malert_text\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"alert\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"text\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 248\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mexception_class\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mscreen\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstacktrace\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0malert_text\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# type: ignore[call-arg] # mypy is not smart enough here\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 249\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mexception_class\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mscreen\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstacktrace\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 405 | "\u001b[1;31mWebDriverException\u001b[0m: Message: disconnected: not connected to DevTools\n (failed to check if window was closed: disconnected: not connected to DevTools)\n (Session info: chrome=119.0.6045.106)\nStacktrace:\n\tGetHandleVerifier [0x00007FF7E7A782B2+55298]\n\t(No symbol) [0x00007FF7E79E5E02]\n\t(No symbol) [0x00007FF7E78A05AB]\n\t(No symbol) [0x00007FF7E788D1AA]\n\t(No symbol) [0x00007FF7E788D9CE]\n\t(No symbol) [0x00007FF7E788D900]\n\t(No symbol) [0x00007FF7E78826EB]\n\t(No symbol) [0x00007FF7E7881250]\n\t(No symbol) [0x00007FF7E78809B6]\n\t(No symbol) [0x00007FF7E792E2E9]\n\t(No symbol) [0x00007FF7E79020AA]\n\t(No symbol) [0x00007FF7E791AAA4]\n\t(No symbol) [0x00007FF7E7901E83]\n\t(No symbol) [0x00007FF7E78D670A]\n\t(No symbol) [0x00007FF7E78D7964]\n\tGetHandleVerifier [0x00007FF7E7DF0AAB+3694587]\n\tGetHandleVerifier [0x00007FF7E7E4728E+4048862]\n\tGetHandleVerifier [0x00007FF7E7E3F173+4015811]\n\tGetHandleVerifier [0x00007FF7E7B147D6+695590]\n\t(No symbol) [0x00007FF7E79F0CE8]\n\t(No symbol) [0x00007FF7E79ECF34]\n\t(No symbol) [0x00007FF7E79ED062]\n\t(No symbol) [0x00007FF7E79DD3A3]\n\tBaseThreadInitThunk [0x00007FFE5D0E257D+29]\n\tRtlUserThreadStart [0x00007FFE5E4AAA78+40]\n" 406 | ] 407 | } 408 | ], 409 | "source": [ 410 | "import application_tasks\n", 411 | "\n", 412 | "chrome = application_tasks.chrome()\n", 413 | "chrome.maximize()\n", 414 | "chrome.search(\"https://www.google.com/search?q=\"+\"weather\"+\"karur\")\n" 415 | ] 416 | }, 417 | { 418 | "cell_type": "code", 419 | "execution_count": 7, 420 | "metadata": {}, 421 | "outputs": [ 422 | { 423 | "ename": "NameError", 424 | "evalue": "name 'BeautifulSoup' is not defined", 425 | "output_type": "error", 426 | "traceback": [ 427 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 428 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 429 | "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_24320\\356360445.py\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[0mhtml\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcontent\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m \u001b[0msoup\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mBeautifulSoup\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhtml\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'html.parser'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 13\u001b[0m \u001b[0mtemp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msoup\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfind\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'div'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mattrs\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m{\u001b[0m\u001b[1;34m'class'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'BNeawe iBp4i AP7Wnd'\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 14\u001b[0m \u001b[0mstr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msoup\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfind\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'div'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mattrs\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m{\u001b[0m\u001b[1;34m'class'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'BNeawe tAd8D AP7Wnd'\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 430 | "\u001b[1;31mNameError\u001b[0m: name 'BeautifulSoup' is not defined" 431 | ] 432 | } 433 | ], 434 | "source": [ 435 | "import application_tasks\n", 436 | "import requests\n", 437 | "chrome = application_tasks.chrome()\n", 438 | "chrome.maximize()\n", 439 | "chrome.search(\"https://www.google.com/search?q=\"+\"weather\"+\"karur\")\n", 440 | "\n", 441 | "city = \"karur\"\n", 442 | "\n", 443 | "url = \"https://www.google.com/search?q=\"+\"weather\"+city\n", 444 | "html = requests.get(url).content\n", 445 | "\n", 446 | "soup = BeautifulSoup(html, 'html.parser')\n", 447 | "temp = soup.find('div', attrs={'class': 'BNeawe iBp4i AP7Wnd'}).text\n", 448 | "str = soup.find('div', attrs={'class': 'BNeawe tAd8D AP7Wnd'}).text\n", 449 | "\n", 450 | "data = str.split('\\n')\n", 451 | "time = data[0]\n", 452 | "sky = data[1]\n", 453 | "\n", 454 | "listdiv = soup.findAll('div', attrs={'class': 'BNeawe s3v9rd AP7Wnd'})\n", 455 | "strd = listdiv[5].text\n", 456 | "\n", 457 | "pos = strd.find('Wind')\n", 458 | "\n", 459 | "\n", 460 | "print(\"data = \",temp,sky,time)" 461 | ] 462 | }, 463 | { 464 | "cell_type": "code", 465 | "execution_count": 7, 466 | "metadata": {}, 467 | "outputs": [ 468 | { 469 | "data": { 470 | "text/plain": [ 471 | "6" 472 | ] 473 | }, 474 | "execution_count": 7, 475 | "metadata": {}, 476 | "output_type": "execute_result" 477 | } 478 | ], 479 | "source": [ 480 | "data = 'hello how are how'\n", 481 | "data.find(\"how\")" 482 | ] 483 | }, 484 | { 485 | "cell_type": "code", 486 | "execution_count": 1, 487 | "metadata": {}, 488 | "outputs": [ 489 | { 490 | "name": "stdout", 491 | "output_type": "stream", 492 | "text": [ 493 | "OPENING NOTEPAD\n" 494 | ] 495 | } 496 | ], 497 | "source": [ 498 | "import pre_analyse\n", 499 | "import tasks\n", 500 | "import time\n", 501 | "\n", 502 | "time.sleep(1)\n", 503 | "#pre_analyse.pre_analyse_command(\"open google chrome\")\n", 504 | "#exec(\"tasks.\"+str(pre_analyse.pre_analyse_command(\"click on file definition\")))\n", 505 | "#tasks.open_application(' google chrome')\n", 506 | "\n", 507 | "\n", 508 | "tasks.take_notes()" 509 | ] 510 | }, 511 | { 512 | "cell_type": "code", 513 | "execution_count": 1, 514 | "metadata": {}, 515 | "outputs": [ 516 | { 517 | "ename": "error", 518 | "evalue": "OpenCV(4.7.0) D:\\a\\opencv-python\\opencv-python\\opencv\\modules\\highgui\\src\\window.cpp:1272: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'\n", 519 | "output_type": "error", 520 | "traceback": [ 521 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 522 | "\u001b[1;31merror\u001b[0m Traceback (most recent call last)", 523 | "Cell \u001b[1;32mIn[1], line 17\u001b[0m\n\u001b[0;32m 14\u001b[0m \u001b[39mfor\u001b[39;00m (x, y, w, h) \u001b[39min\u001b[39;00m faces:\n\u001b[0;32m 15\u001b[0m cv2\u001b[39m.\u001b[39mrectangle(frame, (x, y), (x\u001b[39m+\u001b[39mw, y\u001b[39m+\u001b[39mh), (\u001b[39m255\u001b[39m, \u001b[39m0\u001b[39m, \u001b[39m0\u001b[39m), \u001b[39m2\u001b[39m)\n\u001b[1;32m---> 17\u001b[0m cv2\u001b[39m.\u001b[39;49mimshow(\u001b[39m'\u001b[39;49m\u001b[39mReal-time Face Detection\u001b[39;49m\u001b[39m'\u001b[39;49m, frame)\n\u001b[0;32m 19\u001b[0m \u001b[39mif\u001b[39;00m cv2\u001b[39m.\u001b[39mwaitKey(\u001b[39m1\u001b[39m) \u001b[39m&\u001b[39m \u001b[39m0xFF\u001b[39m \u001b[39m==\u001b[39m \u001b[39mord\u001b[39m(\u001b[39m'\u001b[39m\u001b[39mq\u001b[39m\u001b[39m'\u001b[39m):\n\u001b[0;32m 20\u001b[0m \u001b[39mbreak\u001b[39;00m\n", 524 | "\u001b[1;31merror\u001b[0m: OpenCV(4.7.0) D:\\a\\opencv-python\\opencv-python\\opencv\\modules\\highgui\\src\\window.cpp:1272: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'\n" 525 | ] 526 | } 527 | ], 528 | "source": [ 529 | "import cv2\n", 530 | "\n", 531 | "face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')\n", 532 | "\n", 533 | "cap = cv2.VideoCapture(0)\n", 534 | "while True:\n", 535 | "\n", 536 | " ret, frame = cap.read()\n", 537 | "\n", 538 | " gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\n", 539 | "\n", 540 | " faces = face_cascade.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5)\n", 541 | "\n", 542 | " for (x, y, w, h) in faces:\n", 543 | " cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)\n", 544 | "\n", 545 | " cv2.imshow('Real-time Face Detection', frame)\n", 546 | "\n", 547 | " if cv2.waitKey(1) & 0xFF == ord('q'):\n", 548 | " break\n", 549 | "\n", 550 | "cap.release()\n", 551 | "cv2.destroyAllWindows()\n" 552 | ] 553 | }, 554 | { 555 | "cell_type": "code", 556 | "execution_count": 1, 557 | "metadata": {}, 558 | "outputs": [], 559 | "source": [ 560 | "import cv2\n", 561 | "\n", 562 | "# Open the default camera (camera index 0)\n", 563 | "cap = cv2.VideoCapture(0)\n", 564 | "\n", 565 | "if not cap.isOpened():\n", 566 | " print(\"Error: Could not open camera.\")\n", 567 | "else:\n", 568 | " while True:\n", 569 | " ret, frame = cap.read()\n", 570 | " if not ret:\n", 571 | " print(\"Error: Could not read frame.\")\n", 572 | " break\n", 573 | "\n", 574 | " # Display the captured frame\n", 575 | " cv2.imshow('Camera', frame)\n", 576 | "\n", 577 | " # Press 'q' to exit the loop and close the window\n", 578 | " if cv2.waitKey(1) & 0xFF == ord('q'):\n", 579 | " break\n", 580 | "\n", 581 | " # Release the camera and close the OpenCV window\n", 582 | " cap.release()\n", 583 | " cv2.destroyAllWindows()\n" 584 | ] 585 | }, 586 | { 587 | "cell_type": "code", 588 | "execution_count": 7, 589 | "metadata": {}, 590 | "outputs": [ 591 | { 592 | "name": "stdout", 593 | "output_type": "stream", 594 | "text": [ 595 | "Cannot find screenshot_inverted.py on the screen\n" 596 | ] 597 | }, 598 | { 599 | "data": { 600 | "text/plain": [ 601 | "('Cannot find screenshot_inverted.py on the screen', False)" 602 | ] 603 | }, 604 | "execution_count": 7, 605 | "metadata": {}, 606 | "output_type": "execute_result" 607 | } 608 | ], 609 | "source": [ 610 | "import pyautogui\n", 611 | "import pytesseract\n", 612 | "import json\n", 613 | "from PIL import Image, ImageOps\n", 614 | "from pytesseract import Output\n", 615 | "\n", 616 | "def invert_image_if_needed(image):\n", 617 | " avg_color = ImageOps.exif_transpose(image).convert(\"RGB\").resize((1, 1)).getpixel((0, 0))\n", 618 | " is_dark_background = sum(avg_color) / 3 < 128\n", 619 | "\n", 620 | " if is_dark_background:\n", 621 | " inverted_image = ImageOps.invert(image)\n", 622 | " else:\n", 623 | " inverted_image = image\n", 624 | "\n", 625 | " return inverted_image.convert(\"L\")\n", 626 | "\n", 627 | "def find_text_on_screen(text):\n", 628 | " text = text.lower().strip().split() # Split multiple words\n", 629 | " myscreenshot = pyautogui.screenshot()\n", 630 | " \n", 631 | " # Invert colors if needed\n", 632 | " inverted_image = invert_image_if_needed(myscreenshot)\n", 633 | " \n", 634 | " inverted_image.save(\"D:\\\\mini_project\\\\temp\\\\screenshot_inverted.png\")\n", 635 | "\n", 636 | " data = pytesseract.image_to_data(inverted_image, output_type=Output.DICT)\n", 637 | "\n", 638 | " for i, value in enumerate(data['text']):\n", 639 | " data['text'][i] = data['text'][i].lower()\n", 640 | "\n", 641 | " with open(\"temp.json\", 'w') as f:\n", 642 | " f.write(json.dumps(data))\n", 643 | "\n", 644 | " try:\n", 645 | " # Find the indices where all words are present\n", 646 | " indices = [i for i in range(len(data['text'])) if all(word in data['text'][i].split() for word in text)]\n", 647 | "\n", 648 | " if indices:\n", 649 | " # Use the first matching index for simplicity, you may want to refine this logic\n", 650 | " x, y, width, height = data['left'][indices[0]], data['top'][indices[0]], \\\n", 651 | " data['width'][indices[0]], data['height'][indices[0]]\n", 652 | " pyautogui.moveTo(x + width / 2, y + height / 2)\n", 653 | " pyautogui.click()\n", 654 | " print(x + width / 2, y + height / 2)\n", 655 | " else:\n", 656 | " print(\"Cannot find\", ' '.join(text), \"on the screen\")\n", 657 | " return f\"Cannot find {' '.join(text)} on the screen\", False\n", 658 | " except Exception as e:\n", 659 | " print(\"Error:\", e)\n", 660 | " return f\"Error: {e}\", False\n", 661 | "\n", 662 | "\n", 663 | "find_text_on_screen(\"screenshot_inverted.py\")" 664 | ] 665 | }, 666 | { 667 | "cell_type": "code", 668 | "execution_count": null, 669 | "metadata": {}, 670 | "outputs": [], 671 | "source": [ 672 | "from chatterbot import ChatBot\n", 673 | "from chatterbot.trainers import ChatterBotCorpusTrainer\n", 674 | "\n", 675 | "chatbot = ChatBot('SimpleBot')\n", 676 | "trainer = ChatterBotCorpusTrainer(chatbot)\n", 677 | "\n", 678 | "# Train the chatbot on English language data\n", 679 | "trainer.train('chatterbot.corpus.english')\n", 680 | "\n", 681 | "# Get a response\n", 682 | "response = chatbot.get_response('Hi, how are you?')\n", 683 | "print(response)\n" 684 | ] 685 | }, 686 | { 687 | "cell_type": "code", 688 | "execution_count": 5, 689 | "metadata": {}, 690 | "outputs": [ 691 | { 692 | "name": "stderr", 693 | "output_type": "stream", 694 | "text": [ 695 | "Some weights of the model checkpoint at bert-base-uncased were not used when initializing BertForMaskedLM: ['cls.seq_relationship.weight', 'cls.seq_relationship.bias']\n", 696 | "- This IS expected if you are initializing BertForMaskedLM from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).\n", 697 | "- This IS NOT expected if you are initializing BertForMaskedLM from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).\n" 698 | ] 699 | }, 700 | { 701 | "name": "stdout", 702 | "output_type": "stream", 703 | "text": [ 704 | "response [CLS] hello [SEP] hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello\n" 705 | ] 706 | } 707 | ], 708 | "source": [ 709 | "from transformers import AutoModelWithLMHead, AutoTokenizer\n", 710 | "\n", 711 | "pre_model = \"bert-base-uncased\"\n", 712 | "\n", 713 | "tokenizer = AutoTokenizer.from_pretrained(pre_model)\n", 714 | "model = AutoModelWithLMHead.from_pretrained(pre_model)\n", 715 | "\n", 716 | "input_text = \"hello\"\n", 717 | "input_ids = tokenizer.encode(input_text, return_tensors='pt')\n", 718 | "outputs = model.generate(input_ids)\n", 719 | "\n", 720 | "# Decode the model's response and display it on the screen\n", 721 | "response = tokenizer.decode(outputs[0])\n", 722 | "print(\"response\",response)" 723 | ] 724 | }, 725 | { 726 | "cell_type": "code", 727 | "execution_count": 5, 728 | "metadata": {}, 729 | "outputs": [ 730 | { 731 | "name": "stderr", 732 | "output_type": "stream", 733 | "text": [ 734 | "The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.\n", 735 | "Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.\n" 736 | ] 737 | }, 738 | { 739 | "name": "stdout", 740 | "output_type": "stream", 741 | "text": [ 742 | "response hello.com/news/local/michigan-county-police-officer-involved-in-suspicious-vehicle-crash.html\n", 743 | "\n", 744 | "http://www.wisc.gov/crime-and-justice\n" 745 | ] 746 | } 747 | ], 748 | "source": [ 749 | "from transformers import GPT2LMHeadModel, GPT2Tokenizer\n", 750 | "\n", 751 | "pre_model = \"gpt2\"\n", 752 | "tokenizer = GPT2Tokenizer.from_pretrained(pre_model)\n", 753 | "model = GPT2LMHeadModel.from_pretrained(pre_model)\n", 754 | "\n", 755 | "input_text = \"hello\"\n", 756 | "input_ids = tokenizer.encode(input_text, return_tensors='pt')\n", 757 | "outputs = model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2, top_k=50, top_p=0.95)\n", 758 | "\n", 759 | "response = tokenizer.decode(outputs[0], skip_special_tokens=True)\n", 760 | "print(\"response\", response)\n" 761 | ] 762 | }, 763 | { 764 | "cell_type": "code", 765 | "execution_count": 12, 766 | "metadata": {}, 767 | "outputs": [ 768 | { 769 | "name": "stdout", 770 | "output_type": "stream", 771 | "text": [ 772 | "response hello how are you doing?\"\n", 773 | "\n", 774 | "\"I'm doing fine,\" she said. \"I've got a lot of work to do. I'll be back in a couple of weeks.\"\n" 775 | ] 776 | } 777 | ], 778 | "source": [ 779 | "from transformers import GPT2LMHeadModel, GPT2Tokenizer\n", 780 | "\n", 781 | "pre_model = \"gpt2\"\n", 782 | "tokenizer = GPT2Tokenizer.from_pretrained(pre_model)\n", 783 | "model = GPT2LMHeadModel.from_pretrained(pre_model)\n", 784 | "\n", 785 | "input_text = \"hello how are you\"\n", 786 | "input_ids = tokenizer.encode(input_text, return_tensors='pt')\n", 787 | "outputs = model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2, top_k=50, top_p=0.95, pad_token_id=tokenizer.eos_token_id)\n", 788 | "\n", 789 | "response = tokenizer.decode(outputs[0], skip_special_tokens=True)\n", 790 | "print(\"response\", response)\n" 791 | ] 792 | } 793 | ], 794 | "metadata": { 795 | "kernelspec": { 796 | "display_name": "base", 797 | "language": "python", 798 | "name": "python3" 799 | }, 800 | "language_info": { 801 | "codemirror_mode": { 802 | "name": "ipython", 803 | "version": 3 804 | }, 805 | "file_extension": ".py", 806 | "mimetype": "text/x-python", 807 | "name": "python", 808 | "nbconvert_exporter": "python", 809 | "pygments_lexer": "ipython3", 810 | "version": "3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]" 811 | }, 812 | "orig_nbformat": 4, 813 | "vscode": { 814 | "interpreter": { 815 | "hash": "90ae384ec8aa6644af31da6e68cfa043ca5e4f959255e106df86226e1926c12a" 816 | } 817 | } 818 | }, 819 | "nbformat": 4, 820 | "nbformat_minor": 2 821 | } 822 | -------------------------------------------------------------------------------- /yes_no.pth: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dewadharshan/Virtual-Assistant/d9b15b898aa9e4ff9182dd4fb1691befdb0b8c5a/yes_no.pth --------------------------------------------------------------------------------