File size: 828 Bytes
bb22eb8
9d79f7e
8d027cb
 
2244b0c
8d027cb
 
 
 
 
 
71828e8
8d027cb
 
 
 
259344b
 
8d027cb
5f09d1f
374cec5
8a0cad7
1b99eaa
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
33
34
35
import gradio as gr
import json
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",
    binary_output=True,
)

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

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

demo.launch()