Spaces:
Running
Running
Marcepelaez
commited on
Commit
•
ff1ee28
1
Parent(s):
14e4d68
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
|
|
|
5 |
def set_computer_params(computer):
|
6 |
if computer == "Commodore 64":
|
7 |
return 16, 4 # 16 niveles, pixelado moderado
|
@@ -21,6 +22,7 @@ def set_computer_params(computer):
|
|
21 |
return 4, 6 # 4 niveles, alto pixelado
|
22 |
return 16, 4 # Valores predeterminados (Commodore 64)
|
23 |
|
|
|
24 |
def convert_to_pixelated_8bit(image, computer):
|
25 |
if image is None:
|
26 |
return None
|
@@ -56,45 +58,22 @@ def convert_to_pixelated_8bit(image, computer):
|
|
56 |
|
57 |
return img_pil
|
58 |
|
59 |
-
def process_image(image, computer):
|
60 |
-
if image is None:
|
61 |
-
return None
|
62 |
-
return convert_to_pixelated_8bit(Image.fromarray(image), computer)
|
63 |
-
|
64 |
# Crear la interfaz gráfica de Gradio
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
input_image = gr.Image(source="upload", type="numpy", label="Subir Imagen")
|
72 |
-
camera_input = gr.Image(source="webcam", type="numpy", label="Usar Cámara")
|
73 |
-
capture_button = gr.Button("Capturar Imagen")
|
74 |
-
|
75 |
-
computer_dropdown = gr.Dropdown(
|
76 |
-
["Commodore 64", "ZX Spectrum", "Amstrad CPC", "Atari 8-bit (400/800)", "Apple II", "MSX", "NES (Nintendo)", "IBM PC CGA"],
|
77 |
label="Elige una computadora retro",
|
78 |
-
value="Commodore 64"
|
79 |
)
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
process_image,
|
88 |
-
inputs=[input_image, computer_dropdown],
|
89 |
-
outputs=output_image
|
90 |
-
)
|
91 |
-
|
92 |
-
capture_button.click(
|
93 |
-
lambda x: x,
|
94 |
-
inputs=camera_input,
|
95 |
-
outputs=input_image
|
96 |
-
)
|
97 |
-
|
98 |
-
gr.Markdown("Hecho con ❤️ en MDQ por Peláez")
|
99 |
|
100 |
iface.launch()
|
|
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
|
5 |
+
# Función que ajusta los parámetros según la computadora seleccionada
|
6 |
def set_computer_params(computer):
|
7 |
if computer == "Commodore 64":
|
8 |
return 16, 4 # 16 niveles, pixelado moderado
|
|
|
22 |
return 4, 6 # 4 niveles, alto pixelado
|
23 |
return 16, 4 # Valores predeterminados (Commodore 64)
|
24 |
|
25 |
+
# Función principal que convierte la imagen según los parámetros seleccionados
|
26 |
def convert_to_pixelated_8bit(image, computer):
|
27 |
if image is None:
|
28 |
return None
|
|
|
58 |
|
59 |
return img_pil
|
60 |
|
|
|
|
|
|
|
|
|
|
|
61 |
# Crear la interfaz gráfica de Gradio
|
62 |
+
iface = gr.Interface(
|
63 |
+
fn=convert_to_pixelated_8bit,
|
64 |
+
inputs=[
|
65 |
+
gr.Image(type="numpy", label="Subir Imagen"), # Subida de imagen
|
66 |
+
gr.Dropdown( # Selección de computadora retro
|
67 |
+
["Commodore 64", "ZX Spectrum", "Amstrad CPC", "Atari 8-bit (400/800)", "Apple II", "MSX", "NES (Nintendo)", "IBM PC CGA"],
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
label="Elige una computadora retro",
|
69 |
+
value="Commodore 64" # Valor predeterminado
|
70 |
)
|
71 |
+
],
|
72 |
+
outputs=gr.Image(type="numpy", label="Imagen convertida"), # Imagen resultante
|
73 |
+
title="Emulador de Gráficos de Computadoras Retro",
|
74 |
+
description="Sube una imagen y emula el estilo gráfico de computadoras de los años 80 con 8 bits y pixelado. Elige entre varias computadoras retro.",
|
75 |
+
# Agregando el mensaje "Hecho con ❤️ por Peláez"
|
76 |
+
article="Hecho con en MDQ❤️ por Peláez"
|
77 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
iface.launch()
|