image-embedding / app.py
devan019's picture
Update app.py
c60ae80 verified
raw
history blame
882 Bytes
from sentence_transformers import SentenceTransformer
import gradio as gr
# Load once
image_model = SentenceTransformer("clip-ViT-B-32")
text_model = SentenceTransformer("clip-ViT-B-32-multilingual-v1")
def get_image_embedding(image):
emb = image_model.encode(image)
return {"embedding": emb.tolist()}
def get_text_embedding(text):
emb = text_model.encode(text)
return {"embedding": emb.tolist()}
with gr.Blocks() as demo:
with gr.Tab("Image Embedding"):
img_input = gr.Image(type="pil")
img_output = gr.JSON()
img_btn = gr.Button("Generate")
img_btn.click(get_image_embedding, img_input, img_output)
with gr.Tab("Text Embedding"):
text_input = gr.Textbox()
text_output = gr.JSON()
text_btn = gr.Button("Generate")
text_btn.click(get_text_embedding, text_input, text_output)
demo.launch()