Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import io
|
| 4 |
+
|
| 5 |
+
def convert_image(input_image, output_format):
|
| 6 |
+
image = Image.open(input_image)
|
| 7 |
+
output_buffer = io.BytesIO()
|
| 8 |
+
image.save(output_buffer, format=output_format)
|
| 9 |
+
output_buffer.seek(0)
|
| 10 |
+
return output_buffer
|
| 11 |
+
|
| 12 |
+
formats = ["JPEG", "PNG", "BMP", "GIF", "TIFF"]
|
| 13 |
+
|
| 14 |
+
demo = gr.Interface(
|
| 15 |
+
fn=convert_image,
|
| 16 |
+
inputs=[gr.inputs.Image(type="file"), gr.inputs.Dropdown(formats)],
|
| 17 |
+
outputs=gr.outputs.Image(type="file"),
|
| 18 |
+
title="Image Converter",
|
| 19 |
+
description="Convert images to different formats",
|
| 20 |
+
allow_flagging=False
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
if __name__ == "__main__":
|
| 24 |
+
demo.launch()
|