File size: 1,053 Bytes
31dcf39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
from huggingface_hub import login


# Load the translation model and tokenizer from Hugging Face
model_name = "robzchhangte/enmz-helsinki-case"
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

# 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