Imran1 commited on
Commit
ed0c610
1 Parent(s): d2f5d55

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from PIL import Image
4
+ import requests
5
+
6
+ from transformers import pipeline
7
+
8
+ checkpoint = "openai/clip-vit-large-patch14"
9
+ detector = pipeline(model=checkpoint, task="zero-shot-image-classification")
10
+ # Function to predict dog category
11
+ def predict_dog_category(image):
12
+ # List of dog categories
13
+ dog_category = [
14
+ 'Siberian Husky', 'Boxer', # Working Dogs
15
+ 'Border Collie', 'Australian Shepherd', # Herding Dogs
16
+ 'Chihuahua', 'Pomeranian', # Toy Dogs
17
+ 'Labrador Retriever', 'Golden Retriever', # Sporting Dogs
18
+ 'Yorkshire Terrier', 'Bull Terrier', # Terriers
19
+ 'Bulldog', 'Poodle' # Non-Sporting Dogs
20
+ ]
21
+
22
+ # Use CLIP model to predict dog category
23
+ predictions = detector(image, candidate_labels=dog_category)
24
+ return {predictions[i]['label']: float(predictions[i]['score']) for i in range(len(predictions))}
25
+
26
+ # Create Gradio interface
27
+ iface = gr.Interface(
28
+ fn=predict_dog_category,
29
+ inputs=gr.Image(type="pil"),
30
+ outputs=gr.Label(num_top_classes=12)
31
+ )
32
+ iface.launch(share=True)