Wayland SS delegated to Grim at reduced quality for faster faster speeds

This commit is contained in:
2024-11-07 11:09:20 +11:00
parent 11600ae70f
commit 56d8c18871
9 changed files with 48 additions and 47 deletions
+4 -5
View File
@@ -192,13 +192,12 @@ class ApiModel():
#prompt = f"Without any additional remarks, and without any code, translate the following items of the Python list from {self.from_lang} into {self.target_lang} and output as a Python list ensuring proper escaping of characters and ensuring the length of the list given is exactly equal to the length of the list you provide. Do not output in any other language other than the specified target language: {texts_to_translate}"
prompt = f"""INSTRUCTIONS:
- Provide ONE and ONLY ONE translation to each text provided in the JSON array given.
- Respond using ONLY valid JSON array syntax. Do not use any Python-like dictionary syntax and therefore it must not contain any keys or curly braces.
- Do not include explanations or additional text
- The translations must preserve the original order.
- Each translation must be from the Source language to the Target language
- Source language: {self.from_lang}
- Target language: {self.target_lang}
- Texts are provided in JSON array syntax.
- Respond using ONLY valid JSON array syntax.
- Do not include explanations or additional text
- Escape special characters properly
Input texts:
@@ -212,7 +211,8 @@ Translation:"""
response_list = ast.literal_eval(response.strip())
logger.debug(repr(self))
logger.info(f'{self.model} translated texts from: {texts_to_translate} to {response_list}.')
if not isinstance(response_list, list):
raise TypeError(f"Incorrect response type. Expected list, got {type(response_list)}")
if len(response_list) != len(texts_to_translate) and len(texts_to_translate) <= MAX_TRANSLATE:
logger.error(f"{self.model} model failed to translate all the texts. Number of translations to make: {len(texts_to_translate)}; Number of translated texts: {len(response_list)}.")
if store:
@@ -220,7 +220,6 @@ Translation:"""
else:
if store:
self._db_add_translation(texts_to_translate, response_list)
print(response_list)
return response_list
class Groq(ApiModel):
-1
View File
@@ -86,7 +86,6 @@ def _id_filtered(ocr, image, lang) -> list:
def _id_lang(ocr, image, lang) -> list:
result = _identify(ocr, image)
lang = standardize_lang(lang)['id_model_lang']
print(result)
try:
filtered = [entry for entry in result if contains_lang(entry[1], lang)]
except:
+11 -17
View File
@@ -7,6 +7,7 @@ import jaconv, MeCab, unidic, pykakasi
from sklearn.metrics.pairwise import cosine_similarity
from sklearn.feature_extraction.text import TfidfVectorizer
import numpy as np
import subprocess
# for creating furigana
mecab = MeCab.Tagger('-d "{}"'.format(unidic.DICDIR))
uroman = ur.Uroman()
@@ -25,33 +26,26 @@ def intercepts(x,y):
def is_wayland():
return 'WAYLAND_DISPLAY' in os.environ
# path to save screenshot of monitor to
def printsc_wayland(region, save: bool = False, path: str = None):
if save:
im = ImageGrab.grab(bbox=region)
im.save(path)
else:
return ImageGrab.grab(bbox=region)
# please install grim otherwise this is way too slow for wayland
def printsc_wayland(region: tuple, path: str):
subprocess.run(['grim','-g', f'{region[0]},{region[1]} {region[2]-region[0]}x{region[3]-region[1]}', '-t', 'jpeg', '-q','95', path])
def printsc_non_wayland(region, save: bool = False, path: str = None):
def printsc_non_wayland(region: tuple, path: str):
# use mss to capture the screen
with mss.mss() as sct:
# grab the screen
img = sct.grab(region)
# convert the image to a PIL image
image = Image.frombytes("RGB", img.size, img.bgra, "raw", "BGRX")
# save the image if save is True
if save:
image.save(path)
image.save(path)
def printsc(region, save: bool = False, path: str = None):
def printsc(region: tuple, path: str):
try:
if is_wayland():
return printsc_wayland(region, save, path)
printsc_wayland(region, path)
else:
return printsc_non_wayland(region, save, path)
printsc_non_wayland(region, path)
except Exception as e:
print(f'Error {e}')
@@ -187,5 +181,5 @@ def similar_tfidf(list1,list2,threshold) -> float:
if __name__ == "__main__":
# Example usage
japanesetext = "本が好きにちは"
print(add_furigana(japanesetext))
x = printsc_wayland((0,0,1920,1080), save = False)
print(x)