yangapku commited on
Commit
ceb927d
1 Parent(s): de2e2ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -11,18 +11,27 @@ pipes = {
11
  "chinese-clip-vit-large-patch14-336px": pipeline("zero-shot-image-classification", model="OFA-Sys/chinese-clip-vit-large-patch14-336px"),
12
  "chinese-clip-vit-huge-patch14": pipeline("zero-shot-image-classification", model="OFA-Sys/chinese-clip-vit-huge-patch14"),
13
  }
 
 
 
 
 
 
 
 
 
 
14
  images="festival.jpg"
15
 
16
- def shot(image, labels_text):
17
- PIL_image = Image.fromarray(np.uint8(image)).convert('RGB')
18
- labels = labels_text.split(",")
19
- res = pipes['chinese-clip-vit-base-patch16'](images=PIL_image,
20
  candidate_labels=labels,
21
  hypothesis_template= "一张{}的图片。")
22
  return {dic["label"]: dic["score"] for dic in res}
23
-
24
  iface = gr.Interface(shot,
25
- ["image", "text"],
26
  "label",
27
  examples=[["festival.jpg", "灯笼, 鞭炮, 对联"],
28
  ["cat-dog-music.png", "音乐表演, 体育运动"],
 
11
  "chinese-clip-vit-large-patch14-336px": pipeline("zero-shot-image-classification", model="OFA-Sys/chinese-clip-vit-large-patch14-336px"),
12
  "chinese-clip-vit-huge-patch14": pipeline("zero-shot-image-classification", model="OFA-Sys/chinese-clip-vit-huge-patch14"),
13
  }
14
+ inputs = [
15
+ gr.inputs.Image(type='pil'),
16
+ "text",
17
+ gr.inputs.Radio(choices=[
18
+ "chinese-clip-vit-base-patch16",
19
+ "chinese-clip-vit-large-patch14",
20
+ "chinese-clip-vit-large-patch14-336px",
21
+ "chinese-clip-vit-huge-patch14",
22
+ ], type="value", default="chinese-clip-vit-base-patch16", label="Model"),
23
+ ]
24
  images="festival.jpg"
25
 
26
+ def shot(image, labels_text, model_name):
27
+ labels = labels_text.split(",").strip(" ")
28
+ res = pipes[model_name](images=image,
 
29
  candidate_labels=labels,
30
  hypothesis_template= "一张{}的图片。")
31
  return {dic["label"]: dic["score"] for dic in res}
32
+
33
  iface = gr.Interface(shot,
34
+ inputs,
35
  "label",
36
  examples=[["festival.jpg", "灯笼, 鞭炮, 对联"],
37
  ["cat-dog-music.png", "音乐表演, 体育运动"],