Spaces:
Running
Running
Wkatir
commited on
Commit
·
59ac13d
1
Parent(s):
dded47d
feat: including the input of drp
Browse files- pages/1_Cloudinary_AI.py +8 -6
- pages/2_Cloudinary_Crop.py +8 -10
pages/1_Cloudinary_AI.py
CHANGED
@@ -41,7 +41,7 @@ def cleanup_cloudinary():
|
|
41 |
st.error(f"Error al limpiar recursos: {e}")
|
42 |
|
43 |
|
44 |
-
def process_image(image, width, height):
|
45 |
"""
|
46 |
Procesa la imagen usando Cloudinary. Se asegura de reiniciar el puntero del archivo.
|
47 |
Retorna una tupla (imagen_procesada_bytes, extension_del_archivo).
|
@@ -54,7 +54,7 @@ def process_image(image, width, height):
|
|
54 |
# Reiniciar el puntero para garantizar la lectura completa
|
55 |
image.seek(0)
|
56 |
if not check_file_size(image, 10):
|
57 |
-
st.error(
|
58 |
return None, None
|
59 |
|
60 |
image_content = image.read()
|
@@ -67,7 +67,7 @@ def process_image(image, width, height):
|
|
67 |
"crop": "pad",
|
68 |
"background": "gen_fill",
|
69 |
"quality": 100,
|
70 |
-
"dpr":
|
71 |
"flags": "preserve_transparency"
|
72 |
}]
|
73 |
)
|
@@ -107,7 +107,7 @@ def main():
|
|
107 |
**Características clave:**
|
108 |
- Mantiene transparencia en PNGs
|
109 |
- Soporte para formatos modernos (WEBP)
|
110 |
-
- Calidad ultra HD (DPR 3)
|
111 |
- Procesamiento por lotes
|
112 |
- Fondo generado por IA se adapta al contexto
|
113 |
|
@@ -117,11 +117,13 @@ def main():
|
|
117 |
- El tiempo de procesamiento varía según el tamaño y cantidad de imágenes
|
118 |
""")
|
119 |
|
120 |
-
col1, col2 = st.columns(
|
121 |
with col1:
|
122 |
width = st.number_input("Ancho (px)", value=1000, min_value=100, max_value=3000)
|
123 |
with col2:
|
124 |
height = st.number_input("Alto (px)", value=460, min_value=100, max_value=3000)
|
|
|
|
|
125 |
|
126 |
uploaded_files = st.file_uploader(
|
127 |
"Sube tus imágenes (máx. 10MB por archivo)",
|
@@ -152,7 +154,7 @@ def main():
|
|
152 |
# Crear un nuevo objeto BytesIO para cada imagen
|
153 |
img_io = io.BytesIO(img_bytes)
|
154 |
with st.spinner(f'Procesando imagen {idx + 1}/{len(original_images)}...'):
|
155 |
-
processed, file_format = process_image(img_io, width, height)
|
156 |
if processed:
|
157 |
processed_images.append((processed, file_format))
|
158 |
progress_bar.progress((idx + 1) / len(original_images))
|
|
|
41 |
st.error(f"Error al limpiar recursos: {e}")
|
42 |
|
43 |
|
44 |
+
def process_image(image, width, height, dpr):
|
45 |
"""
|
46 |
Procesa la imagen usando Cloudinary. Se asegura de reiniciar el puntero del archivo.
|
47 |
Retorna una tupla (imagen_procesada_bytes, extension_del_archivo).
|
|
|
54 |
# Reiniciar el puntero para garantizar la lectura completa
|
55 |
image.seek(0)
|
56 |
if not check_file_size(image, 10):
|
57 |
+
st.error("La imagen excede el límite de 10MB")
|
58 |
return None, None
|
59 |
|
60 |
image_content = image.read()
|
|
|
67 |
"crop": "pad",
|
68 |
"background": "gen_fill",
|
69 |
"quality": 100,
|
70 |
+
"dpr": dpr,
|
71 |
"flags": "preserve_transparency"
|
72 |
}]
|
73 |
)
|
|
|
107 |
**Características clave:**
|
108 |
- Mantiene transparencia en PNGs
|
109 |
- Soporte para formatos modernos (WEBP)
|
110 |
+
- Calidad ultra HD (DPR configurable entre 1 y 3)
|
111 |
- Procesamiento por lotes
|
112 |
- Fondo generado por IA se adapta al contexto
|
113 |
|
|
|
117 |
- El tiempo de procesamiento varía según el tamaño y cantidad de imágenes
|
118 |
""")
|
119 |
|
120 |
+
col1, col2, col3 = st.columns(3)
|
121 |
with col1:
|
122 |
width = st.number_input("Ancho (px)", value=1000, min_value=100, max_value=3000)
|
123 |
with col2:
|
124 |
height = st.number_input("Alto (px)", value=460, min_value=100, max_value=3000)
|
125 |
+
with col3:
|
126 |
+
dpr = st.number_input("DPR", value=3, min_value=1, max_value=3, step=1)
|
127 |
|
128 |
uploaded_files = st.file_uploader(
|
129 |
"Sube tus imágenes (máx. 10MB por archivo)",
|
|
|
154 |
# Crear un nuevo objeto BytesIO para cada imagen
|
155 |
img_io = io.BytesIO(img_bytes)
|
156 |
with st.spinner(f'Procesando imagen {idx + 1}/{len(original_images)}...'):
|
157 |
+
processed, file_format = process_image(img_io, width, height, dpr)
|
158 |
if processed:
|
159 |
processed_images.append((processed, file_format))
|
160 |
progress_bar.progress((idx + 1) / len(original_images))
|
pages/2_Cloudinary_Crop.py
CHANGED
@@ -41,7 +41,7 @@ def cleanup_cloudinary():
|
|
41 |
st.error(f"Error al limpiar recursos: {e}")
|
42 |
|
43 |
|
44 |
-
def process_image(image, width, height, gravity_option):
|
45 |
"""
|
46 |
Procesa la imagen usando Cloudinary y retorna la imagen procesada.
|
47 |
Se reinicia el puntero del stream y se utiliza el atributo 'name'
|
@@ -52,7 +52,6 @@ def process_image(image, width, height, gravity_option):
|
|
52 |
return None
|
53 |
|
54 |
try:
|
55 |
-
# Reinicia el puntero para leer la imagen completa
|
56 |
image.seek(0)
|
57 |
image_name = getattr(image, 'name', '')
|
58 |
if not check_file_size(image, 10):
|
@@ -69,7 +68,7 @@ def process_image(image, width, height, gravity_option):
|
|
69 |
"crop": "fill",
|
70 |
"gravity": gravity_option,
|
71 |
"quality": 100,
|
72 |
-
"dpr":
|
73 |
"flags": "preserve_transparency" if image_name.lower().endswith('.png') else None
|
74 |
}]
|
75 |
)
|
@@ -104,13 +103,13 @@ def main():
|
|
104 |
- 🚀 Procesamiento por lotes y descarga en ZIP
|
105 |
|
106 |
**Pasos para usar:**
|
107 |
-
1. ⚙️ Configura dimensiones deseadas
|
108 |
-
2. 🎯 Selecciona el tipo de gravedad
|
109 |
3. 📤 Sube tus imágenes (máx. 10MB c/u)
|
110 |
4. 🚀 Procesa y descarga los resultados
|
111 |
""")
|
112 |
|
113 |
-
col1, col2, col3 = st.columns(
|
114 |
with col1:
|
115 |
width = st.number_input("Ancho (px)", value=1000, min_value=100, max_value=3000)
|
116 |
with col2:
|
@@ -121,6 +120,8 @@ def main():
|
|
121 |
["auto", "center", "face", "faces", "north", "south", "east", "west"],
|
122 |
help="Configura cómo se enfocará el recorte en la imagen"
|
123 |
)
|
|
|
|
|
124 |
|
125 |
uploaded_files = st.file_uploader(
|
126 |
"Sube tus imágenes (máx. 10MB por archivo)",
|
@@ -131,7 +132,6 @@ def main():
|
|
131 |
if uploaded_files:
|
132 |
st.header("Vista Previa Original")
|
133 |
cols = st.columns(3)
|
134 |
-
# Almacena el contenido original de cada imagen en memoria
|
135 |
original_images = []
|
136 |
for idx, file in enumerate(uploaded_files):
|
137 |
file_bytes = file.getvalue()
|
@@ -143,11 +143,10 @@ def main():
|
|
143 |
processed_images = []
|
144 |
progress_bar = st.progress(0)
|
145 |
|
146 |
-
# Procesa cada imagen utilizando un nuevo objeto BytesIO
|
147 |
for idx, (name, img_bytes) in enumerate(original_images):
|
148 |
st.write(f"Procesando: {name}")
|
149 |
img_io = io.BytesIO(img_bytes)
|
150 |
-
processed = process_image(img_io, width, height, gravity_option)
|
151 |
if processed:
|
152 |
processed_images.append((name, processed))
|
153 |
progress_bar.progress((idx + 1) / len(original_images))
|
@@ -162,7 +161,6 @@ def main():
|
|
162 |
zip_buffer = io.BytesIO()
|
163 |
with zipfile.ZipFile(zip_buffer, 'w') as zip_file:
|
164 |
for name, img_bytes in processed_images:
|
165 |
-
# Se utiliza el nombre original para mantener la extensión
|
166 |
zip_file.writestr(f"procesada_{name}", img_bytes)
|
167 |
|
168 |
st.download_button(
|
|
|
41 |
st.error(f"Error al limpiar recursos: {e}")
|
42 |
|
43 |
|
44 |
+
def process_image(image, width, height, gravity_option, dpr):
|
45 |
"""
|
46 |
Procesa la imagen usando Cloudinary y retorna la imagen procesada.
|
47 |
Se reinicia el puntero del stream y se utiliza el atributo 'name'
|
|
|
52 |
return None
|
53 |
|
54 |
try:
|
|
|
55 |
image.seek(0)
|
56 |
image_name = getattr(image, 'name', '')
|
57 |
if not check_file_size(image, 10):
|
|
|
68 |
"crop": "fill",
|
69 |
"gravity": gravity_option,
|
70 |
"quality": 100,
|
71 |
+
"dpr": dpr,
|
72 |
"flags": "preserve_transparency" if image_name.lower().endswith('.png') else None
|
73 |
}]
|
74 |
)
|
|
|
103 |
- 🚀 Procesamiento por lotes y descarga en ZIP
|
104 |
|
105 |
**Pasos para usar:**
|
106 |
+
1. ⚙️ Configura dimensiones deseadas y parámetros de recorte
|
107 |
+
2. 🎯 Selecciona el tipo de gravedad y el DPR (entre 1 y 3)
|
108 |
3. 📤 Sube tus imágenes (máx. 10MB c/u)
|
109 |
4. 🚀 Procesa y descarga los resultados
|
110 |
""")
|
111 |
|
112 |
+
col1, col2, col3, col4 = st.columns(4)
|
113 |
with col1:
|
114 |
width = st.number_input("Ancho (px)", value=1000, min_value=100, max_value=3000)
|
115 |
with col2:
|
|
|
120 |
["auto", "center", "face", "faces", "north", "south", "east", "west"],
|
121 |
help="Configura cómo se enfocará el recorte en la imagen"
|
122 |
)
|
123 |
+
with col4:
|
124 |
+
dpr = st.number_input("DPR", value=3, min_value=1, max_value=3, step=1)
|
125 |
|
126 |
uploaded_files = st.file_uploader(
|
127 |
"Sube tus imágenes (máx. 10MB por archivo)",
|
|
|
132 |
if uploaded_files:
|
133 |
st.header("Vista Previa Original")
|
134 |
cols = st.columns(3)
|
|
|
135 |
original_images = []
|
136 |
for idx, file in enumerate(uploaded_files):
|
137 |
file_bytes = file.getvalue()
|
|
|
143 |
processed_images = []
|
144 |
progress_bar = st.progress(0)
|
145 |
|
|
|
146 |
for idx, (name, img_bytes) in enumerate(original_images):
|
147 |
st.write(f"Procesando: {name}")
|
148 |
img_io = io.BytesIO(img_bytes)
|
149 |
+
processed = process_image(img_io, width, height, gravity_option, dpr)
|
150 |
if processed:
|
151 |
processed_images.append((name, processed))
|
152 |
progress_bar.progress((idx + 1) / len(original_images))
|
|
|
161 |
zip_buffer = io.BytesIO()
|
162 |
with zipfile.ZipFile(zip_buffer, 'w') as zip_file:
|
163 |
for name, img_bytes in processed_images:
|
|
|
164 |
zip_file.writestr(f"procesada_{name}", img_bytes)
|
165 |
|
166 |
st.download_button(
|