Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import onnxruntime
|
3 |
+
import transformers import AutoTokenizer
|
4 |
+
import torch
|
5 |
+
|
6 |
+
|
7 |
+
token = AutoTokenizer.from_pretrained('distilroberta-base')
|
8 |
+
|
9 |
+
inf_session = onnxruntime.InferenceSession('classifier1-quantized.onnx')
|
10 |
+
input_name = inf_session.get_inputs()[0].name
|
11 |
+
output_name = inf_session.get_outputs()[0].name
|
12 |
+
|
13 |
+
classes = ['Art', 'Astrology', 'Biology', 'Chemistry', 'Economics', 'History', 'Literature', 'Philosophy', 'Physics', 'Politics', 'Psychology', 'Sociology']
|
14 |
+
|
15 |
+
def classify(review):
|
16 |
+
input_ids = token(review)['input_ids'][:512]
|
17 |
+
logits = inf_session.run([output_name],{input_name : [input_ids]})[0]
|
18 |
+
logits = torch.FloatTensor(logits)
|
19 |
+
prob = torch.sigmoid(logits)[0]
|
20 |
+
return dict(zip(classes,map(float,probs)))
|
21 |
+
|
22 |
+
label = gr.outputs.Label(num_top_classes=5)
|
23 |
+
iface = gr.Interface(fn=classify,inputs='text',outputs = label)
|
24 |
+
iface.launch(inline=False)
|
25 |
+
|
26 |
+
|
27 |
+
|
28 |
+
|