Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,11 @@ st.markdown('The predicting result will be "Palm", or "Others".')
|
|
13 |
st.markdown('You can click "Browse files" multiple times until adding all images before generating prediction.\n')
|
14 |
|
15 |
uploaded_file = st.file_uploader("Upload an image file", type="jpg", accept_multiple_files=True)
|
16 |
-
|
|
|
|
|
|
|
|
|
17 |
|
18 |
img_height = 224
|
19 |
img_width = 224
|
@@ -21,15 +25,21 @@ class_names = ['Palm', 'Others']
|
|
21 |
|
22 |
model = tf.keras.models.load_model('model')
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
13 |
st.markdown('You can click "Browse files" multiple times until adding all images before generating prediction.\n')
|
14 |
|
15 |
uploaded_file = st.file_uploader("Upload an image file", type="jpg", accept_multiple_files=True)
|
16 |
+
|
17 |
+
imageContainer = st.empty()
|
18 |
+
imageContainer.image(uploaded_file, width=100)
|
19 |
+
|
20 |
+
closeImage = st.button("clear all images")
|
21 |
|
22 |
img_height = 224
|
23 |
img_width = 224
|
|
|
25 |
|
26 |
model = tf.keras.models.load_model('model')
|
27 |
|
28 |
+
while(1):
|
29 |
+
if uploaded_file is not None:
|
30 |
+
Generate_pred = st.button("Generate Prediction")
|
31 |
+
if Generate_pred:
|
32 |
+
for file in uploaded_file:
|
33 |
+
img = Image.open(file)
|
34 |
+
img_array = img_to_array(img)
|
35 |
+
img_array = tf.expand_dims(img_array, axis = 0) # Create a batch
|
36 |
+
processed_image = preprocess_input(img_array)
|
37 |
+
|
38 |
+
predictions = model.predict(processed_image)
|
39 |
+
score = predictions[0]
|
40 |
+
st.markdown("Predicted class of the image {} is : {}".format(file, class_names[np.argmax(score)]))
|
41 |
|
42 |
+
if closeImage:
|
43 |
+
imageContainer.empty()
|
44 |
+
if uploaded_file is not None:
|
45 |
+
del uploaded_file
|