gschurck commited on
Commit
ae0811f
·
verified ·
1 Parent(s): 467bd19

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sentence_transformers import SentenceTransformer, util
2
+ from PIL import Image
3
+ import gradio as gr
4
+ import requests
5
+
6
+ def get_image_embedding(image):
7
+ image_model = SentenceTransformer('clip-ViT-B-32')
8
+ img_emb = image_model.encode(image)
9
+ return {"embedding": img_emb.tolist()}
10
+
11
+ def get_text_embedding(text):
12
+ multilingual_text_model = SentenceTransformer('gte-Qwen2-1.5B-instruct')
13
+ text_emb = multilingual_text_model.encode(text)
14
+ print(text_emb)
15
+ print(type(text_emb))
16
+ print(text_emb.ndim)
17
+ return {"embedding": text_emb.tolist()}
18
+
19
+ image_embedding = gr.Interface(fn=get_image_embedding, inputs=gr.Image(type="pil"), outputs=gr.JSON(api_name="image-embedding"), title="Image Embedding")
20
+ text_embedding = gr.Interface(fn=get_text_embedding, inputs=gr.Textbox(), outputs=gr.JSON(api_name="text-embedding"), title="Text Embedding")
21
+
22
+ space = gr.TabbedInterface([image_embedding, text_embedding], ["Image Embedding", "Text Embedding"])
23
+ space.launch()