-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
34 lines (26 loc) · 1.05 KB
/
app.py
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
26
27
28
29
30
31
32
33
34
import numpy as np
import streamlit as st
from skimage.io import imread
from PIL import Image as Image
from image_compression import ImageCompressor
import base64
from warnings import filterwarnings
class WebApp:
def __init__(self):
st.title('Image Compression using K-Means Clustering')
self.__compressor = None
filterwarnings('ignore')
def upload_and_compress(self):
__uploaded_file = st.file_uploader('Choose an image...', type=['jpg', 'jpeg', 'png'])
if __uploaded_file is not None:
Image = imread(__uploaded_file)
st.image(Image, caption='Original Image', use_column_width=True)
__num_colors = st.slider('Select the number of colors:', 2, 256, 16)
self.__compressor = ImageCompressor(__num_colors)
__compressed_image = self.__compressor.compress_image(Image)
st.image(__compressed_image, caption='Compressed Image', use_column_width=True)
def main():
app = WebApp()
app.upload_and_compress()
if __name__ == '__main__':
main()