nishantguvvada commited on
Commit
8904fa3
·
1 Parent(s): 2cc33ea

added button

Browse files
Files changed (1) hide show
  1. app.py +27 -12
app.py CHANGED
@@ -28,16 +28,31 @@ def model_prediction(image, model):
28
  else:
29
  result = "Prediction is control"
30
  return result
31
-
32
- if file is None:
33
- st.text("Please upload an image file")
34
- else:
35
- image = Image.open(file)
36
- st.image(image, use_column_width=True)
37
- new_image = np.stack((image,), axis=0)
38
- predictions = model_prediction(new_image, model)
39
- st.write(prediction)
40
- print(
41
- "This image most likely belongs to {}."
42
- .format(prediction)
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  )
 
 
 
28
  else:
29
  result = "Prediction is control"
30
  return result
31
+
32
+ def model_prediction(image, model):
33
+ img = cv2.imread(image)
34
+ plt.imshow(img)
35
+ plt.show()
36
+ resize = tf.image.resize(img, (256,256))
37
+ yhat = model.predict(np.expand_dims(resize/255, 0))
38
+ if(yhat>0.5):
39
+ result = "Prediction is loose"
40
+ else:
41
+ result = "Prediction is control"
42
+ return result
43
+
44
+
45
+ def on_click():
46
+ if file is None:
47
+ st.text("Please upload an image file")
48
+ else:
49
+ image = Image.open(file)
50
+ st.image(image, use_column_width=True)
51
+ predictions = model_prediction(image, model)
52
+ st.write(prediction)
53
+ print(
54
+ "This image most likely belongs to {}."
55
+ .format(prediction)
56
  )
57
+
58
+ st.button('Predict', on_click=on_click)