lily-hust commited on
Commit
f93980b
·
1 Parent(s): 8407fab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -12
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
- st.image(uploaded_file, width=100)
 
 
 
 
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
- if uploaded_file is not None:
25
- Generate_pred = st.button("Generate Prediction")
26
- if Generate_pred:
27
- for file in uploaded_file:
28
- img = Image.open(file)
29
- img_array = img_to_array(img)
30
- img_array = tf.expand_dims(img_array, axis = 0) # Create a batch
31
- processed_image = preprocess_input(img_array)
 
 
 
 
 
32
 
33
- predictions = model.predict(processed_image)
34
- score = predictions[0]
35
- st.markdown("Predicted class of the image {} is : {}".format(file, class_names[np.argmax(score)]))
 
 
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