mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-12-23 21:18:00 +01:00
[Added] google_translate activate param (#2961)
- So you can quickly enable/disable it, otherwise you must select English to disable it, and then your language to enable it again.
This commit is contained in:
parent
74ea7522a0
commit
463aac2d65
@ -2,6 +2,7 @@ import gradio as gr
|
||||
from deep_translator import GoogleTranslator
|
||||
|
||||
params = {
|
||||
"activate": True,
|
||||
"language string": "ja",
|
||||
}
|
||||
|
||||
@ -13,6 +14,8 @@ def input_modifier(string):
|
||||
This function is applied to your text inputs before
|
||||
they are fed into the model.
|
||||
"""
|
||||
if not params['activate']:
|
||||
return string
|
||||
|
||||
return GoogleTranslator(source=params['language string'], target='en').translate(string)
|
||||
|
||||
@ -21,6 +24,8 @@ def output_modifier(string):
|
||||
"""
|
||||
This function is applied to the model outputs.
|
||||
"""
|
||||
if not params['activate']:
|
||||
return string
|
||||
|
||||
return GoogleTranslator(source='en', target=params['language string']).translate(string)
|
||||
|
||||
@ -40,7 +45,12 @@ def ui():
|
||||
language_name = list(language_codes.keys())[list(language_codes.values()).index(params['language string'])]
|
||||
|
||||
# Gradio elements
|
||||
language = gr.Dropdown(value=language_name, choices=[k for k in language_codes], label='Language')
|
||||
with gr.Row():
|
||||
activate = gr.Checkbox(value=params['activate'], label='Activate translation')
|
||||
|
||||
with gr.Row():
|
||||
language = gr.Dropdown(value=language_name, choices=[k for k in language_codes], label='Language')
|
||||
|
||||
# Event functions to update the parameters in the backend
|
||||
activate.change(lambda x: params.update({"activate": x}), activate, None)
|
||||
language.change(lambda x: params.update({"language string": language_codes[x]}), language, None)
|
||||
|
Loading…
Reference in New Issue
Block a user