import gradio as gr from transformers import pipeline pipe = pipeline("text-classification","uer/roberta-base-finetuned-jd-binary-chinese") def clf(text): result = pipe(text) label = result[0]['label'] score = result[0]['score'] res = {label:score,'positive' if label.startswith('negative') else 'negative': 1-score} return res demo = gr.Interface(fn=clf, inputs=gr.Textbox(label="输入文本"), outputs=gr.Label(label="输出结果")) gr.close_all() demo.launch()