|
|
|
|
|
import tensorflow as tf |
|
import cv2 |
|
import numpy as np |
|
import gradio as gr |
|
|
|
|
|
|
|
def model(up_img): |
|
cnn = tf.keras.models.load_model("Handwritten_Digit_Recognition_Model.h5") |
|
|
|
|
|
gray_image = cv2.cvtColor(up_img, cv2.COLOR_BGR2GRAY) |
|
|
|
|
|
gray_image = np.expand_dims(gray_image, axis = -1) |
|
gray_image = gray_image.reshape((-1, 28, 28, 1)) |
|
|
|
|
|
prediction = cnn.predict(gray_image) |
|
|
|
|
|
prediction = np.argmax(prediction, axis = 1) |
|
|
|
return "The input digit is: {}".format(int(prediction)) |
|
|
|
|
|
|
|
demo = gr.Interface(fn = model, inputs = 'image', outputs = 'text') |
|
demo.launch() |
|
|