Merlintxu commited on
Commit
0db0341
·
verified ·
1 Parent(s): 9966cd3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ 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
+ def convert_multiple_images(images, target_format):
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 tus imágenes", file_types=['image'], multiple=True)
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=convert_multiple_images, inputs=[image_input, format_dropdown], outputs=output_gallery)
28
+
29
+ demo.launch()