Spaces:
Sleeping
Sleeping
File size: 1,318 Bytes
3d4f13a 3b68341 3d4f13a ef9b88b 3b68341 ef9b88b 3b68341 ef9b88b 3b68341 1335053 4f70f9f 3d4f13a 3b68341 1335053 4f70f9f 1335053 4f70f9f 1335053 4f70f9f 1335053 4f70f9f 1335053 4f70f9f 1335053 4f70f9f 1335053 4f70f9f 3b68341 |
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import gradio as gr
from transformers import M2M100Tokenizer, M2M100ForConditionalGeneration, pipeline
model_name = "dsfsi/nr-en-m2m100-gov"
tokenizer = M2M100Tokenizer.from_pretrained(model_name)
model = M2M100ForConditionalGeneration.from_pretrained(model_name)
tokenizer.src_lang = "nr"
model.config.forced_bos_token_id = tokenizer.get_lang_id("en")
translater_nr_en = pipeline(
"translation",
model=model,
tokenizer=tokenizer,
)
def translate(inp):
res = translater_nr_en(inp, max_length=512, early_stopping=True)[0]['translation_text']
return res
# Update description and article as needed
description = """
<p>
<center>
One-way Translation from isiNdebele to English
</center>
</p>
"""
article = "<p style='text-align: center'><a href='https://huggingface.co/dsfsi/nr-en-m2m100-gov' target='_blank'>by dsfsi</a></p></center></p>"
examples = [
["Ngiyabonga kakhulu ngesipho osinike sona."],
["Ukuthula kuhlale kuyindlela ephilayo yempilo yethu."]
]
iface = gr.Interface(
fn=translate,
title="isiNdebele to English Translation",
description=description,
article=article,
examples=examples,
inputs=gr.components.Textbox(lines=5, placeholder="Enter isiNdebele text (maximum 5 lines)", label="Input"),
outputs="text"
)
iface.launch(enable_queue=True)
|