2020-06-10 08:59:21 +08:00
|
|
|
import tensorflow as tf
|
|
|
|
import gradio
|
2020-06-11 02:34:53 +08:00
|
|
|
import os
|
2020-06-10 08:59:21 +08:00
|
|
|
from tensorflow.keras.layers import *
|
|
|
|
import gradio as gr
|
2020-07-09 06:09:52 +08:00
|
|
|
from urllib.request import urlretrieve
|
2020-06-10 08:59:21 +08:00
|
|
|
|
|
|
|
|
2020-07-09 09:01:43 +08:00
|
|
|
urlretrieve("https://gr-models.s3-us-west-2.amazonaws.com/mnist-model.h5", "mnist-model.h5")
|
2020-07-09 06:09:52 +08:00
|
|
|
model = tf.keras.models.load_model("mnist-model.h5")
|
2020-06-10 08:59:21 +08:00
|
|
|
|
2020-07-09 05:53:24 +08:00
|
|
|
|
2020-06-10 08:59:21 +08:00
|
|
|
def recognize_digit(image):
|
2020-07-09 06:09:52 +08:00
|
|
|
prediction = model.predict(image).tolist()[0]
|
2020-06-11 02:34:53 +08:00
|
|
|
return {str(i): prediction[i] for i in range(10)}
|
2020-06-10 08:59:21 +08:00
|
|
|
|
2020-07-09 05:53:24 +08:00
|
|
|
|
2020-06-11 02:34:53 +08:00
|
|
|
gr.Interface(
|
|
|
|
recognize_digit,
|
|
|
|
gradio.inputs.Sketchpad(flatten=True),
|
|
|
|
gradio.outputs.Label(num_top_classes=3),
|
2020-07-09 06:09:52 +08:00
|
|
|
live=True,
|
|
|
|
capture_session=True,
|
|
|
|
).launch()
|