Spaces:
Sleeping
Sleeping
Commit
•
e70e522
1
Parent(s):
e19bd7a
Add body
Browse files
app.py
CHANGED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
to_german = pipeline("translation", model="t5-base")
|
6 |
+
to_spanish = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
|
7 |
+
|
8 |
+
|
9 |
+
def translate(text, translator):
|
10 |
+
return translator(text)[0]["translation_text"]
|
11 |
+
|
12 |
+
|
13 |
+
example_text = ["I went to the supermarket yesterday.",
|
14 |
+
"Helen is a good swimmer."]
|
15 |
+
|
16 |
+
|
17 |
+
with gr.Blocks() as demo:
|
18 |
+
with gr.Tabs():
|
19 |
+
with gr.TabItem("English to German"):
|
20 |
+
with gr.Row():
|
21 |
+
with gr.Column():
|
22 |
+
english = gr.Textbox(label="English Text")
|
23 |
+
translate_to_german = gr.Button(value="Translate To German")
|
24 |
+
with gr.Column():
|
25 |
+
german = gr.Textbox(label="German Text")
|
26 |
+
translate_to_german.click(lambda text: translate(text, to_german), inputs=english, outputs=german)
|
27 |
+
gr.Examples(examples=example_text,
|
28 |
+
inputs=[english])
|
29 |
+
with gr.TabItem("English to Spanish"):
|
30 |
+
with gr.Row():
|
31 |
+
with gr.Column():
|
32 |
+
english_2 = gr.Textbox(label="English Text")
|
33 |
+
translate_to_spanish = gr.Button(value="Translate To Spanish")
|
34 |
+
with gr.Column():
|
35 |
+
spanish = gr.Textbox(label="Spanish Text")
|
36 |
+
translate_to_spanish.click(lambda text: translate(text, to_spanish), inputs=english_2, outputs=spanish)
|
37 |
+
gr.Examples(examples=example_text,
|
38 |
+
inputs=[english_2])
|
39 |
+
|
40 |
+
|
41 |
+
if __name__ == "__main__":
|
42 |
+
demo.launch()
|