from sentence_transformers import SentenceTransformer, util | |
from PIL import Image | |
from io import BytesIO | |
import gradio as gr | |
import requests | |
def get_image_embedding(image): | |
image_model = SentenceTransformer('clip-ViT-B-32') | |
# Load and preprocess the image | |
img_emb = image_model.encode(image) | |
print(img_emb) | |
print(type(img_emb)) | |
return {"prediction": img_emb.tolist()} | |
image_input = gr.Image(type="pil") | |
label_output = gr.JSON() | |
gr.Interface(fn=get_image_embedding, inputs=image_input, outputs=label_output).launch() | |