VishnuEcoClim commited on
Commit
cefb660
·
1 Parent(s): af8f82e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -22
app.py CHANGED
@@ -3,48 +3,47 @@ import streamlit as st
3
  import numpy as np
4
  from PIL import Image
5
  import urllib.request
6
- from utils import *
7
  import io
 
8
 
 
9
  labels = gen_labels()
 
10
 
11
- html_temp = '''
 
12
  <div style="padding-bottom: 20px; padding-top: 20px; padding-left: 5px; padding-right: 5px">
13
  <center><h1>Garbage Segregation</h1></center>
14
  </div>
15
- '''
16
- st.markdown(html_temp, unsafe_allow_html=True)
17
 
18
- html_temp = '''
19
  <div>
20
- <h2></h2>
21
  <center><h3>Please upload Waste Image to find its Category</h3></center>
22
  </div>
23
- '''
24
- st.markdown(html_temp, unsafe_allow_html=True)
25
 
26
- opt = st.selectbox("How do you want to upload the image for classification?\n", ('Please Select', 'Upload image via link', 'Upload image from device'))
27
-
28
- image = None # Initialize image variable
29
 
 
 
30
  if opt == 'Upload image from device':
31
  file = st.file_uploader('Select', type=['jpg', 'png', 'jpeg'])
32
- if file is not None:
33
  try:
34
  image = Image.open(io.BytesIO(file.read())).resize((256, 256), Image.LANCZOS)
35
  except Exception as e:
36
- st.error(f"Error: {e}")
37
 
38
  elif opt == 'Upload image via link':
39
- try:
40
- img = st.text_input('Enter the Image Address')
41
- response = urllib.request.urlopen(img)
42
- image = Image.open(response).resize((256, 256), Image.LANCZOS)
43
- except ValueError:
44
- if st.button('Submit'):
45
- show = st.error("Please Enter a valid Image Address!")
46
- time.sleep(4)
47
- show.empty()
48
 
49
  try:
50
  if image is not None:
 
3
  import numpy as np
4
  from PIL import Image
5
  import urllib.request
 
6
  import io
7
+ from utils import *
8
 
9
+ # Initialize labels and model
10
  labels = gen_labels()
11
+ model = model_arc() # Assuming this function initializes and returns a trained model
12
 
13
+ # Streamlit UI
14
+ st.markdown('''
15
  <div style="padding-bottom: 20px; padding-top: 20px; padding-left: 5px; padding-right: 5px">
16
  <center><h1>Garbage Segregation</h1></center>
17
  </div>
18
+ ''', unsafe_allow_html=True)
 
19
 
20
+ st.markdown('''
21
  <div>
 
22
  <center><h3>Please upload Waste Image to find its Category</h3></center>
23
  </div>
24
+ ''', unsafe_allow_html=True)
 
25
 
26
+ opt = st.selectbox("How do you want to upload the image for classification?",
27
+ ('Please Select', 'Upload image via link', 'Upload image from device'))
 
28
 
29
+ # Image processing based on user selection
30
+ image = None
31
  if opt == 'Upload image from device':
32
  file = st.file_uploader('Select', type=['jpg', 'png', 'jpeg'])
33
+ if file:
34
  try:
35
  image = Image.open(io.BytesIO(file.read())).resize((256, 256), Image.LANCZOS)
36
  except Exception as e:
37
+ st.error(f"Error reading the file: {e}")
38
 
39
  elif opt == 'Upload image via link':
40
+ img_url = st.text_input('Enter the Image Address')
41
+ if st.button('Submit'):
42
+ try:
43
+ response = urllib.request.urlopen(img_url)
44
+ image = Image.open(response).resize((256, 256), Image.LANCZOS)
45
+ except ValueError:
46
+ st.error("Please Enter a valid Image Address!")
 
 
47
 
48
  try:
49
  if image is not None: