diff --git a/extensions/google_translate/script.py b/extensions/google_translate/script.py index 63226107..5dfdbcd0 100644 --- a/extensions/google_translate/script.py +++ b/extensions/google_translate/script.py @@ -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)