Spaces:
Paused
Paused
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() | |