Spaces:
Sleeping
Sleeping
| from keras.models import load_model | |
| import numpy as np # linear algebra | |
| import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) | |
| import matplotlib.pyplot as plt | |
| from numpy import load | |
| import gradio as gr | |
| # from keras.datasets import mnist | |
| import keras.utils.np_utils as ku | |
| import keras.models as models | |
| import keras.layers as layers | |
| from keras import regularizers | |
| import numpy.random as nr | |
| # save numpy array as npy file | |
| from numpy import asarray | |
| from numpy import save | |
| # save to npy file | |
| import keras | |
| from keras.layers import Dropout | |
| from keras.preprocessing.image import ImageDataGenerator | |
| from tensorflow.keras.optimizers import RMSprop,Adam | |
| from tensorflow.keras.layers import BatchNormalization | |
| from sklearn.metrics import confusion_matrix | |
| import warnings | |
| warnings.simplefilter(action='ignore') | |
| from PIL import Image, ImageFilter | |
| # %matplotlib inline | |
| from tensorflow.keras.preprocessing.image import ImageDataGenerator | |
| nn = load_model('my_model-2.h5') | |
| def predict_image(img): | |
| print("Digit Recognizer") | |
| img_3d=img.reshape(-1,28,28) | |
| im_resize=img_3d/255.0 | |
| prediction=nn.predict(im_resize).tolist()[0] | |
| return {str(i):prediction[i] for i in range(10)} | |
| ''' | |
| with gr.Blocks() as demo: | |
| gr.Title("Digit Recognizer") | |
| ac_inputs=gr.Sketchpad() | |
| ac_outputs=gr.outputs.Label(num_top_classes=3) | |
| greet_btn = gr.Button("Greet") | |
| gr.interface(fn=predict_image, inputs="sketchpad",outputs=gr.outputs.Label(num_top_classes=3)) | |
| ''' | |
| label=gr.outputs.Label(num_top_classes=3) | |
| iface=gr.Interface(predict_image, inputs="sketchpad",outputs=label,title=f"Digit Recognizer",allow_flagging='manual',description="Note:Draw Digits from 0-9 and Try to Draw the Digit in the center for better accuracy") | |
| iface.launch(debug='True') | |