h-siyuan commited on
Commit
68a6103
·
verified ·
1 Parent(s): 5cabf36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -23
app.py CHANGED
@@ -13,7 +13,6 @@ 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
- from hashlib import md5
17
 
18
  # Define constants
19
  DESCRIPTION = "[ShowUI Demo](https://huggingface.co/showlab/ShowUI-2B)"
@@ -212,36 +211,30 @@ def build_demo(embed_mode, concurrency_count=1):
212
  submit_btn = gr.Button(value="Submit", variant="primary")
213
 
214
  examples = [
215
- ["./examples/app_store.png", "Download Kindle."],
216
- ["./examples/ios_setting.png", "Turn off Do not disturb."],
217
- ["./examples/apple_music.png", "Star to favorite."],
218
- ["./examples/map.png", "Boston."],
219
- ["./examples/wallet.png", "Scan a QR code."],
220
- ["./examples/word.png", "More shapes."],
221
- ["./examples/web_shopping.png", "Proceed to checkout."],
222
- ["./examples/web_forum.png", "Post my comment."],
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(
241
- examples=examples,
242
  inputs=[imagebox, textbox],
243
  outputs=[state_is_example_image],
244
- fn=set_example_flag,
245
  examples_per_page=3
246
  )
247
 
 
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)"
 
211
  submit_btn = gr.Button(value="Submit", variant="primary")
212
 
213
  examples = [
214
+ ["./examples/app_store.png", "Download Kindle.", True],
215
+ ["./examples/ios_setting.png", "Turn off Do not disturb.", True],
216
+ ["./examples/apple_music.png", "Star to favorite.", True],
217
+ ["./examples/map.png", "Boston.", True],
218
+ ["./examples/wallet.png", "Scan a QR code.", True],
219
+ ["./examples/word.png", "More shapes.", True],
220
+ ["./examples/web_shopping.png", "Proceed to checkout.", True],
221
+ ["./examples/web_forum.png", "Post my comment.", True],
222
+ ["./examples/safari_google.png", "Click on search bar.", True],
223
  ]
224
 
225
+ def check_if_example(image_array, query):
226
+ """Check if the image and query match an example."""
227
+ for example_path, example_query, is_example in examples:
 
 
 
 
 
228
  example_image = Image.open(example_path)
229
+ if np.array_equal(np.array(example_image), image_array) and example_query == query:
230
+ return is_example
 
231
  return False
232
 
233
  gr.Examples(
234
+ examples=[[e[0], e[1]] for e in examples],
235
  inputs=[imagebox, textbox],
236
  outputs=[state_is_example_image],
237
+ fn=check_if_example,
238
  examples_per_page=3
239
  )
240