Spaces:
Runtime error
Runtime error
| 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() |