awinml commited on
Commit
5f0f615
·
1 Parent(s): a7df9c8

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +2 -2
  2. utils.py +6 -3
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;'>Predicted Sport: {label}</h2>",
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;'>Predicted Sport: {label}</h2>",
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
- y_classes = y_prob.argmax(axis=-1)
113
- label = classes[y_classes[0]]
114
- return label.capitalize()
 
 
 
 
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()