|
import gradio as gr |
|
import tensorflow as tf |
|
import numpy as np |
|
from PIL import Image |
|
|
|
|
|
model = tf.keras.models.load_model("autoencoder_complete_model_Fourier.keras") |
|
|
|
|
|
def preprocess_image(img): |
|
""" Prepara la imagen para el modelo (escala 0-1 y redimensiona a 256x256). """ |
|
img = img.resize((256, 256)) |
|
img_array = np.array(img) / 255.0 |
|
img_array = np.expand_dims(img_array, axis=0) |
|
return img_array |
|
|
|
def denoise_image(img): |
|
""" Pasa la imagen ruidosa por el autoencoder y devuelve la imagen reconstruida. """ |
|
img_array = preprocess_image(img) |
|
|
|
|
|
denoised_img = model.predict(img_array) |
|
|
|
|
|
denoised_img = np.squeeze(denoised_img) |
|
denoised_img = (denoised_img * 255).astype(np.uint8) |
|
return denoised_img |
|
|
|
|
|
gr.Interface(fn=denoise_image, |
|
inputs=gr.Image(type="pil"), |
|
outputs=gr.Image(type="numpy"), |
|
examples=["noisy1.jpg", "noisy2.jpg"] |
|
).launch() |
|
|