Spaces:
Sleeping
Sleeping
nishantguvvada
commited on
Commit
·
8904fa3
1
Parent(s):
2cc33ea
added button
Browse files
app.py
CHANGED
@@ -28,16 +28,31 @@ def model_prediction(image, model):
|
|
28 |
else:
|
29 |
result = "Prediction is control"
|
30 |
return result
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|