Spaces:
Running
on
Zero
Running
on
Zero
Update module_translation.py
Browse files- module_translation.py +16 -4
module_translation.py
CHANGED
|
@@ -40,11 +40,17 @@ def translate_text(text, tgt_lang):
|
|
| 40 |
]
|
| 41 |
|
| 42 |
# Get the translation
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
translated_text_google = GoogleTranslator(
|
| 45 |
source='auto', target=tgt_lang).translate(text=text)
|
| 46 |
|
| 47 |
-
return
|
|
|
|
| 48 |
|
| 49 |
#
|
| 50 |
# User interface
|
|
@@ -77,7 +83,8 @@ with gr.Blocks() as demo:
|
|
| 77 |
label="Target language",
|
| 78 |
render=True
|
| 79 |
)
|
| 80 |
-
translate_btn = gr.Button(value="Translate", variant="primary")
|
|
|
|
| 81 |
clear_btn = gr.Button("Clear", variant="secondary")
|
| 82 |
|
| 83 |
# Examples
|
|
@@ -102,7 +109,12 @@ with gr.Blocks() as demo:
|
|
| 102 |
translate_btn.click(
|
| 103 |
fn=translate_text,
|
| 104 |
inputs=[input_text, tgt_lang],
|
| 105 |
-
outputs=[output_text,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
)
|
| 107 |
clear_btn.click(
|
| 108 |
fn=lambda : ('', '', ''), # input_text, output_text, output_text_google
|
|
|
|
| 40 |
]
|
| 41 |
|
| 42 |
# Get the translation
|
| 43 |
+
yield from vlm.stream_response(messages)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def translate_text_with_google(text, tgt_lang):
|
| 47 |
+
"""Translate the given text into the given target language using Google Translate.
|
| 48 |
+
"""
|
| 49 |
translated_text_google = GoogleTranslator(
|
| 50 |
source='auto', target=tgt_lang).translate(text=text)
|
| 51 |
|
| 52 |
+
return translated_text_google
|
| 53 |
+
|
| 54 |
|
| 55 |
#
|
| 56 |
# User interface
|
|
|
|
| 83 |
label="Target language",
|
| 84 |
render=True
|
| 85 |
)
|
| 86 |
+
translate_btn = gr.Button(value="Translate (Mistral)", variant="primary")
|
| 87 |
+
translate_google_btn = gr.Button(value="Translate (Google)", variant="primary")
|
| 88 |
clear_btn = gr.Button("Clear", variant="secondary")
|
| 89 |
|
| 90 |
# Examples
|
|
|
|
| 109 |
translate_btn.click(
|
| 110 |
fn=translate_text,
|
| 111 |
inputs=[input_text, tgt_lang],
|
| 112 |
+
outputs=[output_text,]
|
| 113 |
+
)
|
| 114 |
+
translate_google_btn.click(
|
| 115 |
+
fn=translate_text_with_google,
|
| 116 |
+
inputs=[input_text, tgt_lang],
|
| 117 |
+
outputs=[output_text_google,]
|
| 118 |
)
|
| 119 |
clear_btn.click(
|
| 120 |
fn=lambda : ('', '', ''), # input_text, output_text, output_text_google
|