zzarif commited on
Commit
66c5291
·
1 Parent(s): 542f5e5

Initial commit

Browse files
README.md CHANGED
@@ -1,13 +1,15 @@
1
  ---
2
  title: Multilabel Scifi Tags Classifier
3
- emoji: 🌍
4
- colorFrom: red
5
- colorTo: indigo
6
  sdk: gradio
7
- sdk_version: 4.38.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
1
  ---
2
  title: Multilabel Scifi Tags Classifier
3
+ emoji: 🏢
4
+ colorFrom: green
5
+ colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 3.50.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
+
15
+ HuggingFace Spaces App URL: https://huggingface.co/spaces/zzarif/Multilabel-Scifi-Tags-Classifier
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("tag_types_encoded.json", "r") as fp:
9
+ encode_tag_types = json.load(fp)
10
+
11
+ genres = list(encode_tag_types.keys())
12
+
13
+ inf_session = rt.InferenceSession('question-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_question_tags(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_question_tags, inputs="text", outputs=label)
26
+ iface.launch(inline=False)
27
+
question-classifier-quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f0b77757323507e5e90e1ff6edebc2ef87aec8520883a9c6fa5e918e8ed75eb1
3
+ size 82681062
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio==3.50.0
2
+ onnxruntime==1.18.0
3
+ torch==1.13.1
4
+ transformers==4.41.2
tag_types_encoded.json ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "the-lord-of-the-rings": 0,
3
+ "tolkiens-legendarium": 1,
4
+ "the-one-ring": 2,
5
+ "star-wars": 3,
6
+ "the-force": 4,
7
+ "the-empire-strikes-back": 5,
8
+ "harry-potter": 6,
9
+ "technology": 7,
10
+ "story-identification": 8,
11
+ "short-stories": 9,
12
+ "time-travel": 10,
13
+ "suggested-order": 11,
14
+ "back-to-the-future": 12,
15
+ "behind-the-scenes": 13,
16
+ "j-r-r-tolkien": 14,
17
+ "dc": 15,
18
+ "character-identification": 16,
19
+ "hogwarts": 17,
20
+ "a-new-hope": 18,
21
+ "the-hitchhikers-guide-to-the-galaxy": 19,
22
+ "batman": 20,
23
+ "the-matrix": 21,
24
+ "gandalf": 22,
25
+ "isaac-asimov": 23,
26
+ "horcrux": 24,
27
+ "magical-theory": 25,
28
+ "star-trek": 26,
29
+ "star-trek-tng": 27,
30
+ "the-force-awakens": 28,
31
+ "uss-enterprise": 29,
32
+ "star-wars-legends": 30,
33
+ "spaceship": 31,
34
+ "marvel": 32,
35
+ "marvel-cinematic-universe": 33,
36
+ "sauron": 34,
37
+ "religion": 35,
38
+ "comics": 36,
39
+ "sith": 37,
40
+ "darth-vader": 38,
41
+ "return-of-the-jedi": 39,
42
+ "revenge-of-the-sith": 40,
43
+ "albus-dumbledore": 41,
44
+ "severus-snape": 42,
45
+ "luke-skywalker": 43,
46
+ "obi-wan-kenobi": 44,
47
+ "star-trek-tos": 45,
48
+ "voldemort": 46,
49
+ "the-return-of-the-king": 47,
50
+ "discworld": 48,
51
+ "game-of-thrones": 49,
52
+ "a-song-of-ice-and-fire": 50,
53
+ "jk-rowling": 51,
54
+ "rogue-one": 52,
55
+ "death-star": 53,
56
+ "the-hobbit": 54,
57
+ "powers": 55,
58
+ "darth-sidious": 56,
59
+ "borg": 57,
60
+ "adaptation-comparison": 58,
61
+ "the-fellowship-of-the-ring": 59,
62
+ "history-of": 60,
63
+ "iron-man": 61,
64
+ "weapon": 62,
65
+ "elves": 63,
66
+ "artificial-intelligence": 64,
67
+ "magic": 65,
68
+ "spells": 66,
69
+ "books": 67,
70
+ "aliens": 68,
71
+ "science-fiction-genre": 69,
72
+ "the-hunger-games": 70,
73
+ "avengers": 71,
74
+ "thor-marvel": 72,
75
+ "the-silmarillion": 73,
76
+ "dragons": 74,
77
+ "muggles": 75,
78
+ "the-last-jedi": 76,
79
+ "droids": 77,
80
+ "star-trek-voyager": 78,
81
+ "names": 79,
82
+ "languages": 80,
83
+ "canon": 81,
84
+ "jedi": 82,
85
+ "vampire": 83,
86
+ "middle-earth": 84,
87
+ "captain-america": 85,
88
+ "the-avengers-2012": 86,
89
+ "kylo-ren": 87,
90
+ "doctor-who": 88,
91
+ "star-trek-data": 89,
92
+ "the-rise-of-skywalker": 90,
93
+ "x-men": 91,
94
+ "babylon-5": 92,
95
+ "the-phantom-menace": 93,
96
+ "hard-sci-fi": 94,
97
+ "battlestar-galactica": 95,
98
+ "video-games": 96,
99
+ "movie": 97,
100
+ "star-trek-2009": 98,
101
+ "futurama": 99,
102
+ "avengers-age-of-ultron": 100,
103
+ "the-incredible-hulk": 101,
104
+ "character-motivation": 102,
105
+ "lightsaber": 103,
106
+ "star-trek-ds9": 104,
107
+ "episode-identification": 105,
108
+ "horror": 106,
109
+ "magical-creatures": 107,
110
+ "space-exploration": 108,
111
+ "computers": 109,
112
+ "superman": 110,
113
+ "object-identification": 111,
114
+ "klingon": 112,
115
+ "nolan-batman-trilogy": 113,
116
+ "stargate": 114,
117
+ "the-terminator": 115,
118
+ "the-terminator-series": 116,
119
+ "robots": 117,
120
+ "death-eaters": 118,
121
+ "firefly": 119,
122
+ "alien-franchise": 120,
123
+ "spider-man": 121,
124
+ "avengers-infinity-war": 122,
125
+ "inspiration": 123,
126
+ "dc-extended-universe": 124,
127
+ "tv": 125,
128
+ "quotes": 126,
129
+ "wolverine": 127,
130
+ "attack-of-the-clones": 128,
131
+ "clones": 129,
132
+ "dune": 130,
133
+ "the-clone-wars": 131,
134
+ "the-wheel-of-time": 132,
135
+ "quidditch": 133,
136
+ "soft-sci-fi": 134,
137
+ "wandlore": 135,
138
+ "science": 136,
139
+ "novel": 137,
140
+ "robert-a-heinlein": 138,
141
+ "the-walking-dead": 139,
142
+ "avengers-endgame": 140,
143
+ "x-men-cinematic-universe": 141,
144
+ "dystopia": 142,
145
+ "parallel-universe": 143,
146
+ "star-trek-discovery": 144,
147
+ "avatar-the-last-airbender": 145,
148
+ "post-apocalyptic": 146,
149
+ "alien-invasion": 147,
150
+ "stargate-sg1": 148,
151
+ "star-trek-enterprise": 149,
152
+ "space": 150,
153
+ "fantastic-beasts": 151,
154
+ "cartoon": 152,
155
+ "young-adult": 153,
156
+ "anime": 154,
157
+ "space-colonization": 155,
158
+ "warhammer-40k": 156,
159
+ "telepathy": 157,
160
+ "childrens-novel": 158,
161
+ "anthology-book": 159
162
+ }