VCoder1410 commited on
Commit
fe37081
·
1 Parent(s): 2259c47

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from matplotlib import pyplot as plt
4
+ import numpy as np
5
+
6
+ objects = tf.keras.datasets.mnist
7
+ (training_images, training_labels), (test_images, test_labels) = objects.load_data()
8
+
9
+ for i in range(9):
10
+ # define subplot
11
+ plt.subplot(330 + 1 + i)
12
+ # plot raw pixel data
13
+ plt.imshow(training_images[i])
14
+
15
+ training_images = training_images / 255.0
16
+ test_images = test_images / 255.0
17
+
18
+
19
+ from tensorflow.keras.layers import Flatten, Dense
20
+ model = tf.keras.models.Sequential([Flatten(input_shape=(28,28)),
21
+ Dense(256, activation='relu'),
22
+ Dense(256, activation='relu'),
23
+ Dense(128, activation='relu'),
24
+ Dense(10, activation=tf.nn.softmax)])
25
+
26
+ model.compile(optimizer = 'adam',
27
+ loss = 'sparse_categorical_crossentropy',
28
+ metrics=['accuracy'])
29
+ model.fit(training_images, training_labels, epochs=10)
30
+
31
+ test=test_images[0].reshape(-1,28,28)
32
+ pred=model.predict(test)
33
+ print(pred)
34
+
35
+ def predict_image(img):
36
+ img_3d=img.reshape(-1,28,28)
37
+ im_resize=img_3d/255.0
38
+ prediction=model.predict(im_resize)
39
+ pred=np.argmax(prediction)
40
+ return pred
41
+
42
+ iface = gr.Interface(predict_image, inputs="sketchpad", outputs="label")
43
+ iface.launch(debug='True')