diff --git a/gradio/inputs.py b/gradio/inputs.py index 89bcdc50f7..119d3e4362 100644 --- a/gradio/inputs.py +++ b/gradio/inputs.py @@ -134,6 +134,7 @@ class Sketchpad(AbstractInput): if self.sample_inputs is not None: for input in self.sample_inputs: encoded_images.append(preprocessing_utils.encode_array_to_base64(input)) + print(encoded_images) return encoded_images diff --git a/gradio/preprocessing_utils.py b/gradio/preprocessing_utils.py index 60f4cb0815..9708b3e603 100644 --- a/gradio/preprocessing_utils.py +++ b/gradio/preprocessing_utils.py @@ -24,7 +24,8 @@ def encode_array_to_base64(image_array): bytes_data = output_bytes.getvalue() base64_str = str(base64.b64encode(bytes_data), 'utf-8') - return base64_str + + return "data:image/png;base64," + base64_str def resize_and_crop(img, size, crop_type='top'): diff --git a/gradio/test.py b/gradio/test.py new file mode 100644 index 0000000000..c9b785d9fc --- /dev/null +++ b/gradio/test.py @@ -0,0 +1,31 @@ +import tensorflow as tf +import gradio + + +#CREATE INTERFACE USING 'GOOD' MNIST MODEL +(x_train, y_train),(x_test, y_test) = tf.keras.datasets.mnist.load_data() +model = tf.keras.models.load_model('MNIST_9344.h5') +input = gradio.inputs.Sketchpad(sample_inputs=x_train[:10]) +iface = gradio.Interface(inputs=input, outputs="label", model=model, model_type='keras') +iface.launch(inline=False, share=False, inbrowser=True); + + +#CREATE INTERFACE BY TRAINING MSNIST MODEL + +# (x_train, y_train),(x_test, y_test) = tf.keras.datasets.mnist.load_data() +# x_train, x_test = x_train / 255.0, x_test / 255.0 +# +# model = tf.keras.models.Sequential([ +# tf.keras.layers.Flatten(), +# tf.keras.layers.Dense(512, activation=tf.nn.relu), +# tf.keras.layers.Dropout(0.2), +# tf.keras.layers.Dense(10, activation=tf.nn.softmax) +# ]) +# +# model.compile(optimizer='adam', +# loss='sparse_categorical_crossentropy', +# metrics=['accuracy']) +# model.fit(x_train, y_train, epochs=1) +# inp = gradio.inputs.Sketchpad(sample_inputs=x_train[:10]) +# iface = gradio.Interface(inputs=inp, outputs="label", model=model, model_type='keras') +# iface.launch(inline=False, share=False, inbrowser=True); \ No newline at end of file