Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,13 @@ model = AutoModelForImageClassification.from_pretrained("google/vit-base-patch16
|
|
| 7 |
extractor = AutoFeatureExtractor.from_pretrained("google/vit-base-patch16-224")
|
| 8 |
|
| 9 |
# Define label map BEFORE using it
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def predict(image):
|
| 13 |
inputs = extractor(images=image, return_tensors="pt")
|
|
|
|
| 7 |
extractor = AutoFeatureExtractor.from_pretrained("google/vit-base-patch16-224")
|
| 8 |
|
| 9 |
# Define label map BEFORE using it
|
| 10 |
+
import json
|
| 11 |
+
import requests
|
| 12 |
+
|
| 13 |
+
# Load official ImageNet-1k labels
|
| 14 |
+
imagenet_url = "https://huggingface.co/datasets/imagenet-1k/resolve/main/labels.json"
|
| 15 |
+
id2label = requests.get(imagenet_url).json()
|
| 16 |
+
|
| 17 |
|
| 18 |
def predict(image):
|
| 19 |
inputs = extractor(images=image, return_tensors="pt")
|