Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
# --- Cargar el modelo completo ---
|
7 |
+
model = tf.keras.models.load_model("autoencoder_complete_model_Fourier.keras")
|
8 |
+
|
9 |
+
# --- Transformaciones necesarias ---
|
10 |
+
def preprocess_image(img):
|
11 |
+
""" Prepara la imagen para el modelo (escala 0-1 y redimensiona a 256x256). """
|
12 |
+
img = img.resize((256, 256)) # Asegurar tamaño correcto
|
13 |
+
img_array = np.array(img) / 255.0 # Normalizar entre 0 y 1
|
14 |
+
img_array = np.expand_dims(img_array, axis=0) # Añadir batch dimension
|
15 |
+
return img_array
|
16 |
+
|
17 |
+
def denoise_image(img):
|
18 |
+
""" Pasa la imagen ruidosa por el autoencoder y devuelve la imagen reconstruida. """
|
19 |
+
img_array = preprocess_image(img)
|
20 |
+
|
21 |
+
# Pasar la imagen por el autoencoder
|
22 |
+
denoised_img = model.predict(img_array)
|
23 |
+
|
24 |
+
# Postprocesamiento
|
25 |
+
denoised_img = np.squeeze(denoised_img) # Remover batch dimension
|
26 |
+
denoised_img = (denoised_img * 255).astype(np.uint8) # Convertir a formato uint8
|
27 |
+
return denoised_img
|
28 |
+
|
29 |
+
# --- Interfaz Gradio ---
|
30 |
+
gr.Interface(fn=denoise_image,
|
31 |
+
inputs=gr.Image(type="pil"), # Imagen de entrada
|
32 |
+
outputs=gr.Image(type="numpy"), # Imagen de salida
|
33 |
+
examples=["noisy1.jpg", "noisy2.jpg"] # Ejemplos opcionales
|
34 |
+
).launch()
|