Mnist-Digits / app.py
cisemh's picture
Update app.py
13f8a14 verified
raw
history blame
1.03 kB
import cv2
import gradio as gr
import tensorflow as tf
import numpy as np
# Title and description for the interface
title = "Welcome to your first sketch recognition app!"
head = "<center>The robot was trained to classify numbers (0 to 9). To test it, write your number in the space provided.</center>"
# Load the trained model
model = tf.keras.models.load_model("number_recognition_model_colab.keras")
def recognize_digit(image):
if image is not None:
image = image.reshape((1, 28, 28, 1)).astype('float32')/255
prediction = model.predict(image)
return {str(i): float(prediction[0][i]) for i in range(10)}
else:
return ''
# Build and launch the Gradio interface
demo = gr.Interface(
fn = recognize_digit,
inputs = gr.Image(
shape=(28, 28),
image_mode='L',
invert_colors=True,
source='canvas',
brush_radius=1,
tool="color-sketch",
),
outputs = gr.Label(num_top_classes=3),
live = True
).launch(share=True)