Aum123's picture
Update app.py
13c5030 verified
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()