Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sentence_transformers import SentenceTransformer, util
|
| 2 |
+
from PIL import Image
|
| 3 |
+
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
+
def get_image_embedding(image):
|
| 7 |
+
image_model = SentenceTransformer('clip-ViT-B-32')
|
| 8 |
+
|
| 9 |
+
# Load and preprocess the image
|
| 10 |
+
image = Image.open(BytesIO(image))
|
| 11 |
+
img_emb = image_model.encode(image)
|
| 12 |
+
|
| 13 |
+
return {"prediction": img_emb}
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
image_input = gr.inputs.Image()
|
| 17 |
+
label_output = gr.outputs.Label()
|
| 18 |
+
|
| 19 |
+
gr.Interface(fn=get_image_embedding, inputs=image_input, outputs=label_output).launch()
|