Spaces:
Running
Running
File size: 1,974 Bytes
58bd1b2 baf7aa0 58bd1b2 af8f82e cefb660 418cf06 cefb660 baf7aa0 cefb660 418cf06 cefb660 baf7aa0 cefb660 418cf06 cefb660 baf7aa0 cefb660 418cf06 cefb660 58bd1b2 cefb660 58bd1b2 cefb660 37e92bb 3b48e73 37e92bb cefb660 58bd1b2 cefb660 baf7aa0 58bd1b2 baf7aa0 25487d9 baf7aa0 |
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 50 51 52 53 54 55 56 57 58 59 60 61 |
import time
import streamlit as st
import numpy as np
from PIL import Image
import urllib.request
import io
from utils import *
# Initialize labels and model
labels = gen_labels()
model = model_arc() # Assuming this function initializes and returns a trained model
# Streamlit UI
st.markdown('''
<div style="padding-bottom: 20px; padding-top: 20px; padding-left: 5px; padding-right: 5px">
<center><h1>Garbage Segregation</h1></center>
</div>
''', unsafe_allow_html=True)
st.markdown('''
<div>
<center><h3>Please upload Waste Image to find its Category</h3></center>
</div>
''', unsafe_allow_html=True)
opt = st.selectbox("How do you want to upload the image for classification?",
('Please Select', 'Upload image via link', 'Upload image from device'))
# Image processing based on user selection
image = None
if opt == 'Upload image from device':
file = st.file_uploader('Select', type=['jpg', 'png', 'jpeg'])
if file:
try:
image = Image.open(io.BytesIO(file.read())).resize((256, 256), Image.LANCZOS)
except Exception as e:
st.error(f"Error reading the file: {e}")
elif opt == 'Upload image via link':
img_url = st.text_input('Enter the Image Address')
if st.button('Submit'):
try:
response = urllib.request.urlopen(img_url)
image = Image.open(response).resize((256, 256), Image.LANCZOS)
except ValueError:
st.error("Please Enter a valid Image Address!")
try:
if image is not None:
st.image(image, width = 300, caption = 'Uploaded Image')
if st.button('Predict'):
img = preprocess(image)
model = model_arc()
#model.load_weights("classify_model.h5")
prediction = model.predict(img[np.newaxis, ...])
st.info('Hey! The uploaded image has been classified as " {} waste " '.format(labels[np.argmax(prediction[0], axis=-1)]))
except Exception as e:
st.info(e)
pass |