duyduong9htv commited on
Commit
9104de2
1 Parent(s): 930daeb

Upload 5 files

Browse files
Files changed (4) hide show
  1. app.py +35 -0
  2. config.json +32 -0
  3. model.safetensors +3 -0
  4. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoImageProcessor, AutoModelForImageClassification
2
+ import numpy as np
3
+ import evaluate
4
+ import torch
5
+ import gradio as gr
6
+
7
+
8
+ model = AutoModelForImageClassification.from_pretrained('hero_photo_eligibility_model')
9
+ checkpoint = 'google/vit-base-patch16-224'
10
+ image_processor = AutoImageProcessor.from_pretrained(checkpoint)
11
+
12
+ label_names = ['NO', 'YES']
13
+
14
+ def classify(im):
15
+ features = image_processor(im, return_tensors='pt')
16
+ logits = model(features["pixel_values"])[-1]
17
+ probability = torch.nn.functional.softmax(logits, dim=-1)
18
+ probs = probability[0].detach().numpy()
19
+ confidences = {label: float(probs[i]) for i, label in enumerate(label_names)}
20
+ return confidences
21
+
22
+
23
+ title = """Detecting whether a photo is suitable for VDP main photo"""
24
+
25
+ description = """Hero photo eligibility demo"""
26
+
27
+ interface = gr.Interface(
28
+ fn=classify,
29
+ inputs='image',
30
+ outputs='label',
31
+ title=title,
32
+ description=description
33
+ )
34
+
35
+ interface.launch(share=True, debug=True)
config.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "google/vit-base-patch16-224",
3
+ "architectures": [
4
+ "ViTForImageClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.0,
7
+ "encoder_stride": 16,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.0,
10
+ "hidden_size": 768,
11
+ "id2label": {
12
+ "0": "no",
13
+ "1": "yes"
14
+ },
15
+ "image_size": 224,
16
+ "initializer_range": 0.02,
17
+ "intermediate_size": 3072,
18
+ "label2id": {
19
+ "no": "0",
20
+ "yes": "1"
21
+ },
22
+ "layer_norm_eps": 1e-12,
23
+ "model_type": "vit",
24
+ "num_attention_heads": 12,
25
+ "num_channels": 3,
26
+ "num_hidden_layers": 12,
27
+ "patch_size": 16,
28
+ "problem_type": "single_label_classification",
29
+ "qkv_bias": true,
30
+ "torch_dtype": "float32",
31
+ "transformers_version": "4.36.0"
32
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0a45a8e2ff308e941570a35f01cd01aa527ffa48a14084dcda385427f859e275
3
+ size 343223968
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch
2
+ gradio
3
+ datasets
4
+ transformers