gschurck's picture
Update app.py
ea61d30 verified
raw
history blame
845 Bytes
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()