Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import onnxruntime as rt
|
| 3 |
from transformers import AutoTokenizer
|
| 4 |
-
import torch
|
|
|
|
| 5 |
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained("distilroberta-base")
|
| 7 |
|
| 8 |
with open("tag_types_encoded(1).json", "r") as fp:
|
| 9 |
-
|
| 10 |
|
| 11 |
genres = list(encode_genre_types.keys())
|
| 12 |
|
|
@@ -15,13 +16,15 @@ input_name = inf_session.get_inputs()[0].name
|
|
| 15 |
output_name = inf_session.get_outputs()[0].name
|
| 16 |
|
| 17 |
def classify_Quote_tag(Quote):
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
| 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(1).json", "r") as fp:
|
| 10 |
+
encode_genre_types = json.load(fp)
|
| 11 |
|
| 12 |
genres = list(encode_genre_types.keys())
|
| 13 |
|
|
|
|
| 16 |
output_name = inf_session.get_outputs()[0].name
|
| 17 |
|
| 18 |
def classify_Quote_tag(Quote):
|
| 19 |
+
input_ids = tokenizer(Quote)['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(genres, map(float, probs)))
|
| 24 |
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=classify_Quote_tag,
|
| 27 |
+
inputs="text",
|
| 28 |
+
outputs=gr.Label(num_top_classes=5) # Use gr.Label for the label output
|
| 29 |
+
)
|
| 30 |
+
iface.launch(inline=False)
|