Spaces:
Runtime error
Runtime error
Download app.py from Marcepelaez/REVELADOOK: direct link, hf CLI and curl.
- Browser
- Download file 3 kB
-
https://huggingface.co/spaces/Marcepelaez/REVELADOOK/resolve/main/app.py
- Command line
-
hf download hf://spaces/Marcepelaez/REVELADOOK/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Marcepelaez/REVELADOOK/resolve/main/app.py
3 kB
| from PIL import Image, ImageOps, ImageEnhance | |
| import gradio as gr | |
| import numpy as np | |
| # Funci贸n para transformar negativo a positivo ajustando el balance de color | |
| def negativo_a_positivo_fotografico(image): | |
| # Convertir la imagen a modo RGB si no lo est谩 | |
| if image.mode != "RGB": | |
| image = image.convert("RGB") | |
| # Invertir los colores de la imagen (convertir negativo a positivo) | |
| image_invertida = ImageOps.invert(image) | |
| # Mejorar la saturaci贸n y el brillo para corregir la apariencia t铆pica de los negativos | |
| image_corregida = ImageEnhance.Color(image_invertida).enhance(1.5) # Ajustar la saturaci贸n | |
| image_corregida = ImageEnhance.Brightness(image_corregida).enhance(1.2) # Ajustar el brillo | |
| return image_corregida | |
| # Funci贸n original para im谩genes digitales negativas | |
| def negativo_a_positivo(image): | |
| # Convertir la imagen a modo RGB si no lo est谩 | |
| if image.mode != "RGB": | |
| image = image.convert("RGB") | |
| # Invertir los colores de la imagen (transformar negativo a positivo) | |
| image_positivo = ImageOps.invert(image) | |
| return image_positivo | |
| # Interfaz para Gradio con selecci贸n de tipo de imagen y ajustes de brillo y saturaci贸n | |
| def interfaz(image, tipo_negativo, brillo, saturacion, contraste, nitidez): | |
| # Convertir la imagen a un formato adecuado para Pillow | |
| pil_image = Image.fromarray(image) | |
| # Elegir el tipo de conversi贸n seg煤n la selecci贸n del usuario | |
| if tipo_negativo == "Negativo Digital": | |
| image_positivo = negativo_a_positivo(pil_image) | |
| else: | |
| image_positivo = negativo_a_positivo_fotografico(pil_image) | |
| # Aplicar ajustes de brillo, saturaci贸n, contraste y nitidez | |
| image_positivo = ImageEnhance.Brightness(image_positivo).enhance(brillo) | |
| image_positivo = ImageEnhance.Color(image_positivo).enhance(saturacion) | |
| image_positivo = ImageEnhance.Contrast(image_positivo).enhance(contraste) | |
| image_positivo = ImageEnhance.Sharpness(image_positivo).enhance(nitidez) | |
| # Devolver la imagen transformada en formato de array para Gradio | |
| return np.array(image_positivo) | |
| # Crear el Space de Hugging Face con Gradio | |
| demo = gr.Interface( | |
| fn=interfaz, | |
| inputs=[ | |
| gr.Image(type="numpy", label="Sube o captura una imagen en negativo"), | |
| gr.Radio(choices=["Negativo Digital", "Negativo de Rollo Fotogr谩fico"], label="Tipo de Negativo"), | |
| gr.Slider(0.5, 2.0, value=1.0, label="Ajuste de Brillo"), | |
| gr.Slider(0.5, 2.0, value=1.0, label="Ajuste de Saturaci贸n"), | |
| gr.Slider(0.5, 2.0, value=1.0, label="Ajuste de Contraste"), | |
| gr.Slider(0.5, 2.0, value=1.0, label="Ajuste de Nitidez") | |
| ], | |
| outputs="image", | |
| live=True, | |
| title="Transforma Negativos en Positivos", | |
| description="Carga una imagen de negativo (desde archivo o c谩mara) y ajusta el brillo, saturaci贸n, contraste y nitidez para obtener el mejor resultado." | |
| ) | |
| # Ejecutar la aplicaci贸n de Gradio | |
| demo.launch() | |