File size: 1,326 Bytes
6f5fe00
 
 
 
 
 
 
792d179
 
 
6f5fe00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3567bbb
6f5fe00
 
 
 
 
 
 
 
792d179
6f5fe00
 
 
7e60fc1
abf1433
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
35
36
37
38
39
40
41
42
43
import gradio as gr
import numpy as np
import tensorflow as tf
from PIL import Image
from tensorflow import keras 
from tensorflow.keras.applications.resnet50 import preprocess_input

autoencoder = keras.models.load_model("./models/denoising_autoencoder_weights.h5")
encoder = keras.models.load_model("./models/encoder.h5")
decoder = keras.models.load_model("./models/decoder.h5")


# Define the Gradio interface
def denoise_image(input_image):
    # Open the image
    input_array = np.array(input_image)
    input_array = preprocess_input(input_array)
    input_array = np.expand_dims(input_array, axis=0)
    hash = encoder.predict(input_array)
    output = decoder.predict(hash)
    hash_image = Image.fromarray((hash[0].reshape(32,32) * 255).astype(np.uint8))
    output_image = Image.fromarray((output[0] * 255).astype(np.uint8))
    return [input_image, hash_image, output_image]

iface = gr.Interface(
    fn=denoise_image,
    inputs= [
         gr.Image (label = "Original Image", shape=(32,32))
    ],
    outputs=[
         gr.Image (label = "Decoded Output"),
         gr.Image (label= "Hash Output"),
         ],
    title="Denoising Autoencoder",
    description="Upload an image and see its denoised version using a denoising autoencoder.",
    examples=[
        ["./example.jpg"]
      ],
)


iface.launch()