Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import torch
|
|
3 |
from transformers import AutoProcessor, CLIPModel
|
4 |
|
5 |
clip_path = "openai/clip-vit-base-patch32"
|
6 |
-
model = CLIPModel.from_pretrained(clip_path)
|
7 |
processor = AutoProcessor.from_pretrained(clip_path)
|
8 |
|
9 |
|
@@ -13,18 +13,17 @@ async def predict(init_image, labels_level1):
|
|
13 |
|
14 |
split_labels = labels_level1.split(",")
|
15 |
ret_str = ""
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
text=split_labels, images=init_image, return_tensors="pt", padding=True
|
20 |
-
)
|
21 |
|
22 |
-
outputs = model(**inputs)
|
23 |
-
logits_per_image = outputs.logits_per_image # this is the image-text similarity score
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
ret_str += split_labels[i] + ": " + str(logits_per_image[0][i]) + "\n"
|
28 |
|
29 |
return ret_str, ret_str
|
30 |
|
|
|
3 |
from transformers import AutoProcessor, CLIPModel
|
4 |
|
5 |
clip_path = "openai/clip-vit-base-patch32"
|
6 |
+
model = CLIPModel.from_pretrained(clip_path).eval()
|
7 |
processor = AutoProcessor.from_pretrained(clip_path)
|
8 |
|
9 |
|
|
|
13 |
|
14 |
split_labels = labels_level1.split(",")
|
15 |
ret_str = ""
|
16 |
+
|
17 |
+
inputs = processor(
|
18 |
+
text=split_labels, images=init_image, return_tensors="pt", padding=True
|
19 |
+
)
|
20 |
|
21 |
+
outputs = model(**inputs)
|
22 |
+
logits_per_image = outputs.logits_per_image # this is the image-text similarity score
|
|
|
|
|
23 |
|
|
|
|
|
24 |
|
25 |
+
for i in range(len(split_labels)):
|
26 |
+
ret_str += split_labels[i] + ": " + str(logits_per_image[0][i]) + "\n"
|
|
|
27 |
|
28 |
return ret_str, ret_str
|
29 |
|