Spaces:
Runtime error
Runtime error
File size: 637 Bytes
3e086d6 | 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 | import gradio as gr
from PIL import Image
import io
def convert_image(input_image, output_format):
image = Image.open(input_image)
output_buffer = io.BytesIO()
image.save(output_buffer, format=output_format)
output_buffer.seek(0)
return output_buffer
formats = ["JPEG", "PNG", "BMP", "GIF", "TIFF"]
demo = gr.Interface(
fn=convert_image,
inputs=[gr.inputs.Image(type="file"), gr.inputs.Dropdown(formats)],
outputs=gr.outputs.Image(type="file"),
title="Image Converter",
description="Convert images to different formats",
allow_flagging=False
)
if __name__ == "__main__":
demo.launch()
|