File size: 1,578 Bytes
b5efccc
6e13b58
b5efccc
6e13b58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
642348f
6e13b58
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

tokenizer = AutoTokenizer.from_pretrained("TwentyNine/byt5-ain-kana-latin-converter-v2")
model = AutoModelForSeq2SeqLM.from_pretrained("TwentyNine/byt5-ain-kana-latin-converter-v2")

def transcribe(input_str):
    output_str = ''

    for input in input_str.split('\n'):
        input_enc  = tokenizer.encode(input.strip(), return_tensors='pt')
        output_enc = model.generate(input_enc, max_length=256)
        
        if len(output_str) > 0:
            output_str = output_str + '\n'
            
        output_str = output_str + tokenizer.decode(output_enc[0], skip_special_tokens=True)
        
    return output_str

gradio_app = gr.Interface(
    transcribe,
    inputs=gr.Textbox(label='Input (kana)', value='γƒˆγ‚₯γ‚€γƒžγ€€γƒ’γ€€γƒ―γ€€γ‚¨γ‚¨γ‡°γ€€γƒ―γ€€γƒ’γ‚ͺγƒΌγ‚€γ‚ͺγ‚€γ€‚γƒ”γ‡Όγ‚«γƒŽγ€€γƒŒγ‚«γ‡»γ€€γƒ€γƒ³οΌ', placeholder='γƒˆγ‚₯γ‚€γƒžγ€€γƒ’γ€€γƒ―γ€€γ‚¨γ‚¨γ‡°γ€€γƒ―γ€€γƒ’γ‚ͺγƒΌγ‚€γ‚ͺγ‚€γ€‚γƒ”γ‡Όγ‚«γƒŽγ€€γƒŒγ‚«γ‡»γ€€γƒ€γƒ³οΌ', info='Ainu text written in Japanese katakana (input).', interactive=True, autofocus=True),
    outputs=gr.Textbox(label='Output (alphabet)', info='Ainu text written in the Latin alphabet (output).'),
    title='BYT5 Ainu Kana-Latin Converter (V2)',
    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">Professor NAKAGAWA Hiroshi</a> of Chiba University.</p>'
)

if __name__ == '__main__':
    gradio_app.launch()