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

# Initialize the translation pipeline
pipe = pipeline("translation", model="google-t5/t5-base")

# Define the translation function
def translate(text):
    translation = pipe(text)
    return translation[0]['translation_text']

# Create the Gradio interface
iface = gr.Interface(
    fn=translate,
    inputs="text",
    outputs="text",
    title="Text Translation with T5",
    description="Enter text to translate it using the Google T5 model.",
)

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