# from transformers import pipeline # import gradio as grad # model_name = "Helsinki-NLP/opus-mt-en-de" # opus_translator = pipeline("translation", model=model_name) # def translate(text): # response = opus_translator(text) # return response # grad.Interface(translate, inputs=["text",], outputs="text").launch() #Please make sure you have `sentencepiece` installed in order to use this tokenizer. from transformers import pipeline import gradio as grad model_name = "Helsinki-NLP/opus-mt-en-de" opus_translator = pipeline("translation", model=model_name) def translate(text): response = opus_translator(text) return response[0]['translation_text'] iface = grad.Interface( fn=translate, inputs=[ grad.Textbox( placeholder="Enter the text in English...", label="English Text", lines=5 ) ], outputs=grad.Textbox(label="German Translation"), live=True, title="English to German Translator", description="Type in English and get the translation in German instantly!", examples=[ ["Hello, how are you?"], ["The weather is nice today."], ["Gradio is great for creating interfaces."] ], theme="dark", # Use a dark theme for the interface layout="horizontal", # Use a horizontal layout allow_flagging="never", # Disable the flagging option css=""" .interface { max-width: 800px; margin: auto; } .input_textbox { font-size: 16px; } .output_textbox { font-size: 16px; } """ ) iface.launch()