Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,7 @@ def predict_image(image):
|
|
19 |
image.save(image_bytes, format="JPEG")
|
20 |
|
21 |
# Load the image from the file-like object
|
22 |
-
image = tf.keras.preprocessing.image.load_img(image_bytes, target_size=(256, 256))
|
23 |
image = np.array(image)/255
|
24 |
image = np.expand_dims(image, axis=0)
|
25 |
|
@@ -29,12 +29,12 @@ def predict_image(image):
|
|
29 |
# Get the probability of being 'Clean' or 'Carries'
|
30 |
probabilities = tf.nn.softmax(prediction, axis=-1)
|
31 |
predicted_class_index = np.argmax(probabilities)
|
32 |
-
if predicted_class_index ==
|
33 |
predicted_label = "Clean"
|
34 |
-
|
35 |
-
|
36 |
predicted_label = "Carries"
|
37 |
-
|
38 |
|
39 |
# Return the prediction result as a dictionary
|
40 |
return {"Predicted Label": predicted_label}
|
|
|
19 |
image.save(image_bytes, format="JPEG")
|
20 |
|
21 |
# Load the image from the file-like object
|
22 |
+
image = tf.keras.preprocessing.image.load_img(image_bytes, target_size=(256, 256,3))
|
23 |
image = np.array(image)/255
|
24 |
image = np.expand_dims(image, axis=0)
|
25 |
|
|
|
29 |
# Get the probability of being 'Clean' or 'Carries'
|
30 |
probabilities = tf.nn.softmax(prediction, axis=-1)
|
31 |
predicted_class_index = np.argmax(probabilities)
|
32 |
+
if predicted_class_index == 1:
|
33 |
predicted_label = "Clean"
|
34 |
+
predicted_probability = probabilities[0][1] * 100 # Convert to percentage
|
35 |
+
elif predicted_class_index == 0:
|
36 |
predicted_label = "Carries"
|
37 |
+
predicted_probability = probabilities[0][0] * 100 # Convert to percentage
|
38 |
|
39 |
# Return the prediction result as a dictionary
|
40 |
return {"Predicted Label": predicted_label}
|