Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,3 @@
|
|
1 |
-
pip install --upgrade transformers
|
2 |
-
|
3 |
-
import gradio as gr
|
4 |
-
from transformers import pipeline
|
5 |
-
from gradio.mix import Parallel
|
6 |
-
|
7 |
-
pipe = pipeline("translation", model="t5-base", tokenizer_kwargs={"model_max_length": 1024})
|
8 |
-
|
9 |
def translate(text, target_language):
|
10 |
return pipe(text, target_language=target_language)[0]["translation_text"]
|
11 |
|
@@ -18,12 +10,37 @@ def clear_callback(english):
|
|
18 |
return ""
|
19 |
|
20 |
def main():
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
title="Text Translation",
|
26 |
description="Translate English text to German, French, or Lao."
|
27 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
iface.launch()
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
def translate(text, target_language):
|
2 |
return pipe(text, target_language=target_language)[0]["translation_text"]
|
3 |
|
|
|
10 |
return ""
|
11 |
|
12 |
def main():
|
13 |
+
english_textbox = gr.inputs.Textbox(label="English text")
|
14 |
+
language_select = gr.inputs.Dropdown(label="Translate to", choices=["German", "French", "Lao"])
|
15 |
+
translated_textbox = gr.outputs.Textbox(label="Translated Text")
|
16 |
+
|
17 |
+
translate_interface = gr.Interface(
|
18 |
+
fn=translate_callback,
|
19 |
+
inputs=[english_textbox, language_select],
|
20 |
+
outputs=translated_textbox,
|
21 |
+
title="Text Translation",
|
22 |
+
description="Translate English text to German, French, or Lao."
|
23 |
+
)
|
24 |
+
|
25 |
+
clear_interface = gr.Interface(
|
26 |
+
fn=clear_callback,
|
27 |
+
inputs=english_textbox,
|
28 |
+
outputs=translated_textbox,
|
29 |
title="Text Translation",
|
30 |
description="Translate English text to German, French, or Lao."
|
31 |
)
|
32 |
+
|
33 |
+
iface = gr.Interface(
|
34 |
+
fn=translate_callback,
|
35 |
+
inputs=[english_textbox, language_select],
|
36 |
+
outputs=translated_textbox,
|
37 |
+
title="Text Translation",
|
38 |
+
description="Translate English text to German, French, or Lao.",
|
39 |
+
examples=[[None, "German"]],
|
40 |
+
examples_per_page=5
|
41 |
+
)
|
42 |
+
|
43 |
iface.launch()
|
44 |
|
45 |
+
if __name__ == "__main__":
|
46 |
+
main()
|