Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,7 @@ import numpy as np
|
|
13 |
from huggingface_hub import hf_hub_download, list_repo_files
|
14 |
import boto3
|
15 |
from botocore.exceptions import NoCredentialsError
|
|
|
16 |
|
17 |
# Define constants
|
18 |
DESCRIPTION = "[ShowUI Demo](https://huggingface.co/showlab/ShowUI-2B)"
|
@@ -222,14 +223,18 @@ def build_demo(embed_mode, concurrency_count=1):
|
|
222 |
["./examples/safari_google.png", "Click on search bar."],
|
223 |
]
|
224 |
|
|
|
|
|
|
|
|
|
|
|
225 |
def set_example_flag(image_array, query):
|
226 |
-
|
227 |
for example_path, _ in examples:
|
228 |
example_image = Image.open(example_path)
|
229 |
-
|
230 |
-
|
231 |
return True
|
232 |
-
print("different")
|
233 |
return False
|
234 |
|
235 |
gr.Examples(
|
|
|
13 |
from huggingface_hub import hf_hub_download, list_repo_files
|
14 |
import boto3
|
15 |
from botocore.exceptions import NoCredentialsError
|
16 |
+
from hashlib import md5
|
17 |
|
18 |
# Define constants
|
19 |
DESCRIPTION = "[ShowUI Demo](https://huggingface.co/showlab/ShowUI-2B)"
|
|
|
223 |
["./examples/safari_google.png", "Click on search bar."],
|
224 |
]
|
225 |
|
226 |
+
def compute_image_hash(image_array):
|
227 |
+
"""Compute a hash for the image."""
|
228 |
+
img = Image.fromarray(np.uint8(image_array))
|
229 |
+
return md5(img.tobytes()).hexdigest()
|
230 |
+
|
231 |
def set_example_flag(image_array, query):
|
232 |
+
image_hash = compute_image_hash(image_array)
|
233 |
for example_path, _ in examples:
|
234 |
example_image = Image.open(example_path)
|
235 |
+
example_hash = md5(example_image.tobytes()).hexdigest()
|
236 |
+
if image_hash == example_hash:
|
237 |
return True
|
|
|
238 |
return False
|
239 |
|
240 |
gr.Examples(
|