Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,6 +47,21 @@ def predict_dog_breed(image):
|
|
| 47 |
img_array = preprocess_image(image)
|
| 48 |
predictions = model.predict(img_array)
|
| 49 |
class_idx = np.argmax(predictions) # Get index of the class with the highest probability
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
breed = class_labels[class_idx] # Map the index to the breed name
|
| 51 |
confidence = predictions[0][class_idx] # Confidence score
|
| 52 |
return [breed, confidence] # Return as a list
|
|
|
|
| 47 |
img_array = preprocess_image(image)
|
| 48 |
predictions = model.predict(img_array)
|
| 49 |
class_idx = np.argmax(predictions) # Get index of the class with the highest probability
|
| 50 |
+
|
| 51 |
+
# Ensure that class_idx is within the range of class_labels
|
| 52 |
+
if class_idx < len(class_labels):
|
| 53 |
+
breed = class_labels[class_idx] # Map the index to the breed name
|
| 54 |
+
confidence = predictions[0][class_idx] # Confidence score
|
| 55 |
+
return [breed, confidence] # Return as a list
|
| 56 |
+
else:
|
| 57 |
+
return ["Error", "Invalid model output"]
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def old_predict_dog_breed(image):
|
| 62 |
+
img_array = preprocess_image(image)
|
| 63 |
+
predictions = model.predict(img_array)
|
| 64 |
+
class_idx = np.argmax(predictions) # Get index of the class with the highest probability
|
| 65 |
breed = class_labels[class_idx] # Map the index to the breed name
|
| 66 |
confidence = predictions[0][class_idx] # Confidence score
|
| 67 |
return [breed, confidence] # Return as a list
|