shkumar156 commited on
Commit
52b4bf7
·
verified ·
1 Parent(s): 04c948b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -18
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 gr.Error("Please upload the right image from the given breeds list.")
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
- top_breed = max(result, key=result.get)
26
- top_confidence = result[top_breed]
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
- **Supported Breeds:**
40
- - Abyssinian
41
- - Bengal
42
- - Birman
43
- - Bombay
44
- - British Shorthair
45
- - Egyptian Mau
46
- - Maine Coon
47
- - Persian
48
- - Ragdoll
49
- - Russian Blue
50
- - Siamese
51
- - Sphynx
 
 
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
  """