English-Mizo / app.py
robzchhangte's picture
Update app.py
1491f00 verified
raw
history blame
1.1 kB
import os
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
token = os.getenv(hf_token)
# Load the translation model and tokenizer from Hugging Face
model_name = "robzchhangte/enmz-helsinki-case"
model = AutoModelForSeq2SeqLM.from_pretrained(model_name, use_auth_token=token)
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=token)
# Translation function with max_length=512
def translate(text):
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
outputs = model.generate(inputs["input_ids"], max_length=512) # Set max_length to 512
translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return translated_text
# Gradio Interface
interface = gr.Interface(
fn=translate,
inputs="text",
outputs="text",
title="Text Translator",
description="Translate text using the gravix321/model1 translation model.",
examples=[["Hello, how are you?"], ["What time is it?"]]
)
# Launch the Gradio app locally
interface.launch(share=False) # Set sharer=True to share your app