Update app.py
Browse files
app.py
CHANGED
@@ -1,54 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from gradio import Interface
|
3 |
-
import tensorflow as tf
|
4 |
-
from tensorflow import keras
|
5 |
-
from tensorflow.keras import datasets, layers, models
|
6 |
-
import numpy as np
|
7 |
-
|
8 |
-
(X_train, y_train) , (X_test, y_test) = keras.datasets.mnist.load_data()
|
9 |
-
|
10 |
-
X_train = np.concatenate((X_train, X_test))
|
11 |
-
y_train = np.concatenate((y_train, y_test))
|
12 |
-
|
13 |
-
X_train = X_train / 255
|
14 |
-
X_test = X_test / 255
|
15 |
-
|
16 |
-
data_augmentation = keras.Sequential([
|
17 |
-
tf.keras.layers.experimental.preprocessing.RandomRotation(0.2, input_shape=(28, 28, 1)),
|
18 |
-
])
|
19 |
-
|
20 |
-
model = models.Sequential([
|
21 |
-
data_augmentation,
|
22 |
-
|
23 |
-
#cnn
|
24 |
-
layers.Conv2D(filters=32, kernel_size=(3,3), padding='same', activation='relu'),
|
25 |
-
layers.MaxPooling2D((2,2)),
|
26 |
-
layers.Conv2D(filters=32, kernel_size=(3,3), padding='same', activation='relu'),
|
27 |
-
layers.MaxPooling2D((2,2)),
|
28 |
-
|
29 |
-
#dense
|
30 |
-
|
31 |
-
layers.Flatten(),
|
32 |
-
layers.Dense(32, activation='relu'),
|
33 |
-
layers.Dense(10, activation='softmax'),
|
34 |
-
|
35 |
-
])
|
36 |
-
|
37 |
-
model.compile(optimizer='adam',
|
38 |
-
loss='sparse_categorical_crossentropy',
|
39 |
-
metrics=['accuracy'])
|
40 |
-
|
41 |
-
model.fit(X_train, y_train, epochs=1)
|
42 |
-
|
43 |
-
def predict_image(img):
|
44 |
-
img_3d = img.reshape(-1, 28,28)
|
45 |
-
img_scaled = img_3d/255
|
46 |
-
prediction = model.predict(img_scaled)
|
47 |
-
pred = np.argmax(prediction)
|
48 |
-
|
49 |
-
return pred.item()
|
50 |
-
|
51 |
-
|
52 |
-
iface = gr.Interface(predict_image, inputs='sketchpad', outputs='label', title='Digit Recognition Model By Debamrita Paul', description='Draw a single digit(0 to 9)')
|
53 |
-
|
54 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|