Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
import cv2
|
3 |
import pandas
|
4 |
from PIL import Image
|
@@ -13,31 +15,37 @@ st.markdown("This is a Deep Learning application to identify if a satellite imag
|
|
13 |
st.markdown('The predicting result will be "Jacaranda", or "Others".')
|
14 |
st.markdown('You can click "Browse files" multiple times until adding all images before generating prediction.\n')
|
15 |
|
16 |
-
|
17 |
-
uploaded_file = st.file_uploader("Upload image files", type="jpg", accept_multiple_files=True)
|
18 |
-
|
19 |
-
#image_iterator = paginator("Select a page", uploaded_file)
|
20 |
-
#indices_on_page, images_on_page = map(list, zip(*image_iterator))
|
21 |
-
st.image(uploaded_file, width=100)
|
22 |
-
|
23 |
img_height = 224
|
24 |
img_width = 224
|
25 |
class_names = ['Jacaranda', 'Others']
|
26 |
|
27 |
model = tf.keras.models.load_model('model')
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
if uploaded_file is not None:
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
36 |
for file in uploaded_file:
|
37 |
-
# with grid[col]:
|
38 |
-
# img = Image.open(file)
|
39 |
-
# st.image(img)
|
40 |
-
#col += 1
|
41 |
img = Image.open(file)
|
42 |
img_array = img_to_array(img)
|
43 |
img_array = tf.expand_dims(img_array, axis = 0) # Create a batch
|
@@ -45,4 +53,5 @@ if uploaded_file is not None:
|
|
45 |
|
46 |
predictions = model.predict(processed_image)
|
47 |
score = predictions[0]
|
48 |
-
st.markdown("Predicted class of the image {} is : {}".format(file, class_names[np.argmax(score)]))
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import time
|
3 |
+
|
4 |
import cv2
|
5 |
import pandas
|
6 |
from PIL import Image
|
|
|
15 |
st.markdown('The predicting result will be "Jacaranda", or "Others".')
|
16 |
st.markdown('You can click "Browse files" multiple times until adding all images before generating prediction.\n')
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
img_height = 224
|
19 |
img_width = 224
|
20 |
class_names = ['Jacaranda', 'Others']
|
21 |
|
22 |
model = tf.keras.models.load_model('model')
|
23 |
|
24 |
+
state = st.session_state
|
25 |
+
if 'file_uploader_key' not in state:
|
26 |
+
state['file_uploader_key'] = 0
|
27 |
+
|
28 |
+
if "uploaded_files" not in state:
|
29 |
+
state["uploaded_files"] = []
|
30 |
+
|
31 |
+
uploaded_file = st.file_uploader(
|
32 |
+
"Upload images",
|
33 |
+
type="jpg" or 'jpeg' or 'bmp' or 'png' or 'tif',
|
34 |
+
accept_multiple_files=True,
|
35 |
+
key=state['file_uploader_key'])
|
36 |
+
|
37 |
if uploaded_file is not None:
|
38 |
+
st.image(uploaded_file, width=100)
|
39 |
+
state["uploaded_files"] = uploaded_file
|
40 |
+
|
41 |
+
if st.button("Clear uploaded images"):
|
42 |
+
state["file_uploader_key"] += 1
|
43 |
+
st.empty()
|
44 |
+
time.sleep(.5)
|
45 |
+
st.experimental_rerun()
|
46 |
+
|
47 |
+
if st.button("Generate prediction"):
|
48 |
for file in uploaded_file:
|
|
|
|
|
|
|
|
|
49 |
img = Image.open(file)
|
50 |
img_array = img_to_array(img)
|
51 |
img_array = tf.expand_dims(img_array, axis = 0) # Create a batch
|
|
|
53 |
|
54 |
predictions = model.predict(processed_image)
|
55 |
score = predictions[0]
|
56 |
+
st.markdown("Predicted class of the image {} is : {}".format(file, class_names[np.argmax(score)]))
|
57 |
+
|