Spaces:
Runtime error
Runtime error
Upload plip_support.py
Browse files- plip_support.py +9 -0
plip_support.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import clip
|
2 |
+
import torch
|
3 |
+
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
def embed_text(plip, text, device="cpu"):
|
8 |
+
idx = clip.tokenize([text], truncate=True).to(device)
|
9 |
+
return plip.encode_text(idx).detach().cpu().numpy()[0]
|