Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import io
|
| 4 |
+
|
| 5 |
+
def compress_image(image_path):
|
| 6 |
+
img = Image.open(image_path)
|
| 7 |
+
compressed_io = io.BytesIO()
|
| 8 |
+
img.save(compressed_io, format='JPEG', quality=30)
|
| 9 |
+
compressed_io.seek(0)
|
| 10 |
+
compressed_filename = "compressed_image.jpg"
|
| 11 |
+
with open(compressed_filename, "wb") as f:
|
| 12 |
+
f.write(compressed_io.read())
|
| 13 |
+
return compressed_filename
|
| 14 |
+
|
| 15 |
+
interface = gr.Interface(
|
| 16 |
+
fn=compress_image,
|
| 17 |
+
inputs=gr.Image(type="filepath", label="Upload Image"),
|
| 18 |
+
outputs=gr.File(label="Download Compressed Image"),
|
| 19 |
+
title="Image Compressor",
|
| 20 |
+
description="Upload an image to compress it and download the compressed version."
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
interface.launch()
|