TwentyNine commited on
Commit
529d1c8
1 Parent(s): 915b1f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -1,11 +1,24 @@
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
 
4
- tokenizer = AutoTokenizer.from_pretrained("TwentyNine/byt5-small-ainu-latinizer-lr-11")
5
- model = AutoModelForSeq2SeqLM.from_pretrained("TwentyNine/byt5-small-ainu-latinizer-lr-11")
 
 
6
 
7
- def transcribe(input_str):
8
  output_str = ''
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  for input in input_str.split('\n'):
11
  input_enc = tokenizer.encode(input.strip(), return_tensors='pt')
@@ -20,7 +33,7 @@ def transcribe(input_str):
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">Professor NAKAGAWA Hiroshi</a> of Chiba University.</p>'
 
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
 
4
+ tokenizer = AutoTokenizer.from_pretrained("TwentyNine/byt5-small-ainu-latinizer-cos_w_restarts")
5
+ model1 = AutoModelForSeq2SeqLM.from_pretrained("TwentyNine/byt5-small-ainu-latinizer-cos_w_restarts")
6
+ model2 = AutoModelForSeq2SeqLM.from_pretrained("TwentyNine/byt5-small-ainu-latinizer-polynomial")
7
+ model3 = AutoModelForSeq2SeqLM.from_pretrained("TwentyNine/byt5-small-ainu-latinizer-linear")
8
 
9
+ def transcribe(input_str, model_index):
10
  output_str = ''
11
+ model = None
12
+
13
+ match model_index:
14
+ case 1:
15
+ model = model1
16
+ case 2:
17
+ model = model2
18
+ case 3:
19
+ model = model3
20
+ case _:
21
+ model = model1
22
 
23
  for input in input_str.split('\n'):
24
  input_enc = tokenizer.encode(input.strip(), return_tensors='pt')
 
33
 
34
  gradio_app = gr.Interface(
35
  transcribe,
36
+ inputs=(gr.Textbox(label='Input (kana)', value='トゥイマ ヒ ワ エエㇰ ワ ヒオーイオイ。ピㇼカノ ヌカㇻ ヤン!', placeholder='トゥイマ ヒ ワ エエㇰ ワ ヒオーイオイ。ピㇼカノ ヌカㇻ ヤン!', info='Ainu text written in Japanese katakana (input).', interactive=True, autofocus=True)), gr.radio(label="Training scheduler type", choices=[("Cosine with Restarts", 1), ("Polynomial", 2), ("Linear", 3)]),
37
  outputs=gr.Textbox(label='Output (alphabet)', info='Ainu text written in the Latin alphabet (output).'),
38
  title='BYT5 Ainu Kana-Latin Converter (V1)',
39
  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>'