Update app.py
Browse files
app.py
CHANGED
@@ -24,19 +24,24 @@ def compute_similarity(target_image, image_list):
|
|
24 |
|
25 |
|
26 |
# Function to handle the Gradio interface
|
27 |
-
|
|
|
28 |
target_image = target_image.astype(np.uint8)
|
29 |
-
|
30 |
-
scores = compute_similarity(target_image,
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
33 |
|
34 |
# Function to format the image representation as a string
|
35 |
def format_image(image):
|
36 |
formatted_image = ""
|
37 |
for row in image:
|
38 |
-
formatted_row = ", ".join([f"
|
39 |
-
formatted_image += f"[{formatted_row}]
|
40 |
return formatted_image[:-2]
|
41 |
|
42 |
# Prepare Gradio interface
|
@@ -44,11 +49,11 @@ iface = gr.Interface(
|
|
44 |
fn=image_similarity,
|
45 |
inputs=[
|
46 |
gr.inputs.Image(type="numpy", label="Target Image"),
|
47 |
-
gr.inputs.Image(type="numpy", label="Image")
|
48 |
],
|
49 |
outputs="text",
|
50 |
title="Image Similarity Calculator",
|
51 |
-
description="Upload a target image and
|
52 |
)
|
53 |
|
54 |
# Launch the interface
|
@@ -60,3 +65,4 @@ iface.launch()
|
|
60 |
|
61 |
|
62 |
|
|
|
|
24 |
|
25 |
|
26 |
# Function to handle the Gradio interface
|
27 |
+
# Function to handle the Gradio interface
|
28 |
+
def image_similarity(target_image, image_list):
|
29 |
target_image = target_image.astype(np.uint8)
|
30 |
+
image_list = [image.astype(np.uint8) for image in image_list]
|
31 |
+
scores = compute_similarity(target_image, image_list)
|
32 |
+
results = []
|
33 |
+
for image, score in zip(image_list, scores):
|
34 |
+
formatted_image = format_image(image)
|
35 |
+
result = f"Image: {formatted_image}\nScore: {score:.4f}\n"
|
36 |
+
results.append(result)
|
37 |
+
return "".join(results)
|
38 |
|
39 |
# Function to format the image representation as a string
|
40 |
def format_image(image):
|
41 |
formatted_image = ""
|
42 |
for row in image:
|
43 |
+
formatted_row = ", ".join([f"[{', '.join(map(str, pixel))}]" for pixel in row])
|
44 |
+
formatted_image += f"[{formatted_row}],\n"
|
45 |
return formatted_image[:-2]
|
46 |
|
47 |
# Prepare Gradio interface
|
|
|
49 |
fn=image_similarity,
|
50 |
inputs=[
|
51 |
gr.inputs.Image(type="numpy", label="Target Image"),
|
52 |
+
gr.inputs.Image(type="numpy", label="Image List", multiple=True)
|
53 |
],
|
54 |
outputs="text",
|
55 |
title="Image Similarity Calculator",
|
56 |
+
description="Upload a target image and a list of images. Get similarity scores."
|
57 |
)
|
58 |
|
59 |
# Launch the interface
|
|
|
65 |
|
66 |
|
67 |
|
68 |
+
|