Spaces:
Running
Running
Upload 4 files
Browse files- app.py +29 -0
- film_genre_classifier_quantized.onnx +3 -0
- genre_types_encoded_multi_class.json +1 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import onnxruntime as rt
|
3 |
+
from transformers import AutoTokenizer
|
4 |
+
import torch, json
|
5 |
+
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("distilroberta-base")
|
7 |
+
|
8 |
+
with open("genre_types_encoded_multi_class.json", "r") as fp:
|
9 |
+
encode_genre_types = json.load(fp)
|
10 |
+
|
11 |
+
genres = list(encode_genre_types.keys())
|
12 |
+
|
13 |
+
|
14 |
+
inf_session = rt.InferenceSession('paper_task_classifier_quantized.onnx')
|
15 |
+
input_name = inf_session.get_inputs()[0].name
|
16 |
+
output_name = inf_session.get_outputs()[0].name
|
17 |
+
|
18 |
+
|
19 |
+
def classify_film_genre(description):
|
20 |
+
input_ids = tokenizer(description)['input_ids'][:512]
|
21 |
+
logits = inf_session.run([output_name], {input_name: [input_ids]})[0]
|
22 |
+
logits = torch.FloatTensor(logits)
|
23 |
+
probs = torch.sigmoid(logits)[0]
|
24 |
+
return dict(zip(genres, map(float, probs)))
|
25 |
+
|
26 |
+
label = gr.outputs.Label(num_top_classes=5)
|
27 |
+
iface = gr.Interface(fn=classify_film_genre, inputs="text", outputs=label)
|
28 |
+
iface.launch(inline=False)
|
29 |
+
|
film_genre_classifier_quantized.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:67882ca32c6eb286e4922f000644491d3a386fcfb9bd8f81b17536bbe55d0c97
|
3 |
+
size 82588680
|
genre_types_encoded_multi_class.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"Drama": 0, "Crime": 1, "Adventure": 2, "Biography": 3, "War": 4, "History": 5, "Mystery": 6, "Romance": 7, "Thriller": 8, "Film-Noir": 9, "Comedy": 10, "Musical": 11, "Animation": 12, "Family": 13, "Fantasy": 14, "Action": 15, "Western": 16, "Music": 17, "Documentary": 18, "Sport": 19, "Sci-Fi": 20, "Horror": 21, "News": 22, "Unknown": 23, "Reality-TV": 24, "Talk-Show": 25, "Game-Show": 26}
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.17.0
|
2 |
+
onnxruntime==1.13.1
|
3 |
+
torch==1.13.1
|
4 |
+
transformers==4.26.0
|