shkumar156 commited on
Commit
a32d605
·
verified ·
1 Parent(s): 4da093a

Upload 4 files

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. README.md +48 -13
  3. app.py +36 -0
  4. cat_breed_model.keras +3 -0
  5. requirements.txt +4 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ cat_breed_model.keras filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,13 +1,48 @@
1
- ---
2
- title: Cats Classifier
3
- emoji: 📈
4
- colorFrom: green
5
- colorTo: green
6
- sdk: gradio
7
- sdk_version: 5.36.2
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Cat Breed Classifier 🐱
2
+
3
+ This Hugging Face Space uses a deep learning model to classify cat breeds from images. Upload a photo of a cat, and the app will predict its breed!
4
+
5
+ ## How It Works
6
+ - The app is built with [Gradio](https://gradio.app/) and [TensorFlow](https://www.tensorflow.org/).
7
+ - The model was trained to recognize 12 popular cat breeds.
8
+ - Just upload an image, and you'll get the predicted breed and confidence score.
9
+
10
+ ## Supported Cat Breeds
11
+ - Abyssinian
12
+ - Bengal
13
+ - Birman
14
+ - Bombay
15
+ - British Shorthair
16
+ - Egyptian Mau
17
+ - Maine Coon
18
+ - Persian
19
+ - Ragdoll
20
+ - Russian Blue
21
+ - Siamese
22
+ - Sphynx
23
+
24
+ ## Usage
25
+ 1. Click the **Upload** button and select a cat image (JPG/PNG).
26
+ 2. Wait a moment for the model to process the image.
27
+ 3. View the predicted breed and confidence score.
28
+
29
+ ## API
30
+ You can also use this Space as an API by sending a POST request to the `/run/predict` endpoint with an image file.
31
+
32
+ **Example using `requests` in Python:**
33
+ ```python
34
+ import requests
35
+
36
+ url = "https://<your-username>-<space-name>.hf.space/run/predict"
37
+ files = {"data": ("cat.jpg", open("cat.jpg", "rb"), "image/jpeg")}
38
+ response = requests.post(url, files=files)
39
+ print(response.json())
40
+ ```
41
+
42
+ ## Credits
43
+ - Built with Gradio and TensorFlow
44
+ - Model trained by <your-name-or-team>
45
+
46
+ ---
47
+
48
+ *Replace `<your-username>-<space-name>` with your actual Hugging Face Space URL.*
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # Supported breeds (must match the order in your model's training)
7
+ SUPPORTED_BREEDS = [
8
+ 'Abyssinian', 'Bengal', 'Birman', 'Bombay', 'British_Shorthair',
9
+ 'Egyptian_Mau', 'Maine_Coon', 'Persian', 'Ragdoll', 'Russian_Blue',
10
+ 'Siamese', 'Sphynx'
11
+ ]
12
+
13
+ # Load the model
14
+ model = tf.keras.models.load_model("cat_breed_model.keras")
15
+
16
+ def predict(image: Image.Image):
17
+ # Preprocess image
18
+ img = image.resize((224, 224)).convert("RGB")
19
+ x = np.array(img) / 255.0
20
+ x = np.expand_dims(x, axis=0)
21
+ preds = model.predict(x)
22
+ class_idx = int(np.argmax(preds, axis=-1)[0])
23
+ confidence = float(np.max(preds))
24
+ breed = SUPPORTED_BREEDS[class_idx]
25
+ return {"breed": breed, "confidence": confidence}
26
+
27
+ iface = gr.Interface(
28
+ fn=predict,
29
+ inputs=gr.Image(type="pil"),
30
+ outputs=[gr.Label(num_top_classes=1, label="Predicted Breed")],
31
+ title="Cat Breed Classifier",
32
+ description="Upload a cat image to classify its breed."
33
+ )
34
+
35
+ if __name__ == "__main__":
36
+ iface.launch()
cat_breed_model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8bc5e1fe004b91b20bb2cc86c837b8bedec6066ee9ee26844f98bd10a7c42a54
3
+ size 11609076
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ tensorflow
3
+ pillow
4
+ numpy