File size: 702 Bytes
b6d9cbc
 
15233eb
 
b6d9cbc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from keras.models import load_model
import cv2
import gradio as gr
import numpy as np
loaded_model = load_model('model.h5')

def predict(img):
  img = img['composite'][:,:,3]/255.0
  img = cv2.resize(img, (28, 28))
  prediction = np.argmax(loaded_model.predict(np.array([img]) ,verbose=0))
  return prediction

input = [gr.Sketchpad(label="Sketchpad",  canvas_size= (600,600) , image_mode = "RGBA")]
interface = gr.Interface(
    fn=predict,
    inputs=input,
    outputs="textbox",
    title="MNIST Handwritten Digit Recognition by Johnson Manuel",
    description="Draw digits from 0 to 9 to see real-time recognition by a neural network trained on the MNIST dataset." ,live=True
)
interface.launch()