File size: 908 Bytes
858a059
b907f73
858a059
 
 
 
 
 
3c0b1d8
858a059
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, T5Tokenizer, MT5ForConditionalGeneration

tokenizer = T5Tokenizer.from_pretrained("engmatic-earth/mt5-zh-ja-en-trimmed-fine-tuned-v1")
model = AutoModelForSeq2SeqLM.from_pretrained("engmatic-earth/mt5-zh-ja-en-trimmed-fine-tuned-v1")

def output(raw_input_sentence):
    target_sentence = ["en2ja: " + str(raw_input_sentence)]
    translated = model.generate(**tokenizer(target_sentence, return_tensors="pt"), max_length = 1000)
    tgt_text = [tokenizer.decode(t, skip_special_tokens=True) for t in translated]
    translated_phrase = tgt_text[0]
    translated_phrase = translated_phrase.replace(" ", "")
    return translated_phrase
    
interface = gr.Interface(fn=output, inputs=gr.inputs.Textbox(lines=3, placeholder="Write what you want to say in Japanese.")
                        ,outputs='text')
interface.launch()