File size: 493 Bytes
fc2c13a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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()