Aum123's picture
Update app.py
05afcd1 verified
raw
history blame
2.17 kB
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 from uploaded image
def predict(image):
result = classifier(image)
top_result = result[0]
return f"{top_result['label']} ({round(top_result['score'] * 100, 2)}%)"
# 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 breed!
Powered by πŸ€— Hugging Face Transformers and a custom 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", shape=(300, 300))
output = gr.Textbox(label="🎯 Predicted Breed", 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("---")
gr.Markdown("Made with ❀️ by Sumon Banerjee β€’ Model: `dima806/cat_breed_image_detection`")
image_input.change(fn=predict, inputs=image_input, outputs=output)
demo.launch()