NORLIE JHON MALAGDAO commited on
Commit
5d260c9
·
verified ·
1 Parent(s): c0cb430

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -129,10 +129,16 @@ def predict_image(img):
129
  img_resized = tf.image.resize(img, (img_height, img_width))
130
  img_4d = tf.expand_dims(img_resized, axis=0)
131
  prediction = model.predict(img_4d)[0]
132
- return {class_names[i]: float(prediction[i]) for i in range(len(class_names))}
 
 
 
 
 
 
133
 
134
  image = gr.Image()
135
- label = gr.Label(num_top_classes=12)
136
 
137
  gr.Interface(
138
  fn=predict_image,
 
129
  img_resized = tf.image.resize(img, (img_height, img_width))
130
  img_4d = tf.expand_dims(img_resized, axis=0)
131
  prediction = model.predict(img_4d)[0]
132
+ max_index = np.argmax(prediction)
133
+ max_probability = tf.nn.softmax(prediction)[max_index]
134
+
135
+ if max_probability == 1.0:
136
+ return {class_names[max_index]: float(max_probability)}
137
+ else:
138
+ return {"None": "No class with 100% confidence"}
139
 
140
  image = gr.Image()
141
+ label = gr.Label(num_top_classes=1)
142
 
143
  gr.Interface(
144
  fn=predict_image,