Spaces:
Sleeping
Sleeping
File size: 807 Bytes
bfe2b89 |
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 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
# Load model and tokenizer
model_name = "VietAI/envit5-translation"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
# Translation function
def translate(text):
input_ids = tokenizer(text, return_tensors="pt", padding=True).input_ids
output_ids = model.generate(input_ids, max_length=512)
return tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0]
# Gradio interface
demo = gr.Interface(
fn=translate,
inputs="text",
outputs="text",
title="Vietnamese-English Translation",
description="Translate text between English and Vietnamese using the VietAI envit5 model."
)
# Launch the Gradio app
demo.launch(debug=True)
|