Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,16 +16,16 @@ model = tf.keras.models.load_model("cat_breed_model.keras")
|
|
| 16 |
def predict(image: Image.Image):
|
| 17 |
try:
|
| 18 |
if image is None:
|
| 19 |
-
return
|
| 20 |
img = image.resize((224, 224)).convert("RGB")
|
| 21 |
x = np.array(img) / 255.0
|
| 22 |
x = np.expand_dims(x, axis=0)
|
| 23 |
preds = model.predict(x)[0] # shape: (12,)
|
| 24 |
result = {breed: float(conf) for breed, conf in zip(SUPPORTED_BREEDS, preds)}
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
iface = gr.Interface(
|
| 31 |
fn=predict,
|
|
@@ -36,19 +36,21 @@ iface = gr.Interface(
|
|
| 36 |
article="""
|
| 37 |
⚠️ **Note:** This model will always predict one of the 12 cat breeds, even for non-cat images. For best results, upload a clear image of a cat.
|
| 38 |
|
| 39 |
-
**
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
-
|
| 43 |
-
-
|
| 44 |
-
-
|
| 45 |
-
-
|
| 46 |
-
-
|
| 47 |
-
-
|
| 48 |
-
-
|
| 49 |
-
-
|
| 50 |
-
-
|
| 51 |
-
-
|
|
|
|
|
|
|
| 52 |
|
| 53 |
*Please upload a clear image of a cat belonging to one of these breeds for best results.*
|
| 54 |
"""
|
|
|
|
| 16 |
def predict(image: Image.Image):
|
| 17 |
try:
|
| 18 |
if image is None:
|
| 19 |
+
return {breed: 0.0 for breed in SUPPORTED_BREEDS}
|
| 20 |
img = image.resize((224, 224)).convert("RGB")
|
| 21 |
x = np.array(img) / 255.0
|
| 22 |
x = np.expand_dims(x, axis=0)
|
| 23 |
preds = model.predict(x)[0] # shape: (12,)
|
| 24 |
result = {breed: float(conf) for breed, conf in zip(SUPPORTED_BREEDS, preds)}
|
| 25 |
+
return result
|
| 26 |
+
except Exception as e:
|
| 27 |
+
print(f"Prediction error: {e}")
|
| 28 |
+
return {breed: 0.0 for breed in SUPPORTED_BREEDS}
|
| 29 |
|
| 30 |
iface = gr.Interface(
|
| 31 |
fn=predict,
|
|
|
|
| 36 |
article="""
|
| 37 |
⚠️ **Note:** This model will always predict one of the 12 cat breeds, even for non-cat images. For best results, upload a clear image of a cat.
|
| 38 |
|
| 39 |
+
**Note:**
|
| 40 |
+
This project can detect only the following 12 cat breeds:
|
| 41 |
+
|
| 42 |
+
- Abyssinian
|
| 43 |
+
- Bengal
|
| 44 |
+
- Birman
|
| 45 |
+
- Bombay
|
| 46 |
+
- British Shorthair
|
| 47 |
+
- Egyptian Mau
|
| 48 |
+
- Maine Coon
|
| 49 |
+
- Persian
|
| 50 |
+
- Ragdoll
|
| 51 |
+
- Russian Blue
|
| 52 |
+
- Siamese
|
| 53 |
+
- Sphynx
|
| 54 |
|
| 55 |
*Please upload a clear image of a cat belonging to one of these breeds for best results.*
|
| 56 |
"""
|