barabum commited on
Commit
5651d98
·
1 Parent(s): 84d9935
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy
2
+ from sentence_transformers import SentenceTransformer, util
3
+ from PIL import Image
4
+
5
+
6
+ model = SentenceTransformer('clip-ViT-B-32')
7
+
8
+ def image_classifier(im1: numpy.ndarray, im2: numpy.ndarray):
9
+ encoded_image = model.encode([Image.fromarray(im1), Image.fromarray(im2)], batch_size=128,
10
+ convert_to_tensor=True, show_progress_bar=True)
11
+ processed_images = util.paraphrase_mining_embeddings(encoded_image)
12
+ return processed_images[0][0]
13
+
14
+
15
+
16
+ with gr.Blocks() as b:
17
+ with gr.Row():
18
+ with gr.Column():
19
+ image1 = gr.Image(label="image 1")
20
+ image2 = gr.Image(label="image 2")
21
+ with gr.Row():
22
+ compare = gr.Button("Compare")
23
+ output = gr.Label(label="output")
24
+ compare.click(fn=image_classifier, inputs=[image1, image2], outputs=output)
25
+
26
+
27
+ b.launch()