Spaces:
Sleeping
Sleeping
Commit
·
8b3e556
1
Parent(s):
4b6071c
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,36 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import ViTImageProcessor, ViTForImageClassification
|
2 |
+
import torch
|
3 |
import gradio as gr
|
4 |
|
5 |
+
feature_extractor = ViTImageProcessor.from_pretrained("model_artifacts")
|
6 |
+
model = ViTForImageClassification.from_pretrained("model_artifacts")
|
7 |
|
8 |
+
labels = ['Chevrolet Equinox',
|
9 |
+
'Chevrolet Silverado 1500',
|
10 |
+
'Ford Escape',
|
11 |
+
'Ford Explorer',
|
12 |
+
'Ford F-150',
|
13 |
+
'GMC Sierra 1500',
|
14 |
+
'Honda CR-V',
|
15 |
+
'Jeep Compass',
|
16 |
+
'Jeep Grand Cherokee',
|
17 |
+
'Jeep Wrangler',
|
18 |
+
'Mazda CX-5',
|
19 |
+
'Nissan Rogue',
|
20 |
+
'RAM 1500',
|
21 |
+
'RAM 2500',
|
22 |
+
'Toyota Camry']
|
23 |
|
24 |
+
def classify(im):
|
25 |
+
features = feature_extractor(im, return_tensors='pt')
|
26 |
+
logits = model(features["pixel_values"])[-1]
|
27 |
+
probability = torch.nn.functional.softmax(logits, dim=-1)
|
28 |
+
probs = probability[0].detach().numpy()
|
29 |
+
confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
|
30 |
+
return confidences
|
31 |
+
|
32 |
+
|
33 |
+
description = "Simple car recognition model"
|
34 |
+
interface = gr.Interface(fn=classify, inputs="image", outputs="label", title="Car classification demo :)", description=description )
|
35 |
+
|
36 |
+
interface.launch(debug=True)
|