Update app.py
Browse files
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,
|
28 |
target_image = target_image.astype(np.uint8)
|
29 |
-
|
30 |
-
scores = compute_similarity(target_image,
|
31 |
-
|
32 |
-
|
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
|
42 |
],
|
43 |
outputs="text",
|
44 |
title="Image Similarity Calculator",
|
45 |
-
description="Upload
|
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 |
+
|