File size: 858 Bytes
51857fd
d64b334
51857fd
d64b334
cc03d52
d64b334
0e54b5e
d64b334
 
 
 
0e54b5e
 
 
 
 
d64b334
 
 
 
 
 
51857fd
1878582
d64b334
1878582
 
d64b334
 
 
1878582
d64b334
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
31
32
import gradio
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer


model_name = "zaanind/nllb-ensi-v1.6" #"zaanind/nllb-ensi-v1-tuning-subs"
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

    
def nmtapifunc(text):
    text = translate(text)
    return text 

gradio_interface = gradio.Interface(
  fn=nmtapifunc,
  inputs="text",
  outputs="text",
  title="En-Si NMT",
  description="",
  article="© zaanind 2024"
)
gradio_interface.launch()