duyduong9htv commited on
Commit
4d9f8c5
1 Parent(s): f0b04b8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import ViTImageProcessor, ViTForImageClassification
2
+ import torch
3
+ import gradio as gr
4
+
5
+ feature_extractor = ViTImageProcessor.from_pretrained("car_scene_model")
6
+ model = ViTForImageClassification.from_pretrained("car_scene_model")
7
+
8
+ labels = ['Exterior', 'Interior', 'Unknown']
9
+
10
+ def classify(im):
11
+ features = feature_extractor(im, return_tensors='pt')
12
+ logits = model(features["pixel_values"])[-1]
13
+ probability = torch.nn.functional.softmax(logits, dim=-1)
14
+ probs = probability[0].detach().numpy()
15
+ confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
16
+ return confidences
17
+
18
+
19
+ description = """
20
+ Car scene recognition demo
21
+ """
22
+ interface = gr.Interface(fn=classify,
23
+ inputs="image",
24
+ outputs="label",
25
+ title="Car scene recognition)",
26
+ description=description )
27
+
28
+ interface.launch()