File size: 883 Bytes
0c055f3
40c38d1
3cad0c7
7ef6ec1
4a04f4f
0ce8c49
 
 
 
 
 
 
 
 
 
 
7102374
7ef6ec1
 
 
4a04f4f
7ef6ec1
 
2b52a97
0c055f3
0ce8c49
 
 
 
 
 
29196b3
0ce8c49
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
30
31
32
33
import gradio as gr
from fastbook import load_learner
from fastai.vision.all import *
from PIL import Image

js_func = """
function refresh() {
    const url = new URL(window.location);

    if (url.searchParams.get('__theme') !== 'dark') {
        url.searchParams.set('__theme', 'dark');
        window.location.href = url.href;
    }
}
"""

def predict(im):
	resized_im = im['composite'].resize((28,28))
	pred,idx,probs = model.predict(resized_im)
	return dict(zip(categories, map(float,probs)))

categories = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
model = load_learner('./dr_model.pkl')
labels = model.dls.vocab

with gr.Blocks(js=js_func) as demo:
    demo = gr.Interface(
    	fn=predict,
    	inputs=gr.Sketchpad(image_mode='L', brush=gr.Brush(default_color="FFFFFFFF"), type='pil'),
    	outputs = "label",
        theme=gr.themes.Monochrome())

    demo.launch()