File size: 846 Bytes
719ed90
ae0811f
 
 
 
 
719ed90
ae0811f
 
719ed90
 
 
 
 
 
ae0811f
9eab4da
 
ae0811f
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from sentence_transformers import SentenceTransformer, util
from PIL import Image
import gradio as gr
import requests

def get_image_embedding(image):
    return {"embedding": "img_emb.tolist()")}

def get_text_embedding(text):
    multilingual_text_model = SentenceTransformer('Alibaba-NLP/gte-Qwen2-1.5B-instruct')
    text_emb = multilingual_text_model.encode(text)
    print(text_emb)
    print(type(text_emb))
    print(text_emb.ndim)
    return {"embedding": text_emb.tolist()}

image_embedding = gr.Interface(fn=get_image_embedding, inputs=gr.Image(type="pil"), outputs=gr.JSON(), title="Image Embedding")
text_embedding = gr.Interface(fn=get_text_embedding, inputs=gr.Textbox(), outputs=gr.JSON(), title="Text Embedding")

space = gr.TabbedInterface([image_embedding, text_embedding], ["Image Embedding", "Text Embedding"])
space.launch()