File size: 811 Bytes
ceab426
549bee4
ceab426
549bee4
 
 
 
ceab426
549bee4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# Load your Hugging Face model and tokenizer
model_name = "dreyyyy/EN-ES"  # Replace with your model ID
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

# Define the prediction function
def translate_text(input_text):
    inputs = tokenizer(input_text, return_tensors="pt")
    outputs = model.generate(**inputs)
    return tokenizer.decode(outputs[0], skip_special_tokens=True)

# Create the Gradio interface
iface = gr.Interface(
    fn=translate_text,
    inputs="text",
    outputs="text",
    title="Text Translation",
    description="Translate input text using a Hugging Face model."
)

# Launch the Gradio app
if __name__ == "__main__":
    iface.launch()