Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,3 @@
|
|
| 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("neuralmind/bert-large-portuguese-cased")
|
| 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('movie-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_movie_genre(sinopse):
|
| 18 |
-
input_ids = tokenizer(sinopse)['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_movie_genre, inputs="text", outputs=label)
|
| 26 |
-
iface.launch(inline=False)"""
|
| 27 |
-
|
| 28 |
import gradio as gr
|
| 29 |
import onnxruntime as rt
|
| 30 |
from transformers import AutoTokenizer
|
|
@@ -71,5 +44,5 @@ inputs = [
|
|
| 71 |
|
| 72 |
|
| 73 |
label = gr.outputs.Label(num_top_classes=4)
|
| 74 |
-
iface = gr.Interface(fn=classify_movie_genre, inputs=inputs, outputs=label, examples=app_examples)
|
| 75 |
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import onnxruntime as rt
|
| 3 |
from transformers import AutoTokenizer
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
label = gr.outputs.Label(num_top_classes=4)
|
| 47 |
+
iface = gr.Interface(fn=classify_movie_genre, inputs=inputs, outputs=label, examples=app_examples, theme='gradio/monochrome')
|
| 48 |
iface.launch()
|