[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:
Salvador E. Tropea 2023-07-09 01:08:20 -03:00 committed by GitHub
parent 74ea7522a0
commit 463aac2d65
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)