Dgv2 commited on
Commit
6e488f9
·
verified ·
1 Parent(s): edda2b1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoImageProcessor, AutoModelForImageClassification
2
+ from PIL import Image
3
+ import torch
4
+ import gradio as gr
5
+
6
+ image_processor = AutoImageProcessor.from_pretrained("wesleyacheng/dog-breeds-multiclass-image-classification-with-vit")
7
+ model = AutoModelForImageClassification.from_pretrained("wesleyacheng/dog-breeds-multiclass-image-classification-with-vit")
8
+
9
+ def classify_dog(image):
10
+ inputs = image_processor(images=image, return_tensors="pt")
11
+ with torch.no_grad():
12
+ outputs = model(**inputs)
13
+ logits = outputs.logits
14
+ predicted_class_idx = logits.argmax(-1).item()
15
+ predicted_breed = model.config.id2label[predicted_class_idx]
16
+ return f"Predicted Dog Breed: {predicted_breed}"
17
+
18
+ demo = gr.Interface(
19
+ fn=classify_dog,
20
+ inputs=gr.Image(type="pil"),
21
+ outputs="text",
22
+ title="Dog Breed Classifier",
23
+ description="Upload an image of a dog and the model will classify its breed (120 breeds supported)."
24
+ )
25
+
26
+ demo.launch()