Speshal89 commited on
Commit
5296b4e
·
verified ·
1 Parent(s): fc95bd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
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
- id2label = model.config.id2label
 
 
 
 
 
 
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")