Upload 2 files
Browse files
app.py
CHANGED
|
@@ -24,7 +24,7 @@ with st.form("my_form"):
|
|
| 24 |
image = Image.open(uploaded_file)
|
| 25 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 26 |
st.markdown(
|
| 27 |
-
f"<h2 style='text-align: center;'>
|
| 28 |
unsafe_allow_html=True,
|
| 29 |
)
|
| 30 |
else:
|
|
@@ -41,6 +41,6 @@ if sample_img_choice:
|
|
| 41 |
st.image(image, caption="Image", use_column_width=True)
|
| 42 |
label = predict_label(image, model)
|
| 43 |
st.markdown(
|
| 44 |
-
f"<h2 style='text-align: center;'>
|
| 45 |
unsafe_allow_html=True,
|
| 46 |
)
|
|
|
|
| 24 |
image = Image.open(uploaded_file)
|
| 25 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 26 |
st.markdown(
|
| 27 |
+
f"<h2 style='text-align: center;'>{label}</h2>",
|
| 28 |
unsafe_allow_html=True,
|
| 29 |
)
|
| 30 |
else:
|
|
|
|
| 41 |
st.image(image, caption="Image", use_column_width=True)
|
| 42 |
label = predict_label(image, model)
|
| 43 |
st.markdown(
|
| 44 |
+
f"<h2 style='text-align: center;'>{label}</h2>",
|
| 45 |
unsafe_allow_html=True,
|
| 46 |
)
|
utils.py
CHANGED
|
@@ -109,6 +109,9 @@ def predict_label(img, model):
|
|
| 109 |
resized_img = resize(img, (150, 150)).numpy().astype(int)
|
| 110 |
exp_img = np.expand_dims(resized_img, 0)
|
| 111 |
y_prob = model.predict(exp_img)
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
resized_img = resize(img, (150, 150)).numpy().astype(int)
|
| 110 |
exp_img = np.expand_dims(resized_img, 0)
|
| 111 |
y_prob = model.predict(exp_img)
|
| 112 |
+
if y_prob.max(axis=-1) < 0.5:
|
| 113 |
+
return "Cannot predict. Please provide appropriate image."
|
| 114 |
+
else:
|
| 115 |
+
y_classes = y_prob.argmax(axis=-1)
|
| 116 |
+
label = classes[y_classes[0]]
|
| 117 |
+
return "Predicted Sport: " + label.capitalize()
|