|
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() |