jisukim8873
commited on
Commit
β’
c968835
1
Parent(s):
0a7cea6
test
Browse files
app.py
CHANGED
@@ -42,17 +42,70 @@ def translate(source, target, text):
|
|
42 |
|
43 |
return translated_text
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
title = 'KoTAN Translator & Speech-style converter'
|
46 |
lang = ['English','Korean']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
|
49 |
-
fn=translate,
|
50 |
-
inputs=[gr.inputs.Dropdown(choices=lang, label='Source Language'), gr.inputs.Dropdown(choices=lang, label='Target Language'), gr.inputs.Textbox(lines=5, label='Text to Translate')],
|
51 |
-
outputs=[gr.outputs.Textbox(label='Translated Text')],
|
52 |
-
title=title,
|
53 |
-
description = 'KoTAN: Korean Translation and Augmentation with fine-tuned NLLB. If you want to download as pip package, please visit our github. (https://github.com/KoJLabs/KoTAN)',
|
54 |
-
article='Jisu, Kim. Juhwan, Lee',
|
55 |
-
enable_queue=True,
|
56 |
-
)
|
57 |
-
|
58 |
-
translator_app.launch()
|
|
|
42 |
|
43 |
return translated_text
|
44 |
|
45 |
+
def conversion(source, text):
|
46 |
+
formats = {
|
47 |
+
"formal":"λ¬Έμ΄μ²΄",
|
48 |
+
"informal":"ꡬμ΄μ²΄",
|
49 |
+
"android":"μλλ‘μ΄λ",
|
50 |
+
"azae":"μμ¬",
|
51 |
+
"chat":"μ±ν
",
|
52 |
+
"choding":"μ΄λ±νμ",
|
53 |
+
"emoticon":"μ΄λͺ¨ν°μ½",
|
54 |
+
"enfp":"enfp",
|
55 |
+
"gentle":"μ μ¬",
|
56 |
+
"halbae":"ν μλ²μ§",
|
57 |
+
"halmae":"ν λ¨Έλ",
|
58 |
+
"joongding":"μ€νμ",
|
59 |
+
"king":"μ",
|
60 |
+
"naruto":"λ루ν ",
|
61 |
+
"seonbi":"μ λΉ",
|
62 |
+
"sosim":"μμ¬ν",
|
63 |
+
"translator":"λ²μκΈ°",
|
64 |
+
}
|
65 |
+
style = formats[source]
|
66 |
+
|
67 |
+
input_text = f"{style} νμμΌλ‘ λ³ν:" + text
|
68 |
+
|
69 |
+
converter = pipeline(
|
70 |
+
'text2text-generation',
|
71 |
+
model=style_model,
|
72 |
+
tokenizer=style_tokenizer,
|
73 |
+
)
|
74 |
+
|
75 |
+
output = converter(input_text)
|
76 |
+
generated_text = output[0]['generated_text']
|
77 |
+
|
78 |
+
return generated_text
|
79 |
+
|
80 |
title = 'KoTAN Translator & Speech-style converter'
|
81 |
lang = ['English','Korean']
|
82 |
+
style = ['formal', 'informal', 'android', 'azae', 'chat', 'choding', 'emoticon', 'enfp', \
|
83 |
+
'gentle', 'halbae', 'halmae', 'joongding', 'king', 'naruto', 'seonbi', 'sosim', 'translator']
|
84 |
+
|
85 |
+
with gr.Blocks() as demo:
|
86 |
+
gr.Markdown("KoTAN: Korean Translation and Augmentation with fine-tuned NLLB. You can exercise translation tasks, and speech-style conversion. \
|
87 |
+
If you want to download as pip package, please visit our github. (https://github.com/KoJLabs/KoTAN)")
|
88 |
+
|
89 |
+
with gr.Tab("Translation"):
|
90 |
+
translator_app = gr.Interface(
|
91 |
+
fn=translate,
|
92 |
+
inputs=[gr.inputs.Dropdown(choices=lang, label='Source Language'), gr.inputs.Dropdown(choices=lang, label='Target Language'), gr.inputs.Textbox(lines=5, label='Text to Translate')],
|
93 |
+
outputs=[gr.outputs.Textbox(label='Translated Text')],
|
94 |
+
title=title,
|
95 |
+
# description = 'KoTAN: Korean Translation and Augmentation with fine-tuned NLLB. If you want to download as pip package, please visit our github. (https://github.com/KoJLabs/KoTAN)',
|
96 |
+
# article='Jisu, Kim. Juhwan, Lee',
|
97 |
+
enable_queue=True,
|
98 |
+
)
|
99 |
+
|
100 |
+
with gr.Tab("Speech-style conversion"):
|
101 |
+
translator_app = gr.Interface(
|
102 |
+
fn=conversion,
|
103 |
+
inputs=[gr.inputs.Dropdown(choices=style, label='Speech Style'), gr.inputs.Textbox(lines=5, label='Text to style conversion')],
|
104 |
+
outputs=[gr.outputs.Textbox(label='Converted Text')],
|
105 |
+
title=title,
|
106 |
+
# description = 'KoTAN: Korean Translation and Augmentation with fine-tuned NLLB. If you want to download as pip package, please visit our github. (https://github.com/KoJLabs/KoTAN)',
|
107 |
+
# article='Jisu, Kim. Juhwan, Lee',
|
108 |
+
enable_queue=True,
|
109 |
+
)
|
110 |
|
111 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|