Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,27 +3,28 @@ from PIL import Image
|
|
3 |
import os
|
4 |
|
5 |
def convert_image_format(image, target_format):
|
|
|
6 |
img = Image.open(image.name)
|
|
|
|
|
7 |
output_name = os.path.splitext(image.name)[0] + '.' + target_format.lower()
|
|
|
|
|
8 |
img.save(output_name, format=target_format.upper())
|
|
|
|
|
9 |
return output_name
|
10 |
|
11 |
-
|
12 |
-
converted_images = []
|
13 |
-
for image in images:
|
14 |
-
converted_image = convert_image_format(image, target_format)
|
15 |
-
converted_images.append(converted_image)
|
16 |
-
return converted_images
|
17 |
-
|
18 |
with gr.Blocks() as demo:
|
19 |
gr.Markdown("### Conversor de formatos de imagen")
|
20 |
|
21 |
-
image_input = gr.File(label="Sube
|
22 |
format_dropdown = gr.Dropdown(label="Selecciona el formato de salida", choices=["jpg", "png", "webp"])
|
23 |
convert_button = gr.Button("Convertir")
|
24 |
|
25 |
output_gallery = gr.Gallery(label="Imágenes convertidas")
|
26 |
|
27 |
-
convert_button.click(fn=
|
28 |
|
29 |
demo.launch()
|
|
|
3 |
import os
|
4 |
|
5 |
def convert_image_format(image, target_format):
|
6 |
+
# Convertir la imagen a un objeto PIL
|
7 |
img = Image.open(image.name)
|
8 |
+
|
9 |
+
# Definir el nombre de salida con la extensión del formato deseado
|
10 |
output_name = os.path.splitext(image.name)[0] + '.' + target_format.lower()
|
11 |
+
|
12 |
+
# Guardar la imagen en el nuevo formato
|
13 |
img.save(output_name, format=target_format.upper())
|
14 |
+
|
15 |
+
# Devolver la imagen convertida
|
16 |
return output_name
|
17 |
|
18 |
+
# Interfaz de Gradio
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
with gr.Blocks() as demo:
|
20 |
gr.Markdown("### Conversor de formatos de imagen")
|
21 |
|
22 |
+
image_input = gr.File(label="Sube tu imagen", file_types=['image']) # Removido 'multiple=True'
|
23 |
format_dropdown = gr.Dropdown(label="Selecciona el formato de salida", choices=["jpg", "png", "webp"])
|
24 |
convert_button = gr.Button("Convertir")
|
25 |
|
26 |
output_gallery = gr.Gallery(label="Imágenes convertidas")
|
27 |
|
28 |
+
convert_button.click(fn=convert_image_format, inputs=[image_input, format_dropdown], outputs=output_gallery)
|
29 |
|
30 |
demo.launch()
|