Spaces:
Sleeping
Sleeping
zhaoyuyoung
commited on
Commit
•
bcd1aed
1
Parent(s):
2b8a6d8
Update app.py
Browse files
app.py
CHANGED
@@ -7,5 +7,15 @@ labels = ['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips']
|
|
7 |
|
8 |
def classify_image(image):
|
9 |
model = AutoModelForImageClassification.from_pretrained(model_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
examples=['flower-1.jpeg', 'flower-2.jpeg'],
|
11 |
outputs='label').launch()
|
|
|
7 |
|
8 |
def classify_image(image):
|
9 |
model = AutoModelForImageClassification.from_pretrained(model_id)
|
10 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(model_id)
|
11 |
+
inp = feature_extractor(image, return_tensors='pt')
|
12 |
+
outp = model(**inp)
|
13 |
+
pred = torch.nn.functional.softmax(outp.logits, dim=-1)
|
14 |
+
preds = pred[0].cpu().detach().numpy()
|
15 |
+
confidence = {label: float(preds[i]) for i, label in enumerate(labels)}
|
16 |
+
return confidence
|
17 |
+
|
18 |
+
interface = gr.Interface(fn=classify_image,
|
19 |
+
inputs='image',
|
20 |
examples=['flower-1.jpeg', 'flower-2.jpeg'],
|
21 |
outputs='label').launch()
|