Spaces:
Sleeping
Sleeping
app ready
Browse files- app.py +27 -4
- game-classifier-quantized-kaggle.onnx +3 -0
- genre_types_encoded_kaggle_onnx.json +1 -0
- requirements.txt +3 -0
app.py
CHANGED
@@ -1,9 +1,32 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
|
3 |
|
4 |
-
|
5 |
-
return "Hello " + name + "!!"
|
6 |
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import json
|
3 |
+
import torch
|
4 |
+
import onnxruntime as rt
|
5 |
+
from transformers import AutoTokenizer
|
6 |
|
7 |
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained("distilroberta-base")
|
|
|
9 |
|
10 |
+
with open("genre_types_encoded_kaggle_onnx.json", "r") as file:
|
11 |
+
encode_genre_types = json.load(file)
|
12 |
|
13 |
+
|
14 |
+
genres = list(encode_genre_types.keys())
|
15 |
+
|
16 |
+
|
17 |
+
inf_session = rt.InferenceSession("game-classifier-quantized-kaggle.onnx")
|
18 |
+
input_name = inf_session.get_inputs()[0].name
|
19 |
+
output_name = inf_session.get_outputs()[0].name
|
20 |
+
|
21 |
+
|
22 |
+
def classify_game_genre(summary):
|
23 |
+
input_ids = tokenizer(summary)["input_ids"][:512]
|
24 |
+
logits = inf_session.run([output_name], {input_name: [input_ids]})[0]
|
25 |
+
logits = torch.FloatTensor(logits)
|
26 |
+
probs = torch.sigmoid(logits)[0]
|
27 |
+
return dict(zip(genres, map(float, probs)))
|
28 |
+
|
29 |
+
|
30 |
+
labels = gr.outputs.Label(num_top_classes=5)
|
31 |
+
iface = gr.Interface(fn=classify_game_genre, inputs="text", outputs=labels)
|
32 |
+
iface.launch(inline=False)
|
game-classifier-quantized-kaggle.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ae1fa02e59b6e14910aa46994bbcf3d13541783b001c8d383233d6404ee18ceb
|
3 |
+
size 82490912
|
genre_types_encoded_kaggle_onnx.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"Casual": 0, "Indie": 1, "Sports": 2, "Action": 3, "Adventure": 4, "Strategy": 5, "Massively Multiplayer": 6, "RPG": 7, "Free to Play": 8, "Simulation": 9, "Early Access": 10, "Racing": 11, "Utilities": 12, "Education": 13, "Violent": 14, "Gore": 15, "Design & Illustration": 16, "Animation & Modeling": 17, "Game Development": 18, "Software Training": 19, "Video Production": 20}
|
requirements.txt
CHANGED
@@ -1 +1,4 @@
|
|
1 |
gradio==3.41.2
|
|
|
|
|
|
|
|
1 |
gradio==3.41.2
|
2 |
+
torch==2.0.1
|
3 |
+
onnxruntime==1.15.1
|
4 |
+
transformers==4.32.1
|