Spaces:
Build error
Build error
ni6670154@gmail.com commited on
Commit ·
b017d2f
1
Parent(s): de43d3c
modified app
Browse files
app.py
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import onnxruntime as rt
|
| 3 |
from transformers import AutoTokenizer
|
|
@@ -22,5 +48,7 @@ def classify_book_genre(quotes):
|
|
| 22 |
probs = torch.sigmoid(logits)[0]
|
| 23 |
return dict(zip(tags, map(float, probs)))
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
iface.launch(inline=False)
|
|
|
|
| 1 |
+
# import gradio as gr
|
| 2 |
+
# import onnxruntime as rt
|
| 3 |
+
# from transformers import AutoTokenizer
|
| 4 |
+
# import torch
|
| 5 |
+
# import json
|
| 6 |
+
|
| 7 |
+
# tokenizer = AutoTokenizer.from_pretrained("distilroberta-base")
|
| 8 |
+
|
| 9 |
+
# with open("tag_types_encoded.json", "r") as fp:
|
| 10 |
+
# encode_tag_types = json.load(fp)
|
| 11 |
+
|
| 12 |
+
# tags = list(encode_tag_types.keys())
|
| 13 |
+
|
| 14 |
+
# inf_session = rt.InferenceSession('book-classifier-quantized.onnx')
|
| 15 |
+
# input_name = inf_session.get_inputs()[0].name
|
| 16 |
+
# output_name = inf_session.get_outputs()[0].name
|
| 17 |
+
|
| 18 |
+
# def classify_book_genre(quotes):
|
| 19 |
+
# input_ids = tokenizer(quotes)['input_ids'][:512]
|
| 20 |
+
# logits = inf_session.run([output_name], {input_name: [input_ids]})[0]
|
| 21 |
+
# logits = torch.FloatTensor(logits)
|
| 22 |
+
# probs = torch.sigmoid(logits)[0]
|
| 23 |
+
# return dict(zip(tags, map(float, probs)))
|
| 24 |
+
|
| 25 |
+
# iface = gr.Interface(fn=classify_book_genre, inputs="text", outputs="label")
|
| 26 |
+
# iface.launch(inline=False)
|
| 27 |
import gradio as gr
|
| 28 |
import onnxruntime as rt
|
| 29 |
from transformers import AutoTokenizer
|
|
|
|
| 48 |
probs = torch.sigmoid(logits)[0]
|
| 49 |
return dict(zip(tags, map(float, probs)))
|
| 50 |
|
| 51 |
+
# Use only the first 10 tags in the Label component
|
| 52 |
+
label = gr.outputs.Label(label=tags[:10])
|
| 53 |
+
iface = gr.Interface(fn=classify_book_genre, inputs="text", outputs=label)
|
| 54 |
iface.launch(inline=False)
|