yangapku commited on
Commit
29a378b
1 Parent(s): 87564e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -5,13 +5,18 @@ import numpy as np
5
  from PIL import Image
6
 
7
 
8
- pipe = pipeline("zero-shot-image-classification", model="OFA-Sys/chinese-clip-vit-base-patch16")
 
 
 
 
 
9
  images="festival.jpg"
10
 
11
  def shot(image, labels_text):
12
  PIL_image = Image.fromarray(np.uint8(image)).convert('RGB')
13
  labels = labels_text.split(",")
14
- res = pipe(images=PIL_image,
15
  candidate_labels=labels,
16
  hypothesis_template= "This is a photo of a {}")
17
  return {dic["label"]: dic["score"] for dic in res}
 
5
  from PIL import Image
6
 
7
 
8
+ pipes = {
9
+ "chinese-clip-vit-base-patch16": pipeline("zero-shot-image-classification", model="OFA-Sys/chinese-clip-vit-base-patch16"),
10
+ "chinese-clip-vit-large-patch14": pipeline("zero-shot-image-classification", model="OFA-Sys/chinese-clip-vit-large-patch14"),
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= "This is a photo of a {}")
22
  return {dic["label"]: dic["score"] for dic in res}