Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
-
# Definición de colores disponibles
|
| 6 |
COLORES = {
|
| 7 |
"🟢 Verde": [0, 255, 0],
|
| 8 |
"⚪ Blanco": [255, 255, 255],
|
|
@@ -12,304 +12,156 @@ COLORES = {
|
|
| 12 |
"⚫ Gris": [180, 180, 180]
|
| 13 |
}
|
| 14 |
|
| 15 |
-
def
|
| 16 |
"""
|
| 17 |
-
Efecto scanner
|
| 18 |
"""
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
# Convertir imagen
|
| 23 |
-
img = np.array(imagen.convert('RGB'))
|
| 24 |
-
h, w = img.shape[:2]
|
| 25 |
-
|
| 26 |
-
# 1. Crear fondo NEGRO completo
|
| 27 |
-
resultado = np.zeros((h, w, 3), dtype=np.uint8)
|
| 28 |
-
|
| 29 |
-
# 2. MEJORAR NITIDEZ: aplicar filtro de enfoque
|
| 30 |
-
# Primero, trabajar con la imagen en flotante para mayor precisión
|
| 31 |
-
img_float = img.astype(np.float32)
|
| 32 |
-
|
| 33 |
-
# Crear versión con mayor contraste para detalles
|
| 34 |
-
gray = np.mean(img_float, axis=2)
|
| 35 |
-
|
| 36 |
-
# Aumentar contraste local para mejorar detalles
|
| 37 |
-
if nitidez > 0:
|
| 38 |
-
# Filtro de enfoque (unsharp mask)
|
| 39 |
-
blurred = np.zeros_like(gray)
|
| 40 |
-
# Desenfoque gaussiano simple
|
| 41 |
-
kernel_size = 5
|
| 42 |
-
for i in range(kernel_size // 2, h - kernel_size // 2):
|
| 43 |
-
for j in range(kernel_size // 2, w - kernel_size // 2):
|
| 44 |
-
blurred[i, j] = np.mean(gray[i-2:i+3, j-2:j+3])
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
# Normalizar y convertir a uint8
|
| 51 |
-
gray = np.clip(gray, 0, 255).astype(np.uint8)
|
| 52 |
-
|
| 53 |
-
# 3. Detectar bordes MEJORADO
|
| 54 |
-
edges = np.zeros_like(gray, dtype=np.uint8)
|
| 55 |
-
|
| 56 |
-
# Usar operador Sobel mejorado para bordes
|
| 57 |
-
for i in range(1, h-1):
|
| 58 |
-
for j in range(1, w-1):
|
| 59 |
-
# Gradiente horizontal
|
| 60 |
-
gx = (2*gray[i, j+1] + gray[i-1, j+1] + gray[i+1, j+1] -
|
| 61 |
-
2*gray[i, j-1] - gray[i-1, j-1] - gray[i+1, j-1])
|
| 62 |
-
|
| 63 |
-
# Gradiente vertical
|
| 64 |
-
gy = (2*gray[i+1, j] + gray[i+1, j+1] + gray[i+1, j-1] -
|
| 65 |
-
2*gray[i-1, j] - gray[i-1, j+1] - gray[i-1, j-1])
|
| 66 |
-
|
| 67 |
-
# Magnitud del gradiente
|
| 68 |
-
edges[i, j] = np.clip(np.sqrt(gx*gx + gy*gy) * 0.5, 0, 255).astype(np.uint8)
|
| 69 |
-
|
| 70 |
-
# Aplicar umbral adaptativo para bordes
|
| 71 |
-
mean_edge = np.mean(edges)
|
| 72 |
-
edges = np.where(edges > mean_edge * 1.5, edges, 0)
|
| 73 |
-
|
| 74 |
-
# 4. Añadir LÍNEAS HORIZONTALES con color seleccionado
|
| 75 |
-
for y in range(0, h, espacio_lineas):
|
| 76 |
-
for t in range(grosor_linea):
|
| 77 |
-
if y + t < h:
|
| 78 |
-
# Línea con color seleccionado
|
| 79 |
-
for c in range(3):
|
| 80 |
-
resultado[y + t, :, c] = color_rgb[c]
|
| 81 |
-
|
| 82 |
-
# Gradiente sutil en los bordes de la línea
|
| 83 |
-
if t == 0:
|
| 84 |
-
for c in range(3):
|
| 85 |
-
resultado[y + t, :, c] = int(color_rgb[c] * 0.8)
|
| 86 |
-
elif t == grosor_linea - 1:
|
| 87 |
-
for c in range(3):
|
| 88 |
-
resultado[y + t, :, c] = int(color_rgb[c] * 0.9)
|
| 89 |
-
|
| 90 |
-
# 5. MEJORAR detalles de la imagen original
|
| 91 |
-
# Usar la imagen en escala de grises mejorada
|
| 92 |
-
gray_enhanced = (gray * 0.4).astype(np.uint8) # Reducir brillo pero mantener detalles
|
| 93 |
-
|
| 94 |
-
# Crear máscara para áreas con detalles importantes
|
| 95 |
-
detail_mask = gray_enhanced > 20
|
| 96 |
-
|
| 97 |
-
# Añadir detalles en todos los canales, pero predominando el color seleccionado
|
| 98 |
-
for c in range(3):
|
| 99 |
-
if color_rgb[c] > 0: # Si este canal está activo en el color principal
|
| 100 |
-
weight = color_rgb[c] / 255.0
|
| 101 |
-
resultado[detail_mask, c] = np.clip(
|
| 102 |
-
resultado[detail_mask, c] + gray_enhanced[detail_mask] * weight,
|
| 103 |
-
0, 255
|
| 104 |
-
)
|
| 105 |
-
|
| 106 |
-
# 6. Añadir bordes detectados con mayor intensidad
|
| 107 |
-
edge_mask = edges > 40
|
| 108 |
-
for c in range(3):
|
| 109 |
-
edge_intensity = edges[edge_mask] * (color_rgb[c] / 255.0)
|
| 110 |
-
resultado[edge_mask, c] = np.clip(
|
| 111 |
-
resultado[edge_mask, c] + edge_intensity * 1.5,
|
| 112 |
-
0, 255
|
| 113 |
-
)
|
| 114 |
-
|
| 115 |
-
# 7. Añadir efecto de profundidad con desenfoque variable
|
| 116 |
-
# Solo en áreas sin líneas principales
|
| 117 |
-
line_mask = np.zeros((h, w), dtype=bool)
|
| 118 |
-
for y in range(0, h, espacio_lineas):
|
| 119 |
-
for t in range(grosor_linea):
|
| 120 |
-
if y + t < h:
|
| 121 |
-
line_mask[y + t, :] = True
|
| 122 |
-
|
| 123 |
-
# Áreas entre líneas: mantener más nítido cerca de bordes
|
| 124 |
-
non_line_mask = ~line_mask
|
| 125 |
-
for c in range(3):
|
| 126 |
-
channel = resultado[:, :, c]
|
| 127 |
|
| 128 |
-
#
|
| 129 |
-
|
| 130 |
-
if np.any(low_detail):
|
| 131 |
-
# Aplicar suavizado muy ligero
|
| 132 |
-
from scipy.ndimage import gaussian_filter
|
| 133 |
-
channel_smooth = gaussian_filter(channel.astype(float), sigma=0.5)
|
| 134 |
-
channel[low_detail] = channel_smooth[low_detail].astype(np.uint8)
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
for t in range(grosor_linea):
|
| 143 |
if y + t < h:
|
|
|
|
| 144 |
for c in range(3):
|
| 145 |
-
resultado[y + t, :, c] =
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
-
# Interfaz
|
| 180 |
-
with gr.Blocks(theme=gr.themes.Soft()
|
| 181 |
gr.Markdown("""
|
| 182 |
-
# 🎨
|
| 183 |
-
|
| 184 |
-
**Efecto scanner con múltiples colores y nitidez ajustable**
|
| 185 |
|
| 186 |
-
|
| 187 |
""")
|
| 188 |
|
| 189 |
with gr.Row():
|
| 190 |
with gr.Column(scale=1):
|
| 191 |
input_img = gr.Image(
|
| 192 |
type="pil",
|
| 193 |
-
label="📤
|
| 194 |
-
height=250
|
| 195 |
)
|
| 196 |
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
label="🎨 Color de líneas"
|
| 202 |
-
)
|
| 203 |
-
|
| 204 |
-
espacio_slider = gr.Slider(
|
| 205 |
-
minimum=5,
|
| 206 |
-
maximum=50,
|
| 207 |
-
value=20,
|
| 208 |
-
step=1,
|
| 209 |
-
label="📏 Espacio entre líneas"
|
| 210 |
-
)
|
| 211 |
-
|
| 212 |
-
grosor_slider = gr.Slider(
|
| 213 |
-
minimum=1,
|
| 214 |
-
maximum=10,
|
| 215 |
-
value=3,
|
| 216 |
-
step=1,
|
| 217 |
-
label="🖋️ Grosor de líneas"
|
| 218 |
-
)
|
| 219 |
-
|
| 220 |
-
nitidez_slider = gr.Slider(
|
| 221 |
-
minimum=0.0,
|
| 222 |
-
maximum=1.0,
|
| 223 |
-
value=0.5,
|
| 224 |
-
step=0.1,
|
| 225 |
-
label="🔍 Nivel de nitidez"
|
| 226 |
-
)
|
| 227 |
-
|
| 228 |
-
procesar_btn = gr.Button(
|
| 229 |
-
"🚀 Generar Holograma",
|
| 230 |
-
variant="primary",
|
| 231 |
-
size="lg"
|
| 232 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
|
| 234 |
with gr.Column(scale=1):
|
| 235 |
output_img = gr.Image(
|
| 236 |
type="pil",
|
| 237 |
-
label="✨
|
| 238 |
-
height=250
|
| 239 |
)
|
| 240 |
-
|
| 241 |
-
with gr.Row():
|
| 242 |
-
descargar_btn = gr.Button("💾 Descargar")
|
| 243 |
-
reset_btn = gr.Button("🔄 Restablecer")
|
| 244 |
-
|
| 245 |
-
# Información sobre colores
|
| 246 |
-
with gr.Accordion("🎨 Muestra de Colores", open=False):
|
| 247 |
-
gr.Markdown("""
|
| 248 |
-
| Color | Código RGB | Efecto |
|
| 249 |
-
|-------|------------|--------|
|
| 250 |
-
| 🟢 Verde | (0, 255, 0) | Clásico estilo matrix |
|
| 251 |
-
| ⚪ Blanco | (255, 255, 255) | Estilo escáner médico |
|
| 252 |
-
| 🔴 Rojo | (255, 0, 0) | Estilo alarma/emergencia |
|
| 253 |
-
| 🔵 Azul | (0, 0, 255) | Estilo futurista |
|
| 254 |
-
| 🟣 Purpura | (180, 0, 180) | Estilo ciberpunk |
|
| 255 |
-
| ⚫ Gris | (180, 180, 180) | Estilo retro monocromo |
|
| 256 |
-
""")
|
| 257 |
|
| 258 |
-
#
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
("Rojo Intenso", 15, 2, "🔴 Rojo", 0.7),
|
| 264 |
-
("Azul Futurista", 25, 4, "🔵 Azul", 0.6),
|
| 265 |
-
("Blanco Médico", 10, 1, "⚪ Blanco", 0.8),
|
| 266 |
-
]
|
| 267 |
-
|
| 268 |
-
for nombre, espacio, grosor, color, nitidez in ejemplos:
|
| 269 |
-
with gr.Column():
|
| 270 |
-
ejemplo_btn = gr.Button(f"🎯 {nombre}")
|
| 271 |
-
ejemplo_btn.click(
|
| 272 |
-
fn=lambda e=espacio, g=grosor, c=color, n=nitidez: [e, g, c, n],
|
| 273 |
-
inputs=[],
|
| 274 |
-
outputs=[espacio_slider, grosor_slider, color_select, nitidez_slider]
|
| 275 |
-
)
|
| 276 |
-
|
| 277 |
-
# Funciones de utilidad
|
| 278 |
-
def reset_valores():
|
| 279 |
-
return [20, 3, "🟢 Verde", 0.5]
|
| 280 |
|
| 281 |
# Conectar eventos
|
| 282 |
-
|
| 283 |
-
fn=
|
| 284 |
-
inputs=
|
| 285 |
outputs=output_img
|
| 286 |
)
|
| 287 |
|
| 288 |
-
|
| 289 |
-
fn=
|
| 290 |
-
inputs=[],
|
| 291 |
-
outputs=[espacio_slider, grosor_slider, color_select, nitidez_slider]
|
| 292 |
-
)
|
| 293 |
-
|
| 294 |
-
# Procesar automáticamente al cambiar imagen
|
| 295 |
-
input_img.change(
|
| 296 |
-
fn=lambda img: efecto_scanner_mejorado(img, 20, 3, "🟢 Verde", 0.5),
|
| 297 |
-
inputs=input_img,
|
| 298 |
outputs=output_img
|
| 299 |
)
|
| 300 |
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
""")
|
| 309 |
|
| 310 |
if __name__ == "__main__":
|
| 311 |
-
demo.launch(
|
| 312 |
-
server_name="0.0.0.0",
|
| 313 |
-
server_port=7860,
|
| 314 |
-
share=False
|
| 315 |
-
)
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
+
# Definición de colores disponibles (simplificado)
|
| 6 |
COLORES = {
|
| 7 |
"🟢 Verde": [0, 255, 0],
|
| 8 |
"⚪ Blanco": [255, 255, 255],
|
|
|
|
| 12 |
"⚫ Gris": [180, 180, 180]
|
| 13 |
}
|
| 14 |
|
| 15 |
+
def efecto_scanner_simple(imagen, espacio_lineas=20, grosor_linea=3, color="🟢 Verde", nitidez=0.5):
|
| 16 |
"""
|
| 17 |
+
Efecto scanner simplificado y robusto
|
| 18 |
"""
|
| 19 |
+
try:
|
| 20 |
+
# Obtener color seleccionado
|
| 21 |
+
color_rgb = COLORES[color]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# Convertir imagen
|
| 24 |
+
img = np.array(imagen.convert('RGB'))
|
| 25 |
+
h, w = img.shape[:2]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
# 1. Crear fondo NEGRO completo
|
| 28 |
+
resultado = np.zeros((h, w, 3), dtype=np.uint8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# 2. Extraer detalles de la imagen original
|
| 31 |
+
gray = np.mean(img, axis=2).astype(np.uint8)
|
| 32 |
+
|
| 33 |
+
# 3. Mejorar nitidez básica
|
| 34 |
+
if nitidez > 0:
|
| 35 |
+
# Versión simple de enfoque
|
| 36 |
+
sharpened = gray.copy()
|
| 37 |
+
for i in range(1, h-1):
|
| 38 |
+
for j in range(1, w-1):
|
| 39 |
+
# Filtro simple de enfoque
|
| 40 |
+
sharpened[i, j] = np.clip(
|
| 41 |
+
gray[i, j] * (1 + nitidez) -
|
| 42 |
+
0.25 * (gray[i-1, j] + gray[i+1, j] + gray[i, j-1] + gray[i, j+1]),
|
| 43 |
+
0, 255
|
| 44 |
+
)
|
| 45 |
+
gray = sharpened
|
| 46 |
+
|
| 47 |
+
# 4. Detectar bordes simple
|
| 48 |
+
edges = np.zeros((h, w), dtype=np.uint8)
|
| 49 |
+
for i in range(1, h-1):
|
| 50 |
+
for j in range(1, w-1):
|
| 51 |
+
dx = abs(int(gray[i, j+1]) - int(gray[i, j-1]))
|
| 52 |
+
dy = abs(int(gray[i+1, j]) - int(gray[i-1, j]))
|
| 53 |
+
edges[i, j] = min(dx + dy, 255)
|
| 54 |
+
|
| 55 |
+
# 5. Añadir LÍNEAS HORIZONTALES brillantes
|
| 56 |
+
for y in range(0, h, espacio_lineas):
|
| 57 |
for t in range(grosor_linea):
|
| 58 |
if y + t < h:
|
| 59 |
+
# Línea con color seleccionado
|
| 60 |
for c in range(3):
|
| 61 |
+
resultado[y + t, :, c] = color_rgb[c]
|
| 62 |
+
|
| 63 |
+
# 6. Añadir detalles importantes
|
| 64 |
+
# Áreas con bordes fuertes
|
| 65 |
+
edge_mask = edges > 50
|
| 66 |
+
for c in range(3):
|
| 67 |
+
if color_rgb[c] > 0:
|
| 68 |
+
resultado[edge_mask, c] = np.clip(
|
| 69 |
+
resultado[edge_mask, c] + edges[edge_mask] * 0.7,
|
| 70 |
+
0, 255
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
# 7. Añadir áreas brillantes de la imagen original
|
| 74 |
+
bright_mask = gray > 100
|
| 75 |
+
for c in range(3):
|
| 76 |
+
if color_rgb[c] > 0:
|
| 77 |
+
weight = color_rgb[c] / 255.0 * 0.3
|
| 78 |
+
resultado[bright_mask, c] = np.clip(
|
| 79 |
+
resultado[bright_mask, c] + gray[bright_mask] * weight,
|
| 80 |
+
0, 255
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
# 8. Efecto de desvanecimiento en bordes (opcional)
|
| 84 |
+
fade_width = min(50, h//4, w//4)
|
| 85 |
+
for i in range(fade_width):
|
| 86 |
+
factor = i / fade_width
|
| 87 |
+
# Borde superior
|
| 88 |
+
resultado[i, :, :] = (resultado[i, :, :] * factor).astype(np.uint8)
|
| 89 |
+
# Borde inferior
|
| 90 |
+
resultado[-(i+1), :, :] = (resultado[-(i+1), :, :] * factor).astype(np.uint8)
|
| 91 |
+
# Borde izquierdo
|
| 92 |
+
resultado[:, i, :] = (resultado[:, i, :] * factor).astype(np.uint8)
|
| 93 |
+
# Borde derecho
|
| 94 |
+
resultado[:, -(i+1), :] = (resultado[:, -(i+1), :] * factor).astype(np.uint8)
|
| 95 |
+
|
| 96 |
+
return Image.fromarray(resultado)
|
| 97 |
+
|
| 98 |
+
except Exception as e:
|
| 99 |
+
print(f"Error: {e}")
|
| 100 |
+
# En caso de error, devolver imagen de error
|
| 101 |
+
error_img = Image.new('RGB', (300, 300), color=tuple(color_rgb))
|
| 102 |
+
return error_img
|
| 103 |
|
| 104 |
+
# Interfaz simple y funcional
|
| 105 |
+
with gr.Blocks(title="Holograma Scanner Simple", theme=gr.themes.Soft()) as demo:
|
| 106 |
gr.Markdown("""
|
| 107 |
+
# 🎨 HOLOGRAMA SCANNER SIMPLE
|
|
|
|
|
|
|
| 108 |
|
| 109 |
+
Convierte imágenes en efectos scanner con diferentes colores.
|
| 110 |
""")
|
| 111 |
|
| 112 |
with gr.Row():
|
| 113 |
with gr.Column(scale=1):
|
| 114 |
input_img = gr.Image(
|
| 115 |
type="pil",
|
| 116 |
+
label="📤 Sube tu imagen"
|
|
|
|
| 117 |
)
|
| 118 |
|
| 119 |
+
color_select = gr.Dropdown(
|
| 120 |
+
choices=list(COLORES.keys()),
|
| 121 |
+
value="🟢 Verde",
|
| 122 |
+
label="🎨 Color"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
)
|
| 124 |
+
|
| 125 |
+
with gr.Row():
|
| 126 |
+
espacio = gr.Slider(5, 40, value=20, label="Espacio", step=1)
|
| 127 |
+
grosor = gr.Slider(1, 8, value=3, label="Grosor", step=1)
|
| 128 |
+
|
| 129 |
+
nitidez = gr.Slider(0.0, 1.0, value=0.5, label="Nitidez")
|
| 130 |
+
|
| 131 |
+
procesar_btn = gr.Button("✨ Generar", variant="primary")
|
| 132 |
|
| 133 |
with gr.Column(scale=1):
|
| 134 |
output_img = gr.Image(
|
| 135 |
type="pil",
|
| 136 |
+
label="✨ Resultado"
|
|
|
|
| 137 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
+
# Procesar automáticamente
|
| 140 |
+
def procesar_imagen(imagen, espacio_val, grosor_val, color_val, nitidez_val):
|
| 141 |
+
if imagen is None:
|
| 142 |
+
return None
|
| 143 |
+
return efecto_scanner_simple(imagen, espacio_val, grosor_val, color_val, nitidez_val)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
# Conectar eventos
|
| 146 |
+
input_img.change(
|
| 147 |
+
fn=lambda img: efecto_scanner_simple(img, 20, 3, "🟢 Verde", 0.5) if img else None,
|
| 148 |
+
inputs=input_img,
|
| 149 |
outputs=output_img
|
| 150 |
)
|
| 151 |
|
| 152 |
+
procesar_btn.click(
|
| 153 |
+
fn=procesar_imagen,
|
| 154 |
+
inputs=[input_img, espacio, grosor, color_select, nitidez],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
outputs=output_img
|
| 156 |
)
|
| 157 |
|
| 158 |
+
# Cambiar parámetros también actualiza
|
| 159 |
+
for control in [espacio, grosor, color_select, nitidez]:
|
| 160 |
+
control.change(
|
| 161 |
+
fn=procesar_imagen,
|
| 162 |
+
inputs=[input_img, espacio, grosor, color_select, nitidez],
|
| 163 |
+
outputs=output_img
|
| 164 |
+
)
|
|
|
|
| 165 |
|
| 166 |
if __name__ == "__main__":
|
| 167 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|