Spaces:
Running
Running
Download app.py from rbughao/Compressor: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/rbughao/Compressor/resolve/main/app.py
- Command line
-
hf download hf://spaces/rbughao/Compressor/app.py
-
curl -L -o app.py https://huggingface.co/spaces/rbughao/Compressor/resolve/main/app.py
1.1 kB
| import gradio as gr | |
| from PIL import Image | |
| import io | |
| import os | |
| def compress_images(*image_paths): | |
| compressed_files = [] | |
| for image_path in image_paths: | |
| if image_path is not None: | |
| img = Image.open(image_path) | |
| compressed_io = io.BytesIO() | |
| img.save(compressed_io, format='JPEG', quality=80) | |
| compressed_io.seek(0) | |
| compressed_filename = f"compressed_{os.path.basename(image_path)}" | |
| with open(compressed_filename, "wb") as f: | |
| f.write(compressed_io.read()) | |
| compressed_files.append(compressed_filename) | |
| else: | |
| compressed_files.append(None) | |
| return compressed_files | |
| image_inputs = [gr.Image(type="filepath", label=f"Upload Image {i+1}") for i in range(5)] | |
| interface = gr.Interface( | |
| fn=compress_images, | |
| inputs=image_inputs, | |
| outputs=[gr.File(label=f"Download Compressed Image {i+1}") for i in range(5)], | |
| title="Multi-Image Compressor", | |
| description="Upload up to 5 images to compress them and download the compressed versions." | |
| ) | |
| interface.launch() |