Spaces:
Sleeping
Sleeping
fix app
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ import torch
|
|
4 |
from sacremoses import MosesPunctNormalizer
|
5 |
import re
|
6 |
import unicodedata
|
7 |
-
import sys
|
8 |
|
9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
|
@@ -27,16 +26,8 @@ def fix_tokenizer(tokenizer, new_lang='ami_Latn'):
|
|
27 |
|
28 |
fix_tokenizer(small_tokenizer)
|
29 |
|
30 |
-
# Language mapping
|
31 |
-
lang_map = {
|
32 |
-
"汉语 Chinese": "zho_Hant",
|
33 |
-
"Amis": "ami_Latn"
|
34 |
-
}
|
35 |
-
|
36 |
# Translation function
|
37 |
-
def translate(text,
|
38 |
-
src_lang = lang_map[src_lang_label]
|
39 |
-
tgt_lang = lang_map[tgt_lang_label]
|
40 |
tokenizer, model = small_tokenizer, small_model
|
41 |
if src_lang == "zho_Hant":
|
42 |
text = preproc_chinese(text)
|
@@ -69,23 +60,15 @@ def preproc_chinese(text):
|
|
69 |
clean = replace_nonprint(clean)
|
70 |
return unicodedata.normalize("NFKC", clean)
|
71 |
|
72 |
-
# Gradio interface
|
73 |
with gr.Blocks() as demo:
|
74 |
gr.Markdown("# AMIS - Chinese Translation Tool")
|
75 |
-
src_lang = gr.Radio(choices=["
|
76 |
-
tgt_lang = gr.Radio(choices=["
|
77 |
input_text = gr.Textbox(label="Input Text", placeholder="Enter text here...")
|
78 |
output_text = gr.Textbox(label="Translated Text", interactive=False)
|
79 |
translate_btn = gr.Button("Translate")
|
80 |
-
|
81 |
-
|
82 |
-
translate_btn.click(
|
83 |
-
translate,
|
84 |
-
inputs=[input_text, src_lang, tgt_lang],
|
85 |
-
outputs=output_text
|
86 |
-
)
|
87 |
-
|
88 |
-
gr.Markdown("感謝您在此專案上的辛勤工作 這只是這些模型能力的一小部分展示。電子郵件: [email protected]")
|
89 |
|
90 |
if __name__ == "__main__":
|
91 |
demo.launch()
|
|
|
4 |
from sacremoses import MosesPunctNormalizer
|
5 |
import re
|
6 |
import unicodedata
|
|
|
7 |
|
8 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
9 |
|
|
|
26 |
|
27 |
fix_tokenizer(small_tokenizer)
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
# Translation function
|
30 |
+
def translate(text, src_lang, tgt_lang):
|
|
|
|
|
31 |
tokenizer, model = small_tokenizer, small_model
|
32 |
if src_lang == "zho_Hant":
|
33 |
text = preproc_chinese(text)
|
|
|
60 |
clean = replace_nonprint(clean)
|
61 |
return unicodedata.normalize("NFKC", clean)
|
62 |
|
|
|
63 |
with gr.Blocks() as demo:
|
64 |
gr.Markdown("# AMIS - Chinese Translation Tool")
|
65 |
+
src_lang = gr.Radio(choices=["zho_Hant", "ami_Latn"], value="zho_Hant", label="Source Language")
|
66 |
+
tgt_lang = gr.Radio(choices=["ami_Latn", "zho_Hant"], value="ami_Latn", label="Target Language")
|
67 |
input_text = gr.Textbox(label="Input Text", placeholder="Enter text here...")
|
68 |
output_text = gr.Textbox(label="Translated Text", interactive=False)
|
69 |
translate_btn = gr.Button("Translate")
|
70 |
+
|
71 |
+
translate_btn.click(translate, inputs=[input_text, src_lang, tgt_lang], outputs=output_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
if __name__ == "__main__":
|
74 |
demo.launch()
|