Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import onnxruntime
|
| 3 |
+
from transformars import AutoTokenizer
|
| 4 |
+
import torch, json
|
| 5 |
+
|
| 6 |
+
token = AutoTokenizer.from_pretrained('distilbert-base-uncased-finetuned-sst-2-english')
|
| 7 |
+
|
| 8 |
+
types = [{0:'Positive'},1:{'Negative'}]
|
| 9 |
+
|
| 10 |
+
inf_session = onnxruntime.InferenceSession('classifier_quantizer.onnx')
|
| 11 |
+
input_name = inf_session.get_inputs()[0].name
|
| 12 |
+
output_name = inf_session.get_outputs()[0].name
|
| 13 |
+
|
| 14 |
+
def classify(review):
|
| 15 |
+
input_ids = token(review)['inputs_ids'][:512]
|
| 16 |
+
logits = inf_session.run([output_name],{input_name: [input_ids]})[0]
|
| 17 |
+
logits = torch.FloatTensorlogits(logits)
|
| 18 |
+
probs = torch.sigmoid(logits)[0]
|
| 19 |
+
return dict(zip(types,map(float,probs)))
|
| 20 |
+
|
| 21 |
+
label = gr.outputs.label()
|
| 22 |
+
iface = gr.Interface(fn=classify,inputs='text',outputs = label)
|
| 23 |
+
iface.launch(inline=False)
|