From adf134d446d41ae87521d482eb36b7e204d98e11 Mon Sep 17 00:00:00 2001 From: lllyasviel Date: Fri, 20 Oct 2023 17:20:26 -0700 Subject: [PATCH] 100% cover all texts 100% cover all texts --- .gitignore | 1 + javascript/localization.js | 82 -------------------------------------- language/en.json | 35 ++++++++++++---- modules/gradio_hijack.py | 12 +++--- modules/localization.py | 7 +++- 5 files changed, 40 insertions(+), 97 deletions(-) diff --git a/.gitignore b/.gitignore index f29cafc..ce656b0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ __pycache__ *.patch *.backup *.corrupted +/language/default.json lena.png lena_result.png lena_test.py diff --git a/javascript/localization.js b/javascript/localization.js index 8f00c18..58c7b0a 100644 --- a/javascript/localization.js +++ b/javascript/localization.js @@ -1,26 +1,3 @@ - -// localization = {} -- the dict with translations is created by the backend - -var ignore_ids_for_localization = { - setting_sd_hypernetwork: 'OPTION', - setting_sd_model_checkpoint: 'OPTION', - modelmerger_primary_model_name: 'OPTION', - modelmerger_secondary_model_name: 'OPTION', - modelmerger_tertiary_model_name: 'OPTION', - train_embedding: 'OPTION', - train_hypernetwork: 'OPTION', - txt2img_styles: 'OPTION', - img2img_styles: 'OPTION', - setting_random_artist_categories: 'OPTION', - setting_face_restoration_model: 'OPTION', - setting_realesrgan_enabled_models: 'OPTION', - extras_upscaler_1: 'OPTION', - extras_upscaler_2: 'OPTION', -}; - -var re_num = /^[.\d]+$/; -var re_emoji = /[\p{Extended_Pictographic}\u{1F3FB}-\u{1F3FF}\u{1F9B0}-\u{1F9B3}]/u; - var original_lines = {}; var translated_lines = {}; @@ -34,28 +11,6 @@ function textNodesUnder(el) { return a; } -function canBeTranslated(node, text) { - if (!text) return false; - if (!node.parentElement) return false; - - var parentType = node.parentElement.nodeName; - if (parentType == 'SCRIPT' || parentType == 'STYLE' || parentType == 'TEXTAREA') return false; - - if (parentType == 'OPTION' || parentType == 'SPAN') { - var pnode = node; - for (var level = 0; level < 4; level++) { - pnode = pnode.parentElement; - if (!pnode) break; - - if (ignore_ids_for_localization[pnode.id] == parentType) return false; - } - } - - if (re_num.test(text)) return false; - if (re_emoji.test(text)) return false; - return true; -} - function getTranslation(text) { if (!text) return undefined; @@ -73,9 +28,6 @@ function getTranslation(text) { function processTextNode(node) { var text = node.textContent.trim(); - - if (!canBeTranslated(node, text)) return; - var tl = getTranslation(text); if (tl !== undefined) { node.textContent = tl; @@ -136,40 +88,6 @@ function localizeWholePage() { } } -function dumpTranslations() { - if (!hasLocalization()) { - // If we don't have any localization, - // we will not have traversed the app to find - // original_lines, so do that now. - localizeWholePage(); - } - var dumped = {}; - if (localization.rtl) { - dumped.rtl = true; - } - - for (const text in original_lines) { - if (dumped[text] !== undefined) continue; - dumped[text] = localization[text] || text; - } - - return dumped; -} - -function download_localization() { - var text = JSON.stringify(dumpTranslations(), null, 4); - - var element = document.createElement('a'); - element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); - element.setAttribute('download', "localization.json"); - element.style.display = 'none'; - document.body.appendChild(element); - - element.click(); - - document.body.removeChild(element); -} - document.addEventListener("DOMContentLoaded", function() { if (!hasLocalization()) { return; diff --git a/language/en.json b/language/en.json index ed25165..9ae3986 100644 --- a/language/en.json +++ b/language/en.json @@ -6,6 +6,9 @@ "Stop": "Stop", "Input Image": "Input Image", "Advanced": "Advanced", + "Upscale or Variation": "Upscale or Variation", + "Image Prompt": "Image Prompt", + "Inpaint or Outpaint (beta)": "Inpaint or Outpaint (beta)", "Drag above image to here": "Drag above image to here", "Upscale or Variation:": "Upscale or Variation:", "Disabled": "Disabled", @@ -14,22 +17,32 @@ "Upscale (1.5x)": "Upscale (1.5x)", "Upscale (2x)": "Upscale (2x)", "Upscale (Fast 2x)": "Upscale (Fast 2x)", + "\ud83d\udcd4 Document": "\uD83D\uDCD4 Document", "Image": "Image", "Stop At": "Stop At", "Weight": "Weight", "Type": "Type", - "Image Prompt": "Image Prompt", "PyraCanny": "PyraCanny", "CPDS": "CPDS", + "* \"Image Prompt\" is powered by Fooocus Image Mixture Engine (v1.0.1).": "* \"Image Prompt\" is powered by Fooocus Image Mixture Engine (v1.0.1).", + "The scaler multiplied to positive ADM (use 1.0 to disable).": "The scaler multiplied to positive ADM (use 1.0 to disable).", + "The scaler multiplied to negative ADM (use 1.0 to disable).": "The scaler multiplied to negative ADM (use 1.0 to disable).", + "When to end the guidance from positive/negative ADM.": "When to end the guidance from positive/negative ADM.", + "Similar to the Control Mode in A1111 (use 0.0 to disable).": "Similar to the Control Mode in A1111 (use 0.0 to disable).", + "Outpaint Expansion (": "Outpaint Expansion (", "Outpaint": "Outpaint", "Left": "Left", "Right": "Right", "Top": "Top", "Bottom": "Bottom", + "* \"Inpaint or Outpaint\" is powered by the sampler \"DPMPP Fooocus Seamless 2M SDE Karras Inpaint Sampler\" (beta)": "* \"Inpaint or Outpaint\" is powered by the sampler \"DPMPP Fooocus Seamless 2M SDE Karras Inpaint Sampler\" (beta)", + "Setting": "Setting", + "Style": "Style", "Performance": "Performance", "Speed": "Speed", "Quality": "Quality", "Aspect Ratios": "Aspect Ratios", + "896\u00d71152": "896\u00d71152", "width \u00d7 height": "width \u00d7 height", "704\u00d71408": "704\u00d71408", "704\u00d71344": "704\u00d71344", @@ -37,7 +50,6 @@ "768\u00d71280": "768\u00d71280", "832\u00d71216": "832\u00d71216", "832\u00d71152": "832\u00d71152", - "896\u00d71152": "896\u00d71152", "896\u00d71088": "896\u00d71088", "960\u00d71088": "960\u00d71088", "960\u00d71024": "960\u00d71024", @@ -45,7 +57,6 @@ "1024\u00d7960": "1024\u00d7960", "1088\u00d7960": "1088\u00d7960", "1088\u00d7896": "1088\u00d7896", - "1152\u00d7896": "1152\u00d7896", "1152\u00d7832": "1152\u00d7832", "1216\u00d7832": "1216\u00d7832", "1280\u00d7768": "1280\u00d7768", @@ -62,6 +73,7 @@ "Describing what you do not want to see.": "Describing what you do not want to see.", "Random": "Random", "Seed": "Seed", + "\ud83d\udcda History Log": "\uD83D\uDCDA History Log", "Image Style": "Image Style", "Fooocus V2": "Fooocus V2", "Default (Slightly Cinematic)": "Default (Slightly Cinematic)", @@ -275,31 +287,35 @@ "Volumetric Lighting": "Volumetric Lighting", "Watercolor 2": "Watercolor 2", "Whimsical And Playful": "Whimsical And Playful", + "Model": "Model", "Base Model (SDXL only)": "Base Model (SDXL only)", + "sd_xl_base_1.0_0.9vae.safetensors": "sd_xl_base_1.0_0.9vae.safetensors", "bluePencilXL_v009.safetensors": "bluePencilXL_v009.safetensors", "bluePencilXL_v050.safetensors": "bluePencilXL_v050.safetensors", "DreamShaper_8_pruned.safetensors": "DreamShaper_8_pruned.safetensors", "realisticStockPhoto_v10.safetensors": "realisticStockPhoto_v10.safetensors", "realisticVisionV51_v51VAE.safetensors": "realisticVisionV51_v51VAE.safetensors", - "sd_xl_base_1.0_0.9vae.safetensors": "sd_xl_base_1.0_0.9vae.safetensors", "sd_xl_refiner_1.0_0.9vae.safetensors": "sd_xl_refiner_1.0_0.9vae.safetensors", "Refiner (SDXL or SD 1.5)": "Refiner (SDXL or SD 1.5)", "None": "None", + "LoRAs": "LoRAs", "SDXL LoRA 1": "SDXL LoRA 1", + "sd_xl_offset_example-lora_1.0.safetensors": "sd_xl_offset_example-lora_1.0.safetensors", "3d_render_style_xl.safetensors": "3d_render_style_xl.safetensors", "Bloodstained-XL-V1.safetensors": "Bloodstained-XL-V1.safetensors", "SDXL_FILM_PHOTOGRAPHY_STYLE_BetaV0.4.safetensors": "SDXL_FILM_PHOTOGRAPHY_STYLE_BetaV0.4.safetensors", - "sd_xl_offset_example-lora_1.0.safetensors": "sd_xl_offset_example-lora_1.0.safetensors", "SDXL LoRA 2": "SDXL LoRA 2", "SDXL LoRA 3": "SDXL LoRA 3", "SDXL LoRA 4": "SDXL LoRA 4", "SDXL LoRA 5": "SDXL LoRA 5", "Refresh": "Refresh", + "\ud83d\udd04 Refresh All Files": "\ud83d\udd04 Refresh All Files", "Sampling Sharpness": "Sampling Sharpness", "Higher value means image and texture are sharper.": "Higher value means image and texture are sharper.", "Guidance Scale": "Guidance Scale", "Higher value means style is cleaner, vivider, and more artistic.": "Higher value means style is cleaner, vivider, and more artistic.", "Developer Debug Mode": "Developer Debug Mode", + "Developer Debug Tools": "Developer Debug Tools", "Positive ADM Guidance Scaler": "Positive ADM Guidance Scaler", "The scaler multiplied to positive ADM (use 1.0 to disable). ": "The scaler multiplied to positive ADM (use 1.0 to disable). ", "Negative ADM Guidance Scaler": "Negative ADM Guidance Scaler", @@ -313,6 +329,7 @@ "CFG Mimicking from TSNR": "CFG Mimicking from TSNR", "Enabling Fooocus's implementation of CFG mimicking for TSNR (effective when real CFG > mimicked CFG).": "Enabling Fooocus's implementation of CFG mimicking for TSNR (effective when real CFG > mimicked CFG).", "Sampler": "Sampler", + "dpmpp_2m_sde_gpu": "dpmpp_2m_sde_gpu", "Only effective in non-inpaint mode.": "Only effective in non-inpaint mode.", "euler": "euler", "euler_ancestral": "euler_ancestral", @@ -327,7 +344,6 @@ "dpmpp_sde_gpu": "dpmpp_sde_gpu", "dpmpp_2m": "dpmpp_2m", "dpmpp_2m_sde": "dpmpp_2m_sde", - "dpmpp_2m_sde_gpu": "dpmpp_2m_sde_gpu", "dpmpp_3m_sde": "dpmpp_3m_sde", "dpmpp_3m_sde_gpu": "dpmpp_3m_sde_gpu", "ddpm": "ddpm", @@ -335,9 +351,9 @@ "uni_pc": "uni_pc", "uni_pc_bh2": "uni_pc_bh2", "Scheduler": "Scheduler", + "karras": "karras", "Scheduler of Sampler.": "Scheduler of Sampler.", "normal": "normal", - "karras": "karras", "exponential": "exponential", "sgm_uniform": "sgm_uniform", "simple": "simple", @@ -352,16 +368,19 @@ "Set as negative number to disable. For developer debugging.": "Set as negative number to disable. For developer debugging.", "Forced Overwrite of Denoising Strength of \"Upscale\"": "Forced Overwrite of Denoising Strength of \"Upscale\"", "Inpaint Engine": "Inpaint Engine", - "Version of Fooocus inpaint model": "Version of Fooocus inpaint model", "v1": "v1", + "Version of Fooocus inpaint model": "Version of Fooocus inpaint model", "v2.5": "v2.5", + "Control Debug": "Control Debug", "Debug Preprocessors": "Debug Preprocessors", "Mixing Image Prompt and Vary/Upscale": "Mixing Image Prompt and Vary/Upscale", "Mixing Image Prompt and Inpaint": "Mixing Image Prompt and Inpaint", "Softness of ControlNet": "Softness of ControlNet", "Similar to the Control Mode in A1111 (use 0.0 to disable). ": "Similar to the Control Mode in A1111 (use 0.0 to disable). ", + "Canny": "Canny", "Canny Low Threshold": "Canny Low Threshold", "Canny High Threshold": "Canny High Threshold", + "FreeU": "FreeU", "Enabled": "Enabled", "B1": "B1", "B2": "B2", diff --git a/modules/gradio_hijack.py b/modules/gradio_hijack.py index 90149ad..4fd2db5 100644 --- a/modules/gradio_hijack.py +++ b/modules/gradio_hijack.py @@ -15,7 +15,7 @@ from gradio_client.serializing import ImgSerializable from PIL import Image as _Image # using _ to minimize namespace pollution from gradio import processing_utils, utils -from gradio.components.base import IOComponent, _Keywords +from gradio.components.base import IOComponent, _Keywords, Block from gradio.deprecation import warn_style_method_deprecation from gradio.events import ( Changeable, @@ -450,14 +450,14 @@ class Image( all_components = [] -if not hasattr(IOComponent, 'original__init__'): - IOComponent.original_init = IOComponent.__init__ +if not hasattr(Block, 'original__init__'): + Block.original_init = Block.__init__ -def ioc_ini(self, *args, **kwargs): +def blk_ini(self, *args, **kwargs): all_components.append(self) - return IOComponent.original_init(self, *args, **kwargs) + return Block.original_init(self, *args, **kwargs) -IOComponent.__init__ = ioc_ini +Block.__init__ = blk_ini diff --git a/modules/localization.py b/modules/localization.py index 62d2bde..9403b17 100644 --- a/modules/localization.py +++ b/modules/localization.py @@ -22,6 +22,8 @@ def localization_js(filename): print(str(e)) print(f'Failed to load localization file {full_name}') + # data = {k: 'XXX' for k in data.keys()} # use this to see if all texts are covered + return f"window.localization = {json.dumps(data)}" @@ -29,11 +31,14 @@ def dump_english_config(components): all_texts = [] for c in components: label = getattr(c, 'label', None) + value = getattr(c, 'value', None) choices = getattr(c, 'choices', None) info = getattr(c, 'info', None) if isinstance(label, str): all_texts.append(label) + if isinstance(value, str): + all_texts.append(value) if isinstance(info, str): all_texts.append(info) if isinstance(choices, list): @@ -45,7 +50,7 @@ def dump_english_config(components): if isinstance(y, str): all_texts.append(y) - config_dict = {k: k for k in all_texts if k != ""} + config_dict = {k: k for k in all_texts if k != "" and 'progress-container' not in k} full_name = os.path.abspath(os.path.join(localization_root, 'en.json')) with open(full_name, "w", encoding="utf-8") as json_file: