Aryan-EcoClim commited on
Commit
84b79d8
·
1 Parent(s): 72125ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -33
app.py CHANGED
@@ -11,21 +11,22 @@ from utils import *
11
  labels = gen_labels()
12
  model = model_arc() # Assuming this function initializes and returns a trained model
13
 
 
14
  # Streamlit UI
15
  st.markdown('''
16
- <div style="padding-bottom: 20px; padding-top: 20px; padding-left: 5px; padding-right: 5px">
17
- <center><h1>EcoIdentify (Test)</h1></center>
18
- </div>
19
  ''', unsafe_allow_html=True)
20
 
21
  st.markdown('''
22
- <div>
23
- <center><h3>Please upload Waste Image to find its Category</h3></center>
24
- </div>
25
  ''', unsafe_allow_html=True)
26
 
27
- opt = st.selectbox("How do you want to upload the image for classification?",
28
- ('Please Select', 'Upload image via link', 'Upload image from device'))
29
 
30
  # Image processing based on user selection
31
  image = None
@@ -47,32 +48,36 @@ elif opt == 'Upload image via link':
47
  st.error("Please Enter a valid Image Address!")
48
 
49
  try:
50
- if image is not None:
51
- st.image(image, width = 256, caption = 'Uploaded Image')
52
- if st.button('Predict'):
53
- img = preprocess(image)
54
- model = model_arc()
55
- #model.load_weights("classify_model.h5")
 
 
 
 
 
 
 
 
 
 
 
56
 
57
- print("---------------img-array---------------------")
58
- print(img[np.newaxis, ...])
59
- prediction = model.predict(img[np.newaxis, ...])
 
 
 
 
 
 
60
 
61
- print("------------summary------------------------")
62
- print(model.summary())
63
- print("------------------------------------")
64
- print(prediction)
65
-
66
- st.info('Hey! The uploaded image has been classified as " {} waste " '.format(labels[np.argmax(prediction[0], axis=-1)]) + )
67
 
68
- def
69
- if img == 'paper' or 'cardboard' or 'metal' or 'glass':
70
- return(" 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.")
71
- elif img == 'plastic':
72
- return(' therefore you 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=c1474e95017548dfJmltdHM9MTcwMzcyMTYwMCZpZ3VpZD0xNmNjOTFiOS1hMDgwLTY5MmItMzBmNi04MmE1YTE3ODY4NDImaW5zaWQ9NTIyMA&ptn=3&ver=2&hsh=3&fclid=16cc91b9-a080-692b-30f6-82a5a1786842&psq=what+type+of+plastic+can+be+recycled&u=a1aHR0cHM6Ly93d3cucGxhc3RpY3Nmb3JjaGFuZ2Uub3JnL2Jsb2cvd2hpY2gtcGxhc3RpYy1jYW4tYmUtcmVjeWNsZWQ&ntb=1 to check if this item can be recycled.')
73
- else:
74
- return('Your item is not recyclable. Please discard it safely.')
75
-
76
  except Exception as e:
77
- st.info(e)
78
- pass
 
11
  labels = gen_labels()
12
  model = model_arc() # Assuming this function initializes and returns a trained model
13
 
14
+
15
  # Streamlit UI
16
  st.markdown('''
17
+ <div style="padding-bottom: 20px; padding-top: 20px; padding-left: 5px; padding-right: 5px">
18
+ <center><h1>EcoIdentify (Test)</h1></center>
19
+ </div>
20
  ''', unsafe_allow_html=True)
21
 
22
  st.markdown('''
23
+ <div>
24
+ <center><h3>Please upload Waste Image to find its Category</h3></center>
25
+ </div>
26
  ''', unsafe_allow_html=True)
27
 
28
+ opt = st.selectbox("How do you want to upload the image for classification?",
29
+ ('Please Select', 'Upload image via link', 'Upload image from device'))
30
 
31
  # Image processing based on user selection
32
  image = None
 
48
  st.error("Please Enter a valid Image Address!")
49
 
50
  try:
51
+ if image is not None:
52
+ st.image(image, width=256, caption='Uploaded Image')
53
+ if st.button('Predict'):
54
+ img = preprocess(image)
55
+ #model = model_arc()
56
+ # model.load_weights("classify_model.h5")
57
+
58
+ print("---------------img-array---------------------")
59
+ print(img[np.newaxis, ...])
60
+ prediction = model.predict(img[np.newaxis, ...])
61
+
62
+ print("------------summary------------------------")
63
+ print(model.summary())
64
+ print("------------------------------------")
65
+ print(prediction)
66
+
67
+ st.info('Hey! The uploaded image has been classified as " {} waste " '.format(labels[np.argmax(prediction[0], axis=-1)]))
68
 
69
+ def message(img):
70
+ if img == 'paper' or 'cardboard' or 'metal' or 'glass':
71
+ return (
72
+ " 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.")
73
+ elif img == 'plastic':
74
+ return (
75
+ ' therefore you 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=c1474e95017548dfJmltdHM9MTcwMzcyMTYwMCZpZ3VpZD0xNmNjOTFiOS1hMDgwLTY5MmItMzBmNi04MmE1YTE3ODY4NDImaW5zaWQ9NTIyMA&ptn=3&ver=2&hsh=3&fclid=16cc91b9-a080-692b-30f6-82a5a1786842&psq=what+type+of+plastic+can+be+recycled&u=a1aHR0cHM6Ly93d3cucGxhc3RpY3Nmb3JjaGFuZ2Uub3JnL2Jsb2cvd2hpY2gtcGxhc3RpYy1jYW4tYmUtcmVjeWNsZWQ&ntb=1 to check if this item can be recycled.')
76
+ else:
77
+ return ('Your item is not recyclable. Please discard it safely.')
78
 
79
+ st.info(message(labels[np.argmax(prediction[0], axis=-1)]))
 
 
 
 
 
80
 
 
 
 
 
 
 
 
 
81
  except Exception as e:
82
+ st.info(e)
83
+ pass