jisukim8873 commited on
Commit
c968835
β€’
1 Parent(s): 0a7cea6
Files changed (1) hide show
  1. app.py +64 -11
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
- translator_app = gr.Interface(
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()