Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from huggingface_hub import hf_hub_download
|
| 6 |
+
|
| 7 |
+
# Cargar el modelo DAE desde Hugging Face
|
| 8 |
+
modelo_path = hf_hub_download(repo_id="XTEP63/DAE", filename="denoiser.keras")
|
| 9 |
+
dae_model = tf.keras.models.load_model(modelo_path)
|
| 10 |
+
|
| 11 |
+
# Funci贸n para procesar la imagen con el DAE
|
| 12 |
+
def denoise_image(image):
|
| 13 |
+
image = image.resize((128, 128)) # Ajusta seg煤n el tama帽o de las imagenes
|
| 14 |
+
image = np.array(image) / 255.0 # Normalizar
|
| 15 |
+
image = np.expand_dims(image, axis=0)
|
| 16 |
+
output = dae_model.predict(image)
|
| 17 |
+
output = np.squeeze(output, axis=0)
|
| 18 |
+
output = (output * 255).astype(np.uint8) # Volver a escala 0-255
|
| 19 |
+
return Image.fromarray(output)
|
| 20 |
+
|
| 21 |
+
# Interfaz
|
| 22 |
+
iface_dae = gr.Interface(
|
| 23 |
+
fn=denoise_image,
|
| 24 |
+
inputs=gr.Image(type="pil"),
|
| 25 |
+
outputs=gr.Image(type="pil"),
|
| 26 |
+
title="Denoising Autoencoder",
|
| 27 |
+
description="Sube una imagen con ruido y el modelo la limpiar谩."
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
iface_dae.launch()
|