Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Initialize the translation pipeline with a pre-trained model | |
translator = pipeline("translation_en_to_fr", model="t5-small") | |
def translate(text): | |
# Translate the input text from English to French | |
result = translator(text, max_length=512) | |
return result[0]['translation_text'] | |
# Define the Gradio interface | |
iface = gr.Interface( | |
fn=translate, | |
inputs=gr.Textbox(lines=2, placeholder="Enter English text here..."), | |
outputs=gr.Textbox(), # Updated for Gradio version 4.0 | |
title="English to French Translation", | |
description="This app uses the T5 model to translate English text to French. Type some text and press submit." | |
) | |
# Launch the app | |
if __name__ == "__main__": | |
iface.launch() | |