MohamedUgas's picture
Update app.py
7c76852
raw
history blame contribute delete
971 Bytes
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
import torch
from langs import LANGS
model = AutoModelForSeq2SeqLM.from_pretrained("facebook/nllb-200-distilled-600M")
tokenizer = AutoTokenizer.from_pretrained("facebook/nllb-200-distilled-600M")
source = 'som_Latn'
target = "eng_Latn"
def translate(source, target, text):
translation_pipeline = pipeline("translation",
model=model,
tokenizer=tokenizer,
src_lang=source,
tgt_lang=target)
result = translation_pipeline(text)
return result[0]['translation_text']
gr.Interface(
translate,
[
gr.components.Dropdown(label="Source Language", choices=LANGS),
gr.components.Dropdown(label="Target Language", choices=LANGS),
gr.components.Textbox(label="Text")
],
["text"],
).launch()