homework2 / translate.py
Hanxiaofeng123's picture
Upload folder using huggingface_hub
8aaaea4
raw
history blame
395 Bytes
import gradio as gr
from transformers import pipeline
print ("Loading translator...")
model_name = "Helsinki-NLP/opus-mt-en-zh"
# tokenizer = AutoTokenizer.from_pretrained(model_name)
translator = pipeline(task="translation_en_to_zh", model=model_name)
def translate(text):
return translator(text)[0]['translation_text']
gr.Interface(fn=translate, inputs="text", outputs="text").launch()