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.inputs.Textbox(lines=2, placeholder="Enter English text here..."), outputs="text", 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()