diff --git a/Framework/Built_In_Automation/Desktop/CrossPlatform/BuiltInFunctions.py b/Framework/Built_In_Automation/Desktop/CrossPlatform/BuiltInFunctions.py index df186a28e..f9310271b 100644 --- a/Framework/Built_In_Automation/Desktop/CrossPlatform/BuiltInFunctions.py +++ b/Framework/Built_In_Automation/Desktop/CrossPlatform/BuiltInFunctions.py @@ -17,7 +17,6 @@ True # https://pyautogui.readthedocs.io/en/latest/ from fileinput import filename import os, os.path, sys, time, inspect, subprocess -from turtle import right from Framework.Utilities import CommonUtil, FileUtilities as FL from Framework.Utilities.decorators import logger @@ -36,7 +35,6 @@ from Framework.Utilities import ConfigModule import traceback import platform -import easyocr from thefuzz import fuzz import threading from pathlib import Path @@ -1255,16 +1253,87 @@ def keystroke_for_element(data_set): reader = None +def install_easyocr(): + sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME + + # get the OS + pltform = platform.system() + + #check easyocr installment in Windows + if pltform == "Windows": + pip_command = ['pip', 'list'] + easyocr_search_command = ['findstr', 'easyocr'] + pip_process = subprocess.Popen(pip_command, stdout=subprocess.PIPE) + search_process = subprocess.Popen(easyocr_search_command, stdin=pip_process.stdout, stdout=subprocess.PIPE,text=True) + + is_easyocr, _ = search_process.communicate() + + if is_easyocr: + CommonUtil.ExecLog( + sModuleInfo, + "Easyocr is already installed", + 5, + ) + else: + CommonUtil.ExecLog( + sModuleInfo, + "Installing Easyocr", + 5, + ) + try: + result = subprocess.run( + ['pip', 'install', '--trusted-host', 'pypi.org', '--trusted-host', 'files.pythonhosted.org', 'easyocr'], + check=True, + text=True, + capture_output=True + ) + CommonUtil.ExecLog(sModuleInfo,f"{result.stdout}",5) + except subprocess.CalledProcessError as e: + print(f"Error occurred: {e.stderr}") + else: + pip_command = ['pip3', 'list'] + easyocr_search_command = ['grep', 'easyocr'] + pip_process = subprocess.Popen(pip_command, stdout=subprocess.PIPE) + search_process = subprocess.Popen(easyocr_search_command, stdin=pip_process.stdout, stdout=subprocess.PIPE,text=True) + + is_easyocr, _ = search_process.communicate() + + if is_easyocr: + CommonUtil.ExecLog( + sModuleInfo, + "Easyocr is already installed", + 5, + ) + else: + CommonUtil.ExecLog( + sModuleInfo, + "Installing Easyocr", + 5, + ) + try: + result = subprocess.run( + ['pip3', 'install', '--trusted-host', 'pypi.org', '--trusted-host', 'files.pythonhosted.org', 'easyocr'], + check=True, + text=True, + capture_output=True + ) + CommonUtil.ExecLog(sModuleInfo,f"{result.stdout}",5) + except subprocess.CalledProcessError as e: + print(f"Error occurred: {e.stderr}") + + + # initialize the OCR def get_easyocr_reader(): sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME + install_easyocr() + import easyocr global reader if not reader: CommonUtil.ExecLog(sModuleInfo, "Initializing EasyOCR reader...", 1) reader = easyocr.Reader(['en']) else: CommonUtil.ExecLog(sModuleInfo, "EasyOCR reader already initialized.", 1) - return reader # create a list of texts def get_only_text(data:tuple): diff --git a/requirements-linux.txt b/requirements-linux.txt index e5900055c..2ac57f036 100644 --- a/requirements-linux.txt +++ b/requirements-linux.txt @@ -55,4 +55,5 @@ configobj jinja2 pandas pyperclip +thefuzz backports-datetime-fromisoformat; python_version < '3.11' \ No newline at end of file diff --git a/requirements-mac.txt b/requirements-mac.txt index 7aeeb18e8..2fe5a6cf5 100644 --- a/requirements-mac.txt +++ b/requirements-mac.txt @@ -59,4 +59,5 @@ configobj jinja2 pandas pyperclip -backports-datetime-fromisoformat; python_version < '3.11' \ No newline at end of file +backports-datetime-fromisoformat; python_version < '3.11' +thefuzz \ No newline at end of file diff --git a/requirements-win.txt b/requirements-win.txt index fc103610c..7c66bc58a 100644 --- a/requirements-win.txt +++ b/requirements-win.txt @@ -69,4 +69,5 @@ configobj jinja2 pandas pyperclip -backports-datetime-fromisoformat; python_version < '3.11' \ No newline at end of file +backports-datetime-fromisoformat; python_version < '3.11' +thefuzz