Spaces:
Runtime error
Runtime error
File size: 1,198 Bytes
8553d28 |
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 |
from transformers import pipeline
import torch
import gradio as gr
from lang_codes import get_language_code, get_language_list
text_translator = pipeline("translation", model="facebook/nllb-200-distilled-600M", torch_dtype=torch.bfloat16)
def translate_text(text, source = "English", target = "German"):
src_code = get_language_code(source)
dest_code = get_language_code(target)
translation = text_translator(text,
src_lang=src_code,
tgt_lang=dest_code)
return translation[0]["translation_text"]
# translate_text("Hello Friends. How are you?", "German")
language_list = get_language_list()
gr.close_all()
demo = gr.Interface(
fn=translate_text,
inputs=[
gr.Textbox(label="Input text to Translate"),
gr.Dropdown(label="Select Input Language", choices=language_list, value="English"),
gr.Dropdown(label="Select Output Language", choices=language_list, value="German"),
],
outputs=[
gr.Textbox(label="Translated text", lines=6)
],
title="Multi Language Translator",
description="This App translates from any language to any langauge")
demo.launch()
|