Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files- app.py +27 -0
- genre_types_encoded.json +1 -0
- genres-classifier-quantized.onnx +3 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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("roberta-base")
|
7 |
+
|
8 |
+
with open("genre_types_encoded.json", "r") as fp:
|
9 |
+
encode_genre_types = json.load(fp)
|
10 |
+
|
11 |
+
genres = list(encode_genre_types.keys())
|
12 |
+
|
13 |
+
inf_session = rt.InferenceSession('genres-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_movietvshow_genre(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(genres, map(float, probs)))
|
23 |
+
|
24 |
+
label = gr.outputs.Label(num_top_classes=5)
|
25 |
+
iface = gr.Interface(fn=classify_movietvshow_genre, inputs="text", outputs=label)
|
26 |
+
iface.launch(inline=False)
|
27 |
+
|
genre_types_encoded.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"Action": 0, "Thriller": 1, "Drama": 2, "Crime": 3, "Sport": 4, "Comedy": 5, "Mystery": 6, "Biography": 7, "Documentary": 8, "Sci-Fi": 9, "Romance": 10, "Western": 11, "Fantasy": 12, "Horror": 13, "Animation": 14, "Adventure": 15, "Family": 16, "History": 17, "War": 18, "Musical": 19, "Music": 20, "Reality-TV": 21, "Game-Show": 22}
|
genres-classifier-quantized.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:76313440f31d8176acc13ab4496b44f4c795ee3527dd1faa3f114fb74c427aee
|
3 |
+
size 125514820
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==4.14.0
|
2 |
+
onnxruntime==1.16.3
|
3 |
+
torch==1.13.1
|
4 |
+
transformers==4.35.2
|