File size: 1,614 Bytes
58bd1b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94e1bda
58bd1b2
 
 
 
 
94e1bda
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import time
import streamlit as st
import numpy as np
from PIL import Image
import urllib.request
from utils import *

labels = gen_labels()

html_temp = '''
    <div style="padding-bottom: 20px; padding-top: 20px; padding-left: 5px; padding-right: 5px">
    <center><h1>Garbage Segregation</h1></center>
    </div>
    '''
st.markdown(html_temp, unsafe_allow_html=True)

html_temp = '''
    <div>
    <h2></h2>
    <center><h3>Please upload Waste Image to find its Category</h3></center>
    </div>
    '''
st.markdown(html_temp, unsafe_allow_html=True)

opt = st.selectbox("How do you want to upload the image for classification?\n", ('Please Select', 'Upload image via link', 'Upload image from device'))

image = None  # Initialize image variable

if opt == 'Upload image from device':
    file = st.file_uploader('Select', type=['jpg', 'png', 'jpeg'])
    if file is not None:
        image = Image.open(file).resize((256, 256), Image.LANCZOS)

elif opt == 'Upload image via link':
    try:
        img = st.text_input('Enter the Image Address')
        image = Image.open(urllib.request.urlopen(img)).resize((256, 256), Image.LANCZOS)
    except ValueError:
        if st.button('Submit'):
            show = st.error("Please Enter a valid Image Address!")
            time.sleep(4)
            show.empty()

if image is not None:
    st.image(image, width=256, caption='Uploaded Image')
    if st.button('Predict'):
        img_array = preprocess(image)
        prediction = model.predict(img_array)
        st.info(f'Hey! The uploaded image has been classified as "{labels[np.argmax(prediction)]}" waste.')