Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
colorFrom: purple
|
5 |
-
colorTo: pink
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.50.2
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: trans-en2zh
|
3 |
+
app_file: main.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
sdk_version: 3.50.2
|
|
|
|
|
6 |
---
|
|
|
|
main.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-en-zh")
|
6 |
+
|
7 |
+
|
8 |
+
def translate(text):
|
9 |
+
return pipe(text)[0]["translation_text"]
|
10 |
+
|
11 |
+
|
12 |
+
with gr.Blocks() as demo:
|
13 |
+
with gr.Row():
|
14 |
+
with gr.Column():
|
15 |
+
english = gr.Textbox(label="英文文本")
|
16 |
+
translate_btn = gr.Button(value="Hello")
|
17 |
+
with gr.Column():
|
18 |
+
german = gr.Textbox(label="中文翻译")
|
19 |
+
|
20 |
+
translate_btn.click(translate, inputs=english, outputs=german, api_name="translate-to-german")
|
21 |
+
examples = gr.Examples(examples=["I went to the supermarket yesterday.", "Helen is a good swimmer."],
|
22 |
+
inputs=[english])
|
23 |
+
|
24 |
+
demo.launch(share=True)
|