Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import onnxruntime
|
3 |
+
from transformers import AutoTokenizer
|
4 |
+
import torch, json
|
5 |
+
|
6 |
+
token = AutoTokenizer.from_pretrained('distilroberta-base')
|
7 |
+
|
8 |
+
types = ['toxic',
|
9 |
+
'severe_toxic',
|
10 |
+
'obscene',
|
11 |
+
'threat',
|
12 |
+
'insult',
|
13 |
+
'identity_hate',
|
14 |
+
'positive']
|
15 |
+
|
16 |
+
inf_session = onnxruntime.InferenceSession('classifier-quantized.onnx')
|
17 |
+
input_name = inf_session.get_inputs()[0].name
|
18 |
+
output_name = inf_session.get_outputs()[0].name
|
19 |
+
|
20 |
+
def classify(review):
|
21 |
+
input_ids = token(description)['input_ids'][:512]
|
22 |
+
logits = inf_session.run([output_name], {input_name: [input_ids]})[0]
|
23 |
+
logits = torch.FloatTensor(logits)
|
24 |
+
probs = torch.sigmoid(logits)[0]
|
25 |
+
return dict(zip(genres, map(float, probs)))
|
26 |
+
|
27 |
+
|
28 |
+
label = gr.outputs.Label(num_top_classes=3)
|
29 |
+
iface = gr.Interface(fn=classify,inputs='text',outputs = label)
|
30 |
+
iface.launch(inline=False)
|