Spaces:
Running
Running
Commit
·
c293bfe
1
Parent(s):
52e848a
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,14 +3,12 @@ import streamlit as st
|
|
| 3 |
from PIL import Image
|
| 4 |
import urllib.request
|
| 5 |
import io
|
| 6 |
-
from utils import *
|
| 7 |
import tensorflow as tf
|
| 8 |
|
| 9 |
# Initialize labels and model
|
| 10 |
labels = ['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash']
|
| 11 |
model = tf.keras.models.load_model('classify_model.h5')
|
| 12 |
|
| 13 |
-
|
| 14 |
# Streamlit UI
|
| 15 |
st.markdown('''
|
| 16 |
<div style="padding-bottom: 20px; padding-top: 20px; padding-left: 5px; padding-right: 5px">
|
|
@@ -24,21 +22,18 @@ st.markdown('''
|
|
| 24 |
</div>
|
| 25 |
''', unsafe_allow_html=True)
|
| 26 |
|
| 27 |
-
|
| 28 |
opt = st.selectbox(
|
| 29 |
"How do you want to upload the image for classification?",
|
| 30 |
("Please Select", "Upload image via link", "Upload image from device"),
|
| 31 |
)
|
| 32 |
|
| 33 |
image = None
|
| 34 |
-
prediction = None
|
| 35 |
|
| 36 |
if opt == 'Upload image from device':
|
| 37 |
file = st.file_uploader('Select', type=['jpg', 'png', 'jpeg'])
|
| 38 |
if file:
|
| 39 |
image = preprocess_image(file)
|
| 40 |
|
| 41 |
-
|
| 42 |
elif opt == 'Upload image via link':
|
| 43 |
img_url = st.text_input('Enter the Image Address')
|
| 44 |
if st.button('Submit'):
|
|
@@ -48,19 +43,14 @@ elif opt == 'Upload image via link':
|
|
| 48 |
except ValueError:
|
| 49 |
st.error("Please Enter a valid Image Address!")
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
try:
|
| 54 |
if image is not None:
|
| 55 |
st.image(image, width=256, caption='Uploaded Image')
|
| 56 |
if st.button('Predict'):
|
| 57 |
-
|
| 58 |
-
img = labels[np.argmax(prediction[0], axis=-1)]
|
| 59 |
|
| 60 |
print("---------------img-array---------------------")
|
| 61 |
-
print(
|
| 62 |
-
prediction = model.predict(img[np.newaxis, ...])
|
| 63 |
-
|
| 64 |
print("------------summary------------------------")
|
| 65 |
print(model.summary())
|
| 66 |
print("------------------------------------")
|
|
@@ -74,12 +64,4 @@ try:
|
|
| 74 |
" therefore your item is recyclable. Please refer to https://www.wm.com/us/en/drop-off-locations to find a drop-off location near you.")
|
| 75 |
elif img == 'plastic':
|
| 76 |
return (
|
| 77 |
-
' therefore
|
| 78 |
-
else:
|
| 79 |
-
return ('Your item is not recyclable. Please discard it safely.')
|
| 80 |
-
|
| 81 |
-
st.info(message(labels[np.argmax(prediction[0], axis=-1)]))
|
| 82 |
-
|
| 83 |
-
except Exception as e:
|
| 84 |
-
st.info(e)
|
| 85 |
-
pass
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import urllib.request
|
| 5 |
import io
|
|
|
|
| 6 |
import tensorflow as tf
|
| 7 |
|
| 8 |
# Initialize labels and model
|
| 9 |
labels = ['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash']
|
| 10 |
model = tf.keras.models.load_model('classify_model.h5')
|
| 11 |
|
|
|
|
| 12 |
# Streamlit UI
|
| 13 |
st.markdown('''
|
| 14 |
<div style="padding-bottom: 20px; padding-top: 20px; padding-left: 5px; padding-right: 5px">
|
|
|
|
| 22 |
</div>
|
| 23 |
''', unsafe_allow_html=True)
|
| 24 |
|
|
|
|
| 25 |
opt = st.selectbox(
|
| 26 |
"How do you want to upload the image for classification?",
|
| 27 |
("Please Select", "Upload image via link", "Upload image from device"),
|
| 28 |
)
|
| 29 |
|
| 30 |
image = None
|
|
|
|
| 31 |
|
| 32 |
if opt == 'Upload image from device':
|
| 33 |
file = st.file_uploader('Select', type=['jpg', 'png', 'jpeg'])
|
| 34 |
if file:
|
| 35 |
image = preprocess_image(file)
|
| 36 |
|
|
|
|
| 37 |
elif opt == 'Upload image via link':
|
| 38 |
img_url = st.text_input('Enter the Image Address')
|
| 39 |
if st.button('Submit'):
|
|
|
|
| 43 |
except ValueError:
|
| 44 |
st.error("Please Enter a valid Image Address!")
|
| 45 |
|
|
|
|
|
|
|
| 46 |
try:
|
| 47 |
if image is not None:
|
| 48 |
st.image(image, width=256, caption='Uploaded Image')
|
| 49 |
if st.button('Predict'):
|
| 50 |
+
prediction = model.predict(image[np.newaxis, ...])
|
|
|
|
| 51 |
|
| 52 |
print("---------------img-array---------------------")
|
| 53 |
+
print(image[np.newaxis, ...])
|
|
|
|
|
|
|
| 54 |
print("------------summary------------------------")
|
| 55 |
print(model.summary())
|
| 56 |
print("------------------------------------")
|
|
|
|
| 64 |
" therefore your item is recyclable. Please refer to https://www.wm.com/us/en/drop-off-locations to find a drop-off location near you.")
|
| 65 |
elif img == 'plastic':
|
| 66 |
return (
|
| 67 |
+
' therefore your item may have a chance of being recyclable. Since this model has yet to recognize types of plastics, please refer to https://www.bing.com/ck/a?!&&p=c1474e95017548dfJmltdHM9MTcwMzcyMTYwMCZpZ3U9Jm91dHB1dD1zY2VuYXJlc2NyaWFsJmF1dGhvcmU9ISBBbGJ1bXN0ZXImY2xhc3Nlc19yZGM9MjAzNTMzODU5MDE5OTg0MyZjb25kaXRpb25fZHVyPSUyNm51bTttb2QlM0QxJTI2YXJ0aWQlM0QxJTI2aW5zaWQlM0Q1MjIwJTI2cHQlM0QzJTI2dmVyPSUyNnBvc3QlM0QzJTI2cmVxJTNEJTNEJTIyJTIyJTI2Z3JvdXBpZCUzRCUyMjB1cyUyMiUyNmRpc3BsYXklM0QlMjJ1cyUyMiUyNmxvY2FsZSUzRCUyMmVuLVVTJTIyJTI2cmVxdWVzdF9pZCUzRCUyMiUyMiUyNmF1ZHN0cmVhbV9pZCUzRCUyMiUyMiUyNm5vbWVfc3RyZWFtJTNEMSUyNmNvbnRlbnQlM0REJTIyJTIyJTI2c2hvd19hcmNoaXZlJmNtcCUzRDE2Y2M5MWYxLWFhMjAtNjkyYi0zMGI2LTgyYTVhMTc4Njg0MyUyMiUzRSUzQyUyRmJvYXJkLmxlYWd1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