File size: 778 Bytes
bb22eb8
8d027cb
 
2244b0c
8d027cb
 
 
 
 
 
71828e8
527cc9f
 
 
 
 
8d027cb
5f09d1f
374cec5
8a0cad7
527cc9f
260fdda
1b99eaa
 
bdd14b5
 
 
 
9d79f7e
bdd14b5
 
5f09d1f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import gradio as gr
from transformers import AutoTokenizer, pipeline
from optimum.onnxruntime import ORTModelForSequenceClassification

model_id = "SamLowe/roberta-base-go_emotions-onnx"
file_name = "onnx/model_quantized.onnx"

model = ORTModelForSequenceClassification.from_pretrained(model_id, file_name=file_name)
tokenizer = AutoTokenizer.from_pretrained(model_id)

classifier = pipeline(
    task = "text-classification",
    model = model,
    tokenizer = tokenizer,
    top_k = None,
    function_to_apply = "sigmoid",
)

def predict(param_0):
    results = classifier(param_0)
    return {
        "label": results[0][0]["label"],
        "confidences": results[0]
    }

demo = gr.Interface(
    fn = predict,
    inputs = 'text',
    outputs = 'json',
)

demo.launch()