Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import numpy as np
|
3 |
+
import tensorflow as tf
|
4 |
+
import gradio as gr
|
5 |
+
from huggingface_hub import from_pretrained_keras
|
6 |
+
|
7 |
+
model = from_pretrained_keras("keras-io/conv_autoencoder")
|
8 |
+
|
9 |
+
examples = [
|
10 |
+
['./example_0.jpeg'],
|
11 |
+
['./example_1.jpeg'],
|
12 |
+
['./example_2.jpeg'],
|
13 |
+
['./example_3.jpeg'],
|
14 |
+
['./example_4.jpeg']
|
15 |
+
]
|
16 |
+
|
17 |
+
def infer(original_image):
|
18 |
+
image = tf.keras.utils.img_to_array(original_image)
|
19 |
+
image = image.astype("float32") / 255.0
|
20 |
+
image = np.reshape(image, (1, 28, 28, 1))
|
21 |
+
output = model.predict(image)
|
22 |
+
output = np.reshape(output, (28, 28, 1))
|
23 |
+
output_image = tf.keras.preprocessing.image.array_to_img(output)
|
24 |
+
return output_image
|
25 |
+
|
26 |
+
iface = gr.Interface(
|
27 |
+
fn = infer,
|
28 |
+
title = "Image Denoising using Convolutional AutoEncoders",
|
29 |
+
description = "Keras Implementation of a deep convolutional autoencoder for image denoising",
|
30 |
+
inputs = gr.inputs.Image(image_mode='L', shape=(28, 28)),
|
31 |
+
outputs = gr.outputs.Image(type = 'pil'),
|
32 |
+
examples = examples,
|
33 |
+
article = "Author: <a href=\"https://huggingface.co/Blazer007\">Vivek Rai</a>. Based on the keras example from <a href=\"https://keras.io/examples/vision/autoencoder/\">Santiago L. Valdarrama</a>",
|
34 |
+
).launch(enable_queue=True, debug = True)
|