Spaces:
Sleeping
Sleeping
Commit
·
79892f6
1
Parent(s):
1d908cf
Update app3.py
Browse files
app3.py
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from keras.models import load_model
|
| 2 |
+
import numpy as np # linear algebra
|
| 3 |
+
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
from numpy import load
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
# from keras.datasets import mnist
|
| 9 |
+
import keras.utils.np_utils as ku
|
| 10 |
+
import keras.models as models
|
| 11 |
+
import keras.layers as layers
|
| 12 |
+
from keras import regularizers
|
| 13 |
+
import numpy.random as nr
|
| 14 |
+
|
| 15 |
+
# save numpy array as npy file
|
| 16 |
+
from numpy import asarray
|
| 17 |
+
from numpy import save
|
| 18 |
+
# save to npy file
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
import keras
|
| 22 |
+
from keras.layers import Dropout
|
| 23 |
+
|
| 24 |
+
from keras.preprocessing.image import ImageDataGenerator
|
| 25 |
+
from tensorflow.keras.optimizers import RMSprop,Adam
|
| 26 |
+
from tensorflow.keras.layers import BatchNormalization
|
| 27 |
+
from sklearn.metrics import confusion_matrix
|
| 28 |
+
|
| 29 |
+
import warnings
|
| 30 |
+
warnings.simplefilter(action='ignore')
|
| 31 |
+
from PIL import Image, ImageFilter
|
| 32 |
+
|
| 33 |
+
# %matplotlib inline
|
| 34 |
+
|
| 35 |
+
from tensorflow.keras.preprocessing.image import ImageDataGenerator
|
| 36 |
+
|
| 37 |
+
nn = load_model('my_model-2.h5')
|
| 38 |
+
def predict_image(img):
|
| 39 |
+
print("Digit Recognizer")
|
| 40 |
+
img_3d=img.reshape(-1,28,28)
|
| 41 |
+
im_resize=img_3d/255.0
|
| 42 |
+
prediction=nn.predict(im_resize).tolist()[0]
|
| 43 |
+
return {str(i):prediction[i] for i in range(10)}
|
| 44 |
+
|
| 45 |
+
'''
|
| 46 |
+
with gr.Blocks() as demo:
|
| 47 |
+
gr.Title("Digit Recognizer")
|
| 48 |
+
ac_inputs=gr.Sketchpad()
|
| 49 |
+
ac_outputs=gr.outputs.Label(num_top_classes=3)
|
| 50 |
+
greet_btn = gr.Button("Greet")
|
| 51 |
+
gr.interface(fn=predict_image, inputs="sketchpad",outputs=gr.outputs.Label(num_top_classes=3))
|
| 52 |
+
'''
|
| 53 |
+
label=gr.outputs.Label(num_top_classes=3)
|
| 54 |
+
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")
|
| 55 |
+
|
| 56 |
+
iface.launch(debug='True')
|