CoolFace
Apppublic

ayymen/Machine-Translation

sourceHugging Faceupdated 3y agoView on Hugging Face
6likes
app.py32 linesDownload Raw Back to root
1import gradio as gr2from transformers import pipeline3 4models = [5    "Helsinki-NLP/opus-mt-en-ber",6    "Helsinki-NLP/opus-mt-ber-en",7    "Helsinki-NLP/opus-mt-fr-ber",8    "Helsinki-NLP/opus-mt-ber-fr",9    "Helsinki-NLP/opus-mt-es-ber",10    "Helsinki-NLP/opus-mt-ber-es",11    "Helsinki-NLP/opus-mt-kab-en"12]13 14pipes = {}15 16def predict(text, model):17    if model not in pipes:18        pipes[model] = pipeline("translation", model=model)19    pipe = pipes[model]20    return pipe(text)[0]['translation_text']21 22demo = gr.Interface(23    fn=predict,24    inputs=[25        gr.Textbox(lines=5, label="Input Text"),26        gr.Dropdown(models, label="Model")27    ],28    outputs='text',29)30 31demo.launch()32