File size: 729 Bytes
a43ccba
9adca0e
a43ccba
16e1dde
a43ccba
16e1dde
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import gradio as gr
import torch

labels = ['Zero','Um','Dois','Três','Quatro','Cinco','Seis','Sete','Oito', 'Nove']

# LOADING MODEL
model.load_state_dict(torch.load("model_mnist.pth", map_location=torch.device('cuda')))


def predict(input):
  input = torch.from_numpy(input.reshape(1, 1, 28, 28)).to(dtype=torch.float32, device=device)

  with torch.no_grad():
    outputs = model(input)  
    prediction = torch.nn.functional.softmax(outputs[0], dim=0)
    confidences = {labels[i]: float(prediction[i]) for i in range(10)}    
  return confidences

gr.Interface(title='Classificador de dígitos', fn=predict, 
             inputs="sketchpad",
             outputs=gr.Label(num_top_classes=3)).launch(share=True, debug=True)