File size: 1,290 Bytes
b0713c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

import numpy as np
import tensorflow as tf
import gradio as gr
from huggingface_hub import from_pretrained_keras

model = from_pretrained_keras("keras-io/conv_autoencoder")

examples = [
            ['./example_0.jpeg'], 
            ['./example_1.jpeg'], 
            ['./example_2.jpeg'], 
            ['./example_3.jpeg'], 
            ['./example_4.jpeg']
]

def infer(original_image):
    image = tf.keras.utils.img_to_array(original_image)
    image = image.astype("float32") / 255.0
    image = np.reshape(image, (1, 28, 28, 1))
    output = model.predict(image)
    output = np.reshape(output, (28, 28, 1))
    output_image = tf.keras.preprocessing.image.array_to_img(output)
    return output_image

iface = gr.Interface(
    fn = infer,
    title = "Image Denoising using Convolutional AutoEncoders",
    description = "Keras Implementation of a deep convolutional autoencoder for image denoising",
    inputs = gr.inputs.Image(image_mode='L', shape=(28, 28)),
    outputs = gr.outputs.Image(type = 'pil'),
    examples = examples,
    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>",
    ).launch(enable_queue=True, debug = True)