Delete app.py
Browse files
app.py
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
|
3 |
-
import tensorflow as tf
|
4 |
-
import keras
|
5 |
-
from matplotlib import pyplot as plt
|
6 |
-
import numpy as np
|
7 |
-
|
8 |
-
objects = tf.keras.datasets.mnist
|
9 |
-
(training_images, training_labels), (test_images, test_labels) = objects.load_data()
|
10 |
-
|
11 |
-
training_images = training_images / 255.0
|
12 |
-
test_images = test_images / 255.0
|
13 |
-
|
14 |
-
from keras.layers import Flatten, Dense
|
15 |
-
model = tf.keras.models.Sequential([Flatten(input_shape=(28,28)),
|
16 |
-
Dense(256, activation='relu'),
|
17 |
-
Dense(256, activation='relu'),
|
18 |
-
Dense(128, activation='relu'),
|
19 |
-
Dense(10, activation=tf.nn.softmax)])
|
20 |
-
|
21 |
-
model.compile(optimizer = 'adam',
|
22 |
-
loss = 'sparse_categorical_crossentropy',
|
23 |
-
metrics=['accuracy'])
|
24 |
-
|
25 |
-
model.fit(training_images, training_labels, epochs=10)
|
26 |
-
|
27 |
-
test=test_images[0].reshape(-1,28,28)
|
28 |
-
pred=model.predict(test)
|
29 |
-
print(pred)
|
30 |
-
|
31 |
-
def predict_image(img):
|
32 |
-
img_3d=img.reshape(-1,28,28)
|
33 |
-
im_resize=img_3d/255.0
|
34 |
-
prediction=model.predict(im_resize)
|
35 |
-
pred=np.argmax(prediction)
|
36 |
-
return pred
|
37 |
-
|
38 |
-
iface = gr.Interface(
|
39 |
-
fn= predict_image,
|
40 |
-
inputs= gr.Image(height=28, width=28, image_mode='L', sources='upload'),
|
41 |
-
outputs='label'
|
42 |
-
|
43 |
-
)
|
44 |
-
|
45 |
-
iface.launch(debug='True')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|