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