TwentyNine
commited on
Commit
•
3a028ad
1
Parent(s):
b042fbc
Update app.py
Browse files
app.py
CHANGED
@@ -5,16 +5,26 @@ tokenizer = AutoTokenizer.from_pretrained("TwentyNine/byt5-ain-kana-latin-conver
|
|
5 |
model = AutoModelForSeq2SeqLM.from_pretrained("TwentyNine/byt5-ain-kana-latin-converter-v1")
|
6 |
|
7 |
def transcribe(input_str):
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
return tokenizer.decode(output_enc[0], skip_special_tokens=True)
|
11 |
|
12 |
gradio_app = gr.Interface(
|
13 |
transcribe,
|
14 |
inputs=gr.Textbox(label='Input (kana)', value='トゥイマ ヒ ワ エエㇰ ワ ヒオーイオイ。ピㇼカノ ヌカㇻ ヤン!', placeholder='トゥイマ ヒ ワ エエㇰ ワ ヒオーイオイ。ピㇼカノ ヌカㇻ ヤン!', info='Ainu text written in Japanese katakana (input).', interactive=True, autofocus=True),
|
15 |
outputs=gr.Textbox(label='Output (alphabet)', info='Ainu text written in the Latin alphabet (output).'),
|
16 |
-
title=
|
|
|
17 |
)
|
18 |
|
19 |
if __name__ == "__main__":
|
20 |
-
gradio_app.launch(
|
|
|
5 |
model = AutoModelForSeq2SeqLM.from_pretrained("TwentyNine/byt5-ain-kana-latin-converter-v1")
|
6 |
|
7 |
def transcribe(input_str):
|
8 |
+
output_str = ''
|
9 |
+
|
10 |
+
for input in input_str.split(separator='\n'):
|
11 |
+
input_enc = tokenizer.encode(input_str.strip(), return_tensors='pt')
|
12 |
+
output_enc = model.generate(input_enc, max_length=256)
|
13 |
+
|
14 |
+
if len(output_str) > 0:
|
15 |
+
output_str = output_str + '\n'
|
16 |
+
|
17 |
+
output_str = output_str + tokenizer.decode(output_enc[0], skip_special_tokens=True)
|
18 |
+
|
19 |
return tokenizer.decode(output_enc[0], skip_special_tokens=True)
|
20 |
|
21 |
gradio_app = gr.Interface(
|
22 |
transcribe,
|
23 |
inputs=gr.Textbox(label='Input (kana)', value='トゥイマ ヒ ワ エエㇰ ワ ヒオーイオイ。ピㇼカノ ヌカㇻ ヤン!', placeholder='トゥイマ ヒ ワ エエㇰ ワ ヒオーイオイ。ピㇼカノ ヌカㇻ ヤン!', info='Ainu text written in Japanese katakana (input).', interactive=True, autofocus=True),
|
24 |
outputs=gr.Textbox(label='Output (alphabet)', info='Ainu text written in the Latin alphabet (output).'),
|
25 |
+
title='BYT5 Ainu Kana-Latin Converter (V1)',
|
26 |
+
article='<p>Example sentence borrowed from <a href="https://www.hakusuisha.co.jp/book/b584600.html">New Express Ainu-go (ニューエクスプレスプラス アイヌ語)</a> by <a href="https://researchmap.jp/read0064265/?lang=english">NAKAGAWA Hiroshi</a>"</p>'
|
27 |
)
|
28 |
|
29 |
if __name__ == "__main__":
|
30 |
+
gradio_app.launch()
|