File size: 552 Bytes
ce927da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import gradio as gr
from transformers import pipeline

# Load translation pipeline
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-tc-big-en-es")

def translate_text(text):
    result = translator(text, max_length=400)
    return result[0]["translation_text"]

# Gradio interface
iface = gr.Interface(
    fn=translate_text,
    inputs="text",
    outputs="text",
    title="English to Spanish Translator",
    description="Translate English sentences into Spanish using a pre-trained NLP model."
)

iface.launch()