Spaces:
Runtime error
Runtime error
File size: 721 Bytes
4b41413 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
model_translate = AutoModelForSeq2SeqLM.from_pretrained("facebook/m2m100_418M")
tokenizer_translate = AutoTokenizer.from_pretrained("facebook/m2m100_418M")
inlang='en'
outlang='hi'
tokenizer_translate.src_lang = inlang
def translate(text):
encoded_en = tokenizer_translate(text, return_tensors="pt")
generated_tokens = model_translate.generate(**encoded_en, forced_bos_token_id=tokenizer_translate.get_lang_id(outlang))
return tokenizer_translate.batch_decode(generated_tokens, skip_special_tokens=True)[0]
interface = gr.Interface(
fn = translate,
inputs = 'text',
outputs = 'text'
)
interface.launch() |