Spaces:
Sleeping
Sleeping
from transformers import AutoModel | |
from PIL import Image | |
import requests | |
from io import BytesIO | |
# Load model | |
model = AutoModel.from_pretrained('jinaai/jina-clip-v2', trust_remote_code=True) | |
def get_text_embedding(texts, truncate_dim=512): | |
return model.encode_text(texts, truncate_dim=truncate_dim).tolist() | |
def get_image_embedding(image_sources, truncate_dim=512): | |
processed_images = [] | |
for src in image_sources: | |
if src.startswith('http'): | |
response = requests.get(src) | |
img = Image.open(BytesIO(response.content)).convert('RGB') | |
processed_images.append(img) | |
return model.encode_image(processed_images, truncate_dim=truncate_dim).tolist() | |