from transformers import pipeline import gradio as gr import torch pipe = pipeline('translation', model='facebook/nllb-200-distilled-600M', torch_dtype=torch.bfloat16) langs=["eng_Latn", "zho_Hant", "zho_Hans", "jpn_Jpan", "kor_Hang","spa_Latn"] def translate(text, tgt_lang='eng_Latin'): return pipe(text, src_lang='zho_Hant', tgt_lang=tgt_lang)[0]['translation_text'] iface = gr.Interface(translate, inputs=[gr.Textbox(label='',lines=3), gr.Radio(langs, label='語言')], outputs=gr.Textbox(label='',lines=3), title='全能翻譯王') iface.launch()