File size: 2,248 Bytes
da68fdc
 
 
 
 
 
58a1fa8
da68fdc
58a1fa8
 
 
 
da68fdc
05afcd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58a1fa8
 
05afcd1
 
 
 
58a1fa8
 
 
05afcd1
 
 
 
 
 
58a1fa8
 
05afcd1
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import gradio as gr
from transformers import pipeline

# Load your Hugging Face model
classifier = pipeline("image-classification", model="dima806/cat_breed_image_detection")

# Function to predict top 3 cat breeds from uploaded image
def predict(image):
    results = classifier(image)
    top3 = results[:3]
    formatted = [f"{i+1}. {res['label']} ({round(res['score'] * 100, 2)}%)" for i, res in enumerate(top3)]
    return "\n".join(formatted)

# All cat breeds detected by the model
cat_breeds = [
    "Abyssinian", "American Bobtail", "American Curl", "American Shorthair",
    "Applehead Siamese", "Balinese", "Bengal", "Birman", "Bombay", "British Shorthair",
    "Burmese", "Calico", "Cornish Rex", "Devon Rex", "Dilute Calico", "Dilute Tortoiseshell",
    "Domestic Long Hair", "Domestic Medium Hair", "Domestic Short Hair", "Egyptian Mau",
    "Exotic Shorthair", "Extra-Toes Cat - Hemingway Polydactyl", "Havana", "Himalayan",
    "Japanese Bobtail", "Maine Coon", "Manx", "Munchkin", "Nebelung", "Norwegian Forest",
    "Oriental Short Hair", "Persian", "Ragamuffin", "Ragdoll", "Russian Blue",
    "Scottish Fold", "Siamese", "Siberian", "Snowshoe", "Sphynx", "Tabby", "Tiger",
    "Tonkinese", "Torbie", "Tortoiseshell", "Turkish Angora", "Turkish Van", "Tuxedo"
]

breed_list = "\n".join(cat_breeds)

# Build the UI
with gr.Blocks(theme="soft") as demo:
    gr.Markdown("""
    # 🐾 Cat Breed Detector
    Upload a picture of your cat, and let AI tell you its top 3 possible breeds!  
    Powered by πŸ€— Hugging Face Transformers and a fine-tuned model.
    """)
    
    with gr.Row(equal_height=True):
        with gr.Column(scale=1):
            image_input = gr.Image(type="pil", label="πŸ“Έ Upload a Cat Image")
            predict_button = gr.Button("πŸ” Detect Breed")
            output = gr.Textbox(label="🎯 Top 3 Predicted Breeds", interactive=False)
        with gr.Column(scale=1):
            gr.Markdown("### 🐱 All Supported Cat Breeds")
            gr.Textbox(value=breed_list, label="", lines=25, interactive=False, max_lines=25, show_copy_button=True)

    gr.Markdown("---")

    # Loading spinner while processing
    predict_button.click(fn=predict, inputs=image_input, outputs=output)

demo.launch()