Update app.py
Browse files
app.py
CHANGED
@@ -62,9 +62,9 @@ class_labels = ['battery',
|
|
62 |
'trash',
|
63 |
'white-glass']
|
64 |
|
65 |
-
def predict_image(
|
66 |
# Resize the image to the size expected by the model
|
67 |
-
image =
|
68 |
# Convert the image to a NumPy array
|
69 |
image_array = tf.keras.preprocessing.image.img_to_array(image)
|
70 |
# Normalize the image
|
@@ -73,16 +73,13 @@ def predict_image(input):
|
|
73 |
image_array = tf.expand_dims(image_array, 0)
|
74 |
# Predict using the model
|
75 |
predictions = model1.predict(image_array)
|
|
|
|
|
|
|
|
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
predicted_class_label = class_labels[predicted_class_index]
|
80 |
-
|
81 |
-
# Get the confidence score of the predicted class
|
82 |
-
confidence_score = predictions[0][predicted_class_index]
|
83 |
-
|
84 |
-
# Return predicted class label and confidence score
|
85 |
-
return {predicted_class_label: confidence_score}
|
86 |
|
87 |
image_gradio_app = gr.Interface(
|
88 |
fn=predict_image,
|
|
|
62 |
'trash',
|
63 |
'white-glass']
|
64 |
|
65 |
+
def predict_image(image_input):
|
66 |
# Resize the image to the size expected by the model
|
67 |
+
image = image_input.resize((244, 224))
|
68 |
# Convert the image to a NumPy array
|
69 |
image_array = tf.keras.preprocessing.image.img_to_array(image)
|
70 |
# Normalize the image
|
|
|
73 |
image_array = tf.expand_dims(image_array, 0)
|
74 |
# Predict using the model
|
75 |
predictions = model1.predict(image_array)
|
76 |
+
|
77 |
+
category_scores = {}
|
78 |
+
for i, class_label in enumerate(class_labels):
|
79 |
+
category_scores[class_label] = predictions[0][i].item()
|
80 |
|
81 |
+
return category_scores
|
82 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
image_gradio_app = gr.Interface(
|
85 |
fn=predict_image,
|