Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,11 +4,12 @@ from transformers import pipeline
|
|
| 4 |
# Load your Hugging Face model
|
| 5 |
classifier = pipeline("image-classification", model="dima806/cat_breed_image_detection")
|
| 6 |
|
| 7 |
-
# Function to predict from uploaded image
|
| 8 |
def predict(image):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
# All cat breeds detected by the model
|
| 14 |
cat_breeds = [
|
|
@@ -29,14 +30,15 @@ breed_list = "\n".join(cat_breeds)
|
|
| 29 |
with gr.Blocks(theme="soft") as demo:
|
| 30 |
gr.Markdown("""
|
| 31 |
# πΎ Cat Breed Detector
|
| 32 |
-
Upload a picture of your cat, and let AI tell you its
|
| 33 |
-
Powered by π€ Hugging Face Transformers and a
|
| 34 |
""")
|
| 35 |
|
| 36 |
with gr.Row(equal_height=True):
|
| 37 |
with gr.Column(scale=1):
|
| 38 |
-
image_input = gr.Image(type="pil", label="πΈ Upload a Cat Image"
|
| 39 |
-
|
|
|
|
| 40 |
with gr.Column(scale=1):
|
| 41 |
gr.Markdown("### π± All Supported Cat Breeds")
|
| 42 |
gr.Textbox(value=breed_list, label="", lines=25, interactive=False, max_lines=25, show_copy_button=True)
|
|
@@ -44,6 +46,7 @@ with gr.Blocks(theme="soft") as demo:
|
|
| 44 |
gr.Markdown("---")
|
| 45 |
gr.Markdown("Made with β€οΈ by Sumon Banerjee β’ Model: `dima806/cat_breed_image_detection`")
|
| 46 |
|
| 47 |
-
|
|
|
|
| 48 |
|
| 49 |
demo.launch()
|
|
|
|
| 4 |
# Load your Hugging Face model
|
| 5 |
classifier = pipeline("image-classification", model="dima806/cat_breed_image_detection")
|
| 6 |
|
| 7 |
+
# Function to predict top 3 cat breeds from uploaded image
|
| 8 |
def predict(image):
|
| 9 |
+
results = classifier(image)
|
| 10 |
+
top3 = results[:3]
|
| 11 |
+
formatted = [f"{i+1}. {res['label']} ({round(res['score'] * 100, 2)}%)" for i, res in enumerate(top3)]
|
| 12 |
+
return "\n".join(formatted)
|
| 13 |
|
| 14 |
# All cat breeds detected by the model
|
| 15 |
cat_breeds = [
|
|
|
|
| 30 |
with gr.Blocks(theme="soft") as demo:
|
| 31 |
gr.Markdown("""
|
| 32 |
# πΎ Cat Breed Detector
|
| 33 |
+
Upload a picture of your cat, and let AI tell you its top 3 possible breeds!
|
| 34 |
+
Powered by π€ Hugging Face Transformers and a fine-tuned model.
|
| 35 |
""")
|
| 36 |
|
| 37 |
with gr.Row(equal_height=True):
|
| 38 |
with gr.Column(scale=1):
|
| 39 |
+
image_input = gr.Image(type="pil", label="πΈ Upload a Cat Image")
|
| 40 |
+
predict_button = gr.Button("π Detect Breed")
|
| 41 |
+
output = gr.Textbox(label="π― Top 3 Predicted Breeds", interactive=False)
|
| 42 |
with gr.Column(scale=1):
|
| 43 |
gr.Markdown("### π± All Supported Cat Breeds")
|
| 44 |
gr.Textbox(value=breed_list, label="", lines=25, interactive=False, max_lines=25, show_copy_button=True)
|
|
|
|
| 46 |
gr.Markdown("---")
|
| 47 |
gr.Markdown("Made with β€οΈ by Sumon Banerjee β’ Model: `dima806/cat_breed_image_detection`")
|
| 48 |
|
| 49 |
+
# Loading spinner while processing
|
| 50 |
+
predict_button.click(fn=predict, inputs=image_input, outputs=output)
|
| 51 |
|
| 52 |
demo.launch()
|