omar87 commited on
Commit
535b225
·
1 Parent(s): f6e5d83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -24,26 +24,31 @@ def compute_similarity(target_image, image_list):
24
 
25
 
26
  # Function to handle the Gradio interface
27
- def image_similarity(target_image, image_list):
28
  target_image = target_image.astype(np.uint8)
29
- image_list = [image.astype(np.uint8) for image in image_list]
30
- scores = compute_similarity(target_image, image_list)
31
- results = list(zip(image_list, scores))
32
- results.sort(key=lambda x: x[1], reverse=True) # Sort by similarity score
33
- formatted_results = [(str(image.tolist()), f"Score: {score:.4f}") for image, score in results]
34
- return formatted_results
35
 
36
  # Prepare Gradio interface
37
  iface = gr.Interface(
38
  fn=image_similarity,
39
  inputs=[
40
  gr.inputs.Image(type="numpy", label="Target Image"),
41
- gr.inputs.Image(type="numpy", label="Image List")
42
  ],
43
  outputs="text",
44
  title="Image Similarity Calculator",
45
- description="Upload an image and a list of images. Get similarity scores."
46
  )
47
 
48
  # Launch the interface
49
- iface.launch()
 
 
 
 
 
 
 
 
24
 
25
 
26
  # Function to handle the Gradio interface
27
+ def image_similarity(target_image, image):
28
  target_image = target_image.astype(np.uint8)
29
+ image = image.astype(np.uint8)
30
+ scores = compute_similarity(target_image, [image])
31
+ result = (str(image.tolist()), f"Score: {scores[0]:.4f}")
32
+ return [result]
 
 
33
 
34
  # Prepare Gradio interface
35
  iface = gr.Interface(
36
  fn=image_similarity,
37
  inputs=[
38
  gr.inputs.Image(type="numpy", label="Target Image"),
39
+ gr.inputs.Image(type="numpy", label="Image")
40
  ],
41
  outputs="text",
42
  title="Image Similarity Calculator",
43
+ description="Upload a target image and another image. Get the similarity score."
44
  )
45
 
46
  # Launch the interface
47
+ iface.launch()
48
+
49
+
50
+
51
+
52
+
53
+
54
+