Spaces:
Sleeping
Sleeping
File size: 899 Bytes
a25a44c 05a0ac5 be549be a25a44c 05a0ac5 a25a44c 05a0ac5 be549be b87b96d 05a0ac5 be549be 0433860 05a0ac5 0433860 764f2a7 d0aa01e be549be |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import gradio as gr
import onnxruntime as rt
from transformers import AutoTokenizer
import torch, json
tokenizer = AutoTokenizer.from_pretrained("distilroberta-base")
with open("genre_types_encoded.json", "r") as fp:
encode_genre_types = json.load(fp)
genres = list(encode_genre_types.keys())
inf_session = rt.InferenceSession('movie-classifier.onnx')
input_name = inf_session.get_inputs()[0].name
output_name = inf_session.get_outputs()[0].name
def classify_movie_genre(Overview):
input_ids = tokenizer(Overview)['input_ids'][:512]
logits = inf_session.run([output_name], {input_name: [input_ids]})[0]
logits = torch.FloatTensor(logits)
probs = torch.sigmoid(logits)[0]
return dict(zip(genres, map(float, probs)))
label = gr.outputs.Label(num_top_classes=5)
iface = gr.Interface(fn=classify_movie_genre, inputs="text", outputs=label)
iface.launch(inline=False)
|