Spaces:
Runtime error
Runtime error
File size: 1,076 Bytes
0db0341 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import gradio as gr
from PIL import Image
import os
def convert_image_format(image, target_format):
img = Image.open(image.name)
output_name = os.path.splitext(image.name)[0] + '.' + target_format.lower()
img.save(output_name, format=target_format.upper())
return output_name
def convert_multiple_images(images, target_format):
converted_images = []
for image in images:
converted_image = convert_image_format(image, target_format)
converted_images.append(converted_image)
return converted_images
with gr.Blocks() as demo:
gr.Markdown("### Conversor de formatos de imagen")
image_input = gr.File(label="Sube tus imágenes", file_types=['image'], multiple=True)
format_dropdown = gr.Dropdown(label="Selecciona el formato de salida", choices=["jpg", "png", "webp"])
convert_button = gr.Button("Convertir")
output_gallery = gr.Gallery(label="Imágenes convertidas")
convert_button.click(fn=convert_multiple_images, inputs=[image_input, format_dropdown], outputs=output_gallery)
demo.launch()
|