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

# Initialize the translation pipeline with source (en) and target (de) languages
pipe = pipeline("translation_en_to_de", model="google-t5/t5-small")

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

# Set up the Gradio interface with updated components
app = gr.Interface(
    fn=translate,                    # Function for translation
    inputs=gr.Textbox(lines=2, placeholder="Enter text to translate"),  # Updated input field
    outputs=gr.Textbox(),             # Updated output field
    title="Text Translator",          # Title of the app
    description="Enter text to translate from English to German using Google T5 small model."
)

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