Spaces:
Runtime error
Runtime error
File size: 1,535 Bytes
ac8cea6 6fa74a8 ac8cea6 8a51e80 ac8cea6 676dadb ac8cea6 75a2980 ac8cea6 75a2980 ac8cea6 75a2980 ac8cea6 5e420cc |
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 50 |
import os
import torch
import gradio as gr
import time
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
model = AutoModelForSeq2SeqLM.from_pretrained("facebook/nllb-200-distilled-1.3B")
tokenizer = AutoTokenizer.from_pretrained("facebook/nllb-200-distilled-1.3B")
def translation(source, target, text) -> str:
translator = pipeline('translation', model=model, tokenizer=tokenizer, src_lang=source, tgt_lang=target)
output = translator(text, max_length=400)
end_time = time.time()
output = output[0]['translation_text']
return output
if __name__ == '__main__':
# define gradio demo
lang_codes = ["eng_Latn", "fuv_Latn", "fra_Latn", "arb_Arab"]
#inputs = [gr.inputs.Radio(['nllb-distilled-600M', 'nllb-1.3B', 'nllb-distilled-1.3B'], label='NLLB Model'),
inputs = [gr.inputs.Dropdown(lang_codes, default='fra_Latn', label='Source'),
gr.inputs.Dropdown(lang_codes, default='fuv_Latn', label='Target'),
gr.inputs.Textbox(lines=5, label="Input text"),
]
title = "Fulfulde translator"
demo_status = "Demo is running on CPU"
description = "Fulfulde to French, English or Arabic and vice-versa translation demo using NLLB."
examples = [
['fra_Latn', 'fuv_Latn', 'La traduction est une tâche facile.']
]
gr.Interface(
translation,
inputs,
["text"],
examples=examples,
cache_examples=False,
title=title,
description=description
).launch()
|