mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
Merge branch 'feature/add-prompt-translate'
# Conflicts: # requirements_versions.txt # webui.py
This commit is contained in:
@@ -44,6 +44,7 @@ def worker():
|
|||||||
from modules.util import remove_empty_str, HWC3, resize_image, \
|
from modules.util import remove_empty_str, HWC3, resize_image, \
|
||||||
get_image_shape_ceil, set_image_shape_ceil, get_shape_ceil, resample_image
|
get_image_shape_ceil, set_image_shape_ceil, get_shape_ceil, resample_image
|
||||||
from modules.upscaler import perform_upscale
|
from modules.upscaler import perform_upscale
|
||||||
|
from modules.translator import translate2en
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async_gradio_app = shared.gradio_root
|
async_gradio_app = shared.gradio_root
|
||||||
@@ -128,6 +129,7 @@ def worker():
|
|||||||
|
|
||||||
prompt = args.pop()
|
prompt = args.pop()
|
||||||
negative_prompt = args.pop()
|
negative_prompt = args.pop()
|
||||||
|
translate_prompts = args.pop()
|
||||||
style_selections = args.pop()
|
style_selections = args.pop()
|
||||||
performance_selection = args.pop()
|
performance_selection = args.pop()
|
||||||
aspect_ratios_selection = args.pop()
|
aspect_ratios_selection = args.pop()
|
||||||
@@ -203,6 +205,10 @@ def worker():
|
|||||||
modules.patch.adm_scaler_end = advanced_parameters.adm_scaler_end = 0.0
|
modules.patch.adm_scaler_end = advanced_parameters.adm_scaler_end = 0.0
|
||||||
steps = 8
|
steps = 8
|
||||||
|
|
||||||
|
if translate_prompts:
|
||||||
|
prompt = translate2en(prompt, 'prompt')
|
||||||
|
negative_prompt = translate2en(negative_prompt, 'negative prompt')
|
||||||
|
|
||||||
modules.patch.adaptive_cfg = advanced_parameters.adaptive_cfg
|
modules.patch.adaptive_cfg = advanced_parameters.adaptive_cfg
|
||||||
print(f'[Parameters] Adaptive CFG = {modules.patch.adaptive_cfg}')
|
print(f'[Parameters] Adaptive CFG = {modules.patch.adaptive_cfg}')
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import translators
|
||||||
|
from functools import lru_cache
|
||||||
|
|
||||||
|
@lru_cache(maxsize=32, typed=False)
|
||||||
|
def translate2en(text, element):
|
||||||
|
if not text:
|
||||||
|
return text
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = translators.translate_text(text,to_language='en')
|
||||||
|
print(f'[Parameters] Translated {element}: {result}')
|
||||||
|
return result
|
||||||
|
except Exception as e:
|
||||||
|
print(f'[Parameters] Error during translation of {element}: {e}')
|
||||||
|
return text
|
||||||
@@ -6,7 +6,7 @@ accelerate==0.21.0
|
|||||||
pyyaml==6.0
|
pyyaml==6.0
|
||||||
Pillow==9.2.0
|
Pillow==9.2.0
|
||||||
scipy==1.9.3
|
scipy==1.9.3
|
||||||
tqdm==4.64.1
|
tqdm==4.65.0
|
||||||
psutil==5.9.5
|
psutil==5.9.5
|
||||||
numpy==1.23.5
|
numpy==1.23.5
|
||||||
pytorch_lightning==1.9.4
|
pytorch_lightning==1.9.4
|
||||||
@@ -15,4 +15,5 @@ gradio==3.41.2
|
|||||||
pygit2==1.12.2
|
pygit2==1.12.2
|
||||||
opencv-contrib-python==4.8.0.74
|
opencv-contrib-python==4.8.0.74
|
||||||
diffusers==0.21.4
|
diffusers==0.21.4
|
||||||
httpx==0.24.1
|
httpx==0.24.1
|
||||||
|
translators==5.8.9
|
||||||
@@ -224,6 +224,9 @@ with shared.gradio_root:
|
|||||||
info='Describing what you do not want to see.', lines=2,
|
info='Describing what you do not want to see.', lines=2,
|
||||||
elem_id='negative_prompt',
|
elem_id='negative_prompt',
|
||||||
value=modules.config.default_prompt_negative)
|
value=modules.config.default_prompt_negative)
|
||||||
|
translate_prompts = gr.Checkbox(label='Translate Prompts',
|
||||||
|
info='Uses the internet to translate prompts to English',
|
||||||
|
value=False)
|
||||||
seed_random = gr.Checkbox(label='Random', value=True)
|
seed_random = gr.Checkbox(label='Random', value=True)
|
||||||
image_seed = gr.Textbox(label='Seed', value=0, max_lines=1, visible=False) # workaround for https://github.com/gradio-app/gradio/issues/5354
|
image_seed = gr.Textbox(label='Seed', value=0, max_lines=1, visible=False) # workaround for https://github.com/gradio-app/gradio/issues/5354
|
||||||
|
|
||||||
@@ -515,7 +518,7 @@ with shared.gradio_root:
|
|||||||
], show_progress=False, queue=False)
|
], show_progress=False, queue=False)
|
||||||
|
|
||||||
ctrls = [
|
ctrls = [
|
||||||
currentTask, prompt, negative_prompt, style_selections,
|
currentTask, prompt, negative_prompt, translate_prompts, style_selections,
|
||||||
performance_selection, aspect_ratios_selection, image_number, image_seed, sharpness, guidance_scale
|
performance_selection, aspect_ratios_selection, image_number, image_seed, sharpness, guidance_scale
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user