abrar-adnan commited on
Commit
6215077
1 Parent(s): b15cf9e

initial commit

Browse files
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("distilroberta-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('book-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_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_book_genre, inputs="text", outputs=label)
26
+ iface.launch(inline=False)
27
+
book-classifier-quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4640d0ab8a3191a47e741182c59afc2841aa1ae90d54a2703e049cec13c566ac
3
+ size 82634501
genre_types_encoded.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"Action": 0, "Beat-'Em-Up": 1, "Fighting": 2, "2D": 3, "Platformer": 4, "Adventure": 5, "3D": 6, "First-Person": 7, "General": 8, "Shooter": 9, "Arcade": 10, "Miscellaneous": 11, "Party / Minigame": 12, "Role-Playing": 13, "Strategy": 14, "Real-Time": 15, "Japanese-Style": 16, "Tactics": 17, "Visual Novel": 18, "Action Adventure": 19, "Open-World": 20, "Third-Person": 21, "Puzzle": 22, "Rhythm": 23, "Music": 24, "Linear": 25, "Simulation": 26, "Vehicle": 27, "Racing": 28, "Automobile": 29, "Turn-Based": 30, "Action RPG": 31, "Sports": 32, "Team": 33, "Sim": 34, "Shoot-'Em-Up": 35, "Top-Down": 36, "Individual": 37, "Combat": 38, "Vertical": 39, "Horizontal": 40, "Virtual": 41, "Career": 42, "Survival": 43, "Point-and-Click": 44, "Compilation": 45, "Metroidvania": 46, "Management": 47, "Business / Tycoon": 48, "Tactical": 49, "Virtual Life": 50}
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