VishnuEcoClim commited on
Commit
94e1bda
·
1 Parent(s): 7d749db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -23
app.py CHANGED
@@ -5,16 +5,6 @@ from PIL import Image
5
  import urllib.request
6
  from utils import *
7
 
8
- def build_and_load_model():
9
- # Initialize and build the model first
10
- model = model_arc()
11
- dummy_input = tf.zeros((1, 256, 256, 3))
12
- model.build(input_shape=dummy_input.shape)
13
- model(dummy_input)
14
- model.load_weights("classify_model.h5")
15
- return model
16
-
17
- model = build_and_load_model()
18
  labels = gen_labels()
19
 
20
  html_temp = '''
@@ -22,7 +12,6 @@ html_temp = '''
22
  <center><h1>Garbage Segregation</h1></center>
23
  </div>
24
  '''
25
-
26
  st.markdown(html_temp, unsafe_allow_html=True)
27
 
28
  html_temp = '''
@@ -31,7 +20,6 @@ html_temp = '''
31
  <center><h3>Please upload Waste Image to find its Category</h3></center>
32
  </div>
33
  '''
34
-
35
  st.markdown(html_temp, unsafe_allow_html=True)
36
 
37
  opt = st.selectbox("How do you want to upload the image for classification?\n", ('Please Select', 'Upload image via link', 'Upload image from device'))
@@ -47,19 +35,15 @@ elif opt == 'Upload image via link':
47
  try:
48
  img = st.text_input('Enter the Image Address')
49
  image = Image.open(urllib.request.urlopen(img)).resize((256, 256), Image.LANCZOS)
50
- except:
51
  if st.button('Submit'):
52
  show = st.error("Please Enter a valid Image Address!")
53
  time.sleep(4)
54
  show.empty()
55
 
56
- try:
57
- if image is not None:
58
- st.image(image, width=256, caption='Uploaded Image')
59
- if st.button('Predict'):
60
- img = preprocess(image)
61
-
62
- prediction = model.predict(img)
63
- st.info('Hey! The uploaded image has been classified as "{} waste" '.format(labels[np.argmax(prediction)]))
64
- except Exception as e:
65
- st.info(str(e))
 
5
  import urllib.request
6
  from utils import *
7
 
 
 
 
 
 
 
 
 
 
 
8
  labels = gen_labels()
9
 
10
  html_temp = '''
 
12
  <center><h1>Garbage Segregation</h1></center>
13
  </div>
14
  '''
 
15
  st.markdown(html_temp, unsafe_allow_html=True)
16
 
17
  html_temp = '''
 
20
  <center><h3>Please upload Waste Image to find its Category</h3></center>
21
  </div>
22
  '''
 
23
  st.markdown(html_temp, unsafe_allow_html=True)
24
 
25
  opt = st.selectbox("How do you want to upload the image for classification?\n", ('Please Select', 'Upload image via link', 'Upload image from device'))
 
35
  try:
36
  img = st.text_input('Enter the Image Address')
37
  image = Image.open(urllib.request.urlopen(img)).resize((256, 256), Image.LANCZOS)
38
+ except ValueError:
39
  if st.button('Submit'):
40
  show = st.error("Please Enter a valid Image Address!")
41
  time.sleep(4)
42
  show.empty()
43
 
44
+ if image is not None:
45
+ st.image(image, width=256, caption='Uploaded Image')
46
+ if st.button('Predict'):
47
+ img_array = preprocess(image)
48
+ prediction = model.predict(img_array)
49
+ st.info(f'Hey! The uploaded image has been classified as "{labels[np.argmax(prediction)]}" waste.')