Spaces:
Runtime error
Runtime error
NORLIE JHON MALAGDAO
commited on
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
image = gr.Image()
|
135 |
-
label = gr.Label(num_top_classes=
|
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,
|