Spaces:
Runtime error
Runtime error
update ui
Browse files
app.py
CHANGED
@@ -2,20 +2,22 @@ import gradio as gr
|
|
2 |
import tensorflow as tf
|
3 |
import numpy as np
|
4 |
|
5 |
-
model = tf.saved_model.load("/home/user/app/model")
|
|
|
6 |
labels = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
|
7 |
|
8 |
def mnist_classifier(img):
|
9 |
img_tensor = tf.convert_to_tensor(img['composite'], dtype=tf.float32)
|
10 |
-
img_tensor = tf.
|
11 |
-
|
12 |
-
|
|
|
13 |
img_tensor /= 255.0
|
14 |
-
img_tensor = tf.
|
15 |
|
16 |
prediction = model.signatures['serving_default'](img_tensor)
|
17 |
-
|
18 |
-
return str(
|
19 |
|
20 |
demo = gr.Interface(fn=mnist_classifier, inputs="sketchpad", outputs="text", title="MNIST Checker", description="Draw a number 0-9 to see if the model can classify it.")
|
21 |
demo.launch()
|
|
|
2 |
import tensorflow as tf
|
3 |
import numpy as np
|
4 |
|
5 |
+
# model = tf.saved_model.load("/home/user/app/model")
|
6 |
+
model = tf.saved_model.load("C:\\Users\\caleb\\OneDrive\\Documents\\Coding Projects\\INFX_639\\mnist_checker\\model")
|
7 |
labels = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
|
8 |
|
9 |
def mnist_classifier(img):
|
10 |
img_tensor = tf.convert_to_tensor(img['composite'], dtype=tf.float32)
|
11 |
+
img_tensor = tf.expand_dims(img_tensor[:, :, -1], axis=-1) # Select the last channel
|
12 |
+
img_tensor = tf.image.resize(img_tensor, [28, 28])
|
13 |
+
|
14 |
+
# Normalize and flatten
|
15 |
img_tensor /= 255.0
|
16 |
+
img_tensor = tf.reshape(img_tensor, (1, 784))
|
17 |
|
18 |
prediction = model.signatures['serving_default'](img_tensor)
|
19 |
+
prediction = tf.argmax(prediction['output'], axis=1).numpy()
|
20 |
+
return str(prediction[0])
|
21 |
|
22 |
demo = gr.Interface(fn=mnist_classifier, inputs="sketchpad", outputs="text", title="MNIST Checker", description="Draw a number 0-9 to see if the model can classify it.")
|
23 |
demo.launch()
|