Spaces:
Sleeping
Sleeping
app.py changed
Browse files
app.py
CHANGED
|
@@ -5,22 +5,22 @@ import torch, json
|
|
| 5 |
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained("distilroberta-base")
|
| 7 |
|
| 8 |
-
with open("
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
-
inf_session = rt.InferenceSession('
|
| 14 |
input_name = inf_session.get_inputs()[0].name
|
| 15 |
output_name = inf_session.get_outputs()[0].name
|
| 16 |
|
| 17 |
-
def
|
| 18 |
input_ids = tokenizer(description)['input_ids'][:512]
|
| 19 |
logits = inf_session.run([output_name], {input_name: [input_ids]})[0]
|
| 20 |
logits = torch.FloatTensor(logits)
|
| 21 |
probs = torch.sigmoid(logits)[0]
|
| 22 |
-
return dict(zip(
|
| 23 |
|
| 24 |
label = gr.outputs.Label(num_top_classes=5)
|
| 25 |
-
iface = gr.Interface(fn=
|
| 26 |
iface.launch(inline=False)
|
|
|
|
| 5 |
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained("distilroberta-base")
|
| 7 |
|
| 8 |
+
with open("tag_types_encoded.json", "r") as fp:
|
| 9 |
+
encode_tag_types = json.load(fp)
|
| 10 |
|
| 11 |
+
tags = list(encode_tag_types.keys())
|
| 12 |
|
| 13 |
+
inf_session = rt.InferenceSession('quote-classifier-quantized.onnx')
|
| 14 |
input_name = inf_session.get_inputs()[0].name
|
| 15 |
output_name = inf_session.get_outputs()[0].name
|
| 16 |
|
| 17 |
+
def classify_book_tag(description):
|
| 18 |
input_ids = tokenizer(description)['input_ids'][:512]
|
| 19 |
logits = inf_session.run([output_name], {input_name: [input_ids]})[0]
|
| 20 |
logits = torch.FloatTensor(logits)
|
| 21 |
probs = torch.sigmoid(logits)[0]
|
| 22 |
+
return dict(zip(tags, map(float, probs)))
|
| 23 |
|
| 24 |
label = gr.outputs.Label(num_top_classes=5)
|
| 25 |
+
iface = gr.Interface(fn=classify_book_tag, inputs="text", outputs=label)
|
| 26 |
iface.launch(inline=False)
|