Translation / app.py
Shangkhonil's picture
Create app.py
f02240a verified
raw
history blame contribute delete
812 Bytes
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()