From 7ff68ef252ea22db426428b095877ce859226243 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Sat, 28 Jan 2023 23:26:07 -0300 Subject: [PATCH] Add Google Translate extension --- extensions/google-translate/requirements.txt | 1 + extensions/google-translate/script.py | 22 ++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 extensions/google-translate/requirements.txt create mode 100644 extensions/google-translate/script.py diff --git a/extensions/google-translate/requirements.txt b/extensions/google-translate/requirements.txt new file mode 100644 index 00000000..8b0d4f19 --- /dev/null +++ b/extensions/google-translate/requirements.txt @@ -0,0 +1 @@ +googletrans==3.1.0a0 diff --git a/extensions/google-translate/script.py b/extensions/google-translate/script.py new file mode 100644 index 00000000..aa388110 --- /dev/null +++ b/extensions/google-translate/script.py @@ -0,0 +1,22 @@ +from googletrans import Translator + +translator = Translator() + +params = { + "language string": "ja", +} + +def input_modifier(string): + """ + This function is applied to your text inputs before + they are fed into the model. + """ + + return translator.translate(string, dest='en').text + +def output_modifier(string): + """ + This function is applied to the model outputs. + """ + + return translator.translate(string, dest=params['language string']).text