File size: 851 Bytes
640200b
649708f
9a16da8
427f1d1
649708f
 
9a16da8
 
 
 
 
 
 
 
 
640200b
0db789a
 
 
 
8b8ff94
0db789a
9a16da8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer

model_name = "zaanind/nllb-ensi-v1-tuning"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
tokenizer.src_lang = "eng_Latn"

def translate(text):
    inputs = tokenizer(text=text, return_tensors="pt")
    translated_tokens = model.generate(
        **inputs, forced_bos_token_id=tokenizer.lang_code_to_id["sin_Sinh"]
    )
    translation = tokenizer.decode(translated_tokens[0], skip_special_tokens=True)
    return translation

iface = gr.Interface(fn=translate, 
                     inputs="text", 
                     outputs="text",
                     title="EnSi NMT",
                     description="This is a demo and rest api for ensi nmt by @zaanind."
                    )
iface.launch()