Aum123 commited on
Commit
58a1fa8
Β·
verified Β·
1 Parent(s): 05afcd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
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
- result = classifier(image)
10
- top_result = result[0]
11
- return f"{top_result['label']} ({round(top_result['score'] * 100, 2)}%)"
 
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 breed!
33
- Powered by πŸ€— Hugging Face Transformers and a custom fine-tuned model.
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", shape=(300, 300))
39
- output = gr.Textbox(label="🎯 Predicted Breed", interactive=False)
 
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
- image_input.change(fn=predict, inputs=image_input, outputs=output)
 
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()