Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,6 +24,9 @@ with gr.Blocks() as demo:
|
|
| 24 |
def modelTraining(img):
|
| 25 |
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
|
| 26 |
'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# clothing dataset
|
| 29 |
mnist = tf.keras.datasets.mnist
|
|
@@ -66,14 +69,7 @@ with gr.Blocks() as demo:
|
|
| 66 |
# create the final model for production
|
| 67 |
probability_model = tf.keras.Sequential([model, tf.keras.layers.Softmax()])
|
| 68 |
|
| 69 |
-
#
|
| 70 |
-
# the image can be passed as a PIL or numpy
|
| 71 |
-
|
| 72 |
-
# Normalize the pixel values?
|
| 73 |
-
print(f"Input image shape: {img.shape} Dimensions: {img.ndim} Array Element: {img[0]} ***********************************************************************")
|
| 74 |
-
# assuming image_array is your input image array of shape (552, 3)
|
| 75 |
-
resized_array = np.resize(img, (28, 28)) # resize the array to (28, 28)
|
| 76 |
-
input_array = np.expand_dims(resized_array, axis=0) # add an extra dimension to represent the batch size
|
| 77 |
|
| 78 |
# Make a prediction using the model
|
| 79 |
prediction = probability_model.predict(input_array)
|
|
@@ -85,7 +81,7 @@ with gr.Blocks() as demo:
|
|
| 85 |
# Creates the Gradio interface objects
|
| 86 |
with gr.Row():
|
| 87 |
with gr.Column(scale=2):
|
| 88 |
-
image_data = gr.Image(label="Upload Image", type="numpy")
|
| 89 |
with gr.Column(scale=1):
|
| 90 |
model_prediction = gr.Text(label="Model Prediction", interactive=False)
|
| 91 |
image_data.change(modelTraining, image_data, model_prediction)
|
|
|
|
| 24 |
def modelTraining(img):
|
| 25 |
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
|
| 26 |
'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
|
| 27 |
+
|
| 28 |
+
# Normalize the pixel values
|
| 29 |
+
img = np.array(img) / 255.0
|
| 30 |
|
| 31 |
# clothing dataset
|
| 32 |
mnist = tf.keras.datasets.mnist
|
|
|
|
| 69 |
# create the final model for production
|
| 70 |
probability_model = tf.keras.Sequential([model, tf.keras.layers.Softmax()])
|
| 71 |
|
| 72 |
+
input_array = np.expand_dims(img, axis=0) # add an extra dimension to represent the batch size
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
# Make a prediction using the model
|
| 75 |
prediction = probability_model.predict(input_array)
|
|
|
|
| 81 |
# Creates the Gradio interface objects
|
| 82 |
with gr.Row():
|
| 83 |
with gr.Column(scale=2):
|
| 84 |
+
image_data = gr.Image(label="Upload Image", type="numpy", image_mode="L", shape=[28,28], invert_colors=True)
|
| 85 |
with gr.Column(scale=1):
|
| 86 |
model_prediction = gr.Text(label="Model Prediction", interactive=False)
|
| 87 |
image_data.change(modelTraining, image_data, model_prediction)
|