Spaces:
Sleeping
Sleeping
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) | |