Spaces:
Runtime error
Runtime error
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() | |