File size: 747 Bytes
27ee273
 
 
 
 
 
 
 
 
 
da7bfb4
27ee273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Importing Necessary Libraries

import tensorflow as tf
import cv2
import numpy as np
import gradio as gr

# Importing the Model

def model(up_img):
  cnn = tf.keras.models.load_model("Handwritten_Digit_Recognition_Model.h5")

  #import image
  gray_image = cv2.cvtColor(up_img, cv2.COLOR_BGR2GRAY)

  #preprocess
  gray_image = np.expand_dims(gray_image, axis = -1)
  gray_image = gray_image.reshape((-1, 28, 28, 1))

  #predict
  prediction = cnn.predict(gray_image)

  #converting the float values to int values for y_test
  prediction = np.argmax(prediction, axis = 1)

  return "The input digit is: {}".format(int(prediction))

# Running the Model on Gradio

demo = gr.Interface(fn = model, inputs = 'image', outputs = 'text')
demo.launch()