jisukim8873
commited on
Commit
•
bf37b0d
1
Parent(s):
5a31d97
finishgit add app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,7 @@ en2ko_tokenizer = AutoTokenizer.from_pretrained(en2ko)
|
|
14 |
ko2en_tokenizer = AutoTokenizer.from_pretrained(ko2en)
|
15 |
style_tokenizer = AutoTokenizer.from_pretrained(style)
|
16 |
|
17 |
-
def
|
18 |
formats = {"English":"eng_Latn", "Korean":"kor_Hang"}
|
19 |
src = formats[source]
|
20 |
tgt = formats[target]
|
@@ -23,7 +23,7 @@ def translate(source, target, text):
|
|
23 |
translator = pipeline(
|
24 |
'translation',
|
25 |
model=en2ko_model,
|
26 |
-
tokenizer=
|
27 |
src_lang=src,
|
28 |
tgt_lang=tgt,
|
29 |
)
|
@@ -32,7 +32,7 @@ def translate(source, target, text):
|
|
32 |
translator = pipeline(
|
33 |
'translation',
|
34 |
model=ko2en_model,
|
35 |
-
tokenizer=
|
36 |
src_lang=src,
|
37 |
tgt_lang=tgt
|
38 |
)
|
@@ -42,6 +42,32 @@ def translate(source, target, text):
|
|
42 |
|
43 |
return translated_text
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
def conversion(source, text):
|
46 |
formats = {
|
47 |
"formal":"문어체",
|
@@ -77,19 +103,28 @@ def conversion(source, text):
|
|
77 |
|
78 |
return generated_text
|
79 |
|
80 |
-
|
|
|
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 |
|
86 |
-
|
87 |
-
fn=
|
88 |
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')],
|
89 |
outputs=[gr.outputs.Textbox(label='Translated Text')],
|
90 |
title=title,
|
91 |
enable_queue=True,
|
92 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
conversion_app = gr.Interface(
|
95 |
fn=conversion,
|
@@ -99,6 +134,11 @@ conversion_app = gr.Interface(
|
|
99 |
enable_queue=True,
|
100 |
)
|
101 |
|
102 |
-
demo = gr.TabbedInterface([
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
demo.launch()
|
|
|
14 |
ko2en_tokenizer = AutoTokenizer.from_pretrained(ko2en)
|
15 |
style_tokenizer = AutoTokenizer.from_pretrained(style)
|
16 |
|
17 |
+
def translation(source, target, text):
|
18 |
formats = {"English":"eng_Latn", "Korean":"kor_Hang"}
|
19 |
src = formats[source]
|
20 |
tgt = formats[target]
|
|
|
23 |
translator = pipeline(
|
24 |
'translation',
|
25 |
model=en2ko_model,
|
26 |
+
tokenizer=en2ko_tokenizer,
|
27 |
src_lang=src,
|
28 |
tgt_lang=tgt,
|
29 |
)
|
|
|
32 |
translator = pipeline(
|
33 |
'translation',
|
34 |
model=ko2en_model,
|
35 |
+
tokenizer=ko2en_tokenizer,
|
36 |
src_lang=src,
|
37 |
tgt_lang=tgt
|
38 |
)
|
|
|
42 |
|
43 |
return translated_text
|
44 |
|
45 |
+
def augmentation(text):
|
46 |
+
ko2en_translator = pipeline(
|
47 |
+
'translation',
|
48 |
+
model=ko2en_model,
|
49 |
+
tokenizer=ko2en_tokenizer,
|
50 |
+
src_lang="kor_Hang",
|
51 |
+
tgt_lang="eng_Latn"
|
52 |
+
)
|
53 |
+
|
54 |
+
output = ko2en_translator(text)
|
55 |
+
ko2en_text = output[0]['translation_text']
|
56 |
+
|
57 |
+
en2ko_translator = pipeline(
|
58 |
+
'translation',
|
59 |
+
model=en2ko_model,
|
60 |
+
tokenizer=en2ko_tokenizer,
|
61 |
+
src_lang="eng_Latn",
|
62 |
+
tgt_lang="kor_Hang",
|
63 |
+
)
|
64 |
+
|
65 |
+
output = en2ko_translator(ko2en_text)
|
66 |
+
en2ko_text = output[0]['translation_text']
|
67 |
+
|
68 |
+
return en2ko_text
|
69 |
+
|
70 |
+
|
71 |
def conversion(source, text):
|
72 |
formats = {
|
73 |
"formal":"문어체",
|
|
|
103 |
|
104 |
return generated_text
|
105 |
|
106 |
+
|
107 |
+
|
108 |
lang = ['English','Korean']
|
109 |
style = ['formal', 'informal', 'android', 'azae', 'chat', 'choding', 'emoticon', 'enfp', \
|
110 |
'gentle', 'halbae', 'halmae', 'joongding', 'king', 'naruto', 'seonbi', 'sosim', 'translator']
|
111 |
|
112 |
|
113 |
+
translation_app = gr.Interface(
|
114 |
+
fn=translation,
|
115 |
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')],
|
116 |
outputs=[gr.outputs.Textbox(label='Translated Text')],
|
117 |
title=title,
|
118 |
enable_queue=True,
|
119 |
)
|
120 |
+
|
121 |
+
augmentation_app = gr.Interface(
|
122 |
+
fn=augmentation,
|
123 |
+
inputs=[gr.inputs.Textbox(lines=5, label='Korean Text to Augmentation')],
|
124 |
+
outputs=[gr.outputs.Textbox(label='Augmented Text')],
|
125 |
+
title=title,
|
126 |
+
enable_queue=True,
|
127 |
+
)
|
128 |
|
129 |
conversion_app = gr.Interface(
|
130 |
fn=conversion,
|
|
|
134 |
enable_queue=True,
|
135 |
)
|
136 |
|
137 |
+
demo = gr.TabbedInterface([translation_app, augmentation_app, conversion_app], \
|
138 |
+
["Translation", "Augmentation", "Speech Style conversion"],\
|
139 |
+
title = 'KoTAN Translator & Speech-style converter. \n \
|
140 |
+
🔥If you want to download as pip package, \
|
141 |
+
please visit our github. (https://github.com/KoJLabs/KoTAN) 🔥'
|
142 |
+
)
|
143 |
|
144 |
demo.launch()
|