qubvel-hf HF Staff commited on
Commit
61d656f
·
1 Parent(s): 8ddd00a

More examples + cache

Browse files
app.py CHANGED
@@ -43,6 +43,9 @@ TORCH_DTYPE = torch.float32
43
 
44
  # Image
45
  IMAGE_EXAMPLES = [
 
 
 
46
  {"path": "./examples/images/crossroad.jpg", "use_url": False, "url": "", "label": "Local Image"},
47
  {
48
  "path": None,
@@ -59,6 +62,7 @@ ALLOWED_VIDEO_EXTENSIONS = {".mp4", ".avi", ".mov"}
59
  VIDEO_OUTPUT_DIR = Path("static/videos")
60
  VIDEO_OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
61
  VIDEO_EXAMPLES = [
 
62
  {"path": "./examples/videos/traffic.mp4", "label": "Local Video"},
63
  {"path": "./examples/videos/fast_and_furious.mp4", "label": "Local Video"},
64
  {"path": "./examples/videos/break_dance.mp4", "label": "Local Video"},
@@ -129,8 +133,11 @@ def process_image(
129
  checkpoint: str = DEFAULT_CHECKPOINT,
130
  image: Optional[Image.Image] = None,
131
  url: Optional[str] = None,
 
132
  confidence_threshold: float = DEFAULT_CONFIDENCE_THRESHOLD,
133
  ):
 
 
134
 
135
  if (image is None) ^ bool(url):
136
  raise ValueError(f"Either image or url must be provided, but not both.")
@@ -344,25 +351,26 @@ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
344
  gr.Examples(
345
  examples=[
346
  [
 
347
  example["path"],
348
- example["use_url"],
349
  example["url"],
350
- DEFAULT_CHECKPOINT,
351
  DEFAULT_CONFIDENCE_THRESHOLD,
352
  ]
353
  for example in IMAGE_EXAMPLES
354
  ],
355
  inputs=[
 
356
  image_input,
357
- use_url,
358
  url_input,
359
- image_model_checkpoint,
360
  image_confidence_threshold,
361
  ],
362
  outputs=[image_output],
363
  fn=process_image,
364
- cache_examples=False,
365
  label="Select an image example to populate inputs",
 
 
366
  )
367
 
368
  with gr.Tab("Video"):
@@ -389,7 +397,8 @@ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
389
  inputs=[video_input, video_checkpoint, video_confidence_threshold],
390
  outputs=[video_output],
391
  fn=process_video,
392
- cache_examples=False,
 
393
  label="Select a video example to populate inputs",
394
  )
395
 
@@ -443,6 +452,7 @@ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
443
  image_model_checkpoint,
444
  image_input,
445
  url_input,
 
446
  image_confidence_threshold,
447
  ],
448
  outputs=[image_output],
 
43
 
44
  # Image
45
  IMAGE_EXAMPLES = [
46
+ {"path": "./examples/images/tennis.jpg", "use_url": False, "url": "", "label": "Local Image"},
47
+ {"path": "./examples/images/dogs.jpg", "use_url": False, "url": "", "label": "Local Image"},
48
+ {"path": "./examples/images/nascar.jpg", "use_url": False, "url": "", "label": "Local Image"},
49
  {"path": "./examples/images/crossroad.jpg", "use_url": False, "url": "", "label": "Local Image"},
50
  {
51
  "path": None,
 
62
  VIDEO_OUTPUT_DIR = Path("static/videos")
63
  VIDEO_OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
64
  VIDEO_EXAMPLES = [
65
+ {"path": "./examples/videos/dogs_running.mp4", "label": "Local Video"},
66
  {"path": "./examples/videos/traffic.mp4", "label": "Local Video"},
67
  {"path": "./examples/videos/fast_and_furious.mp4", "label": "Local Video"},
68
  {"path": "./examples/videos/break_dance.mp4", "label": "Local Video"},
 
133
  checkpoint: str = DEFAULT_CHECKPOINT,
134
  image: Optional[Image.Image] = None,
135
  url: Optional[str] = None,
136
+ use_url: bool = False,
137
  confidence_threshold: float = DEFAULT_CONFIDENCE_THRESHOLD,
138
  ):
139
+ if not use_url:
140
+ url = None
141
 
142
  if (image is None) ^ bool(url):
143
  raise ValueError(f"Either image or url must be provided, but not both.")
 
351
  gr.Examples(
352
  examples=[
353
  [
354
+ DEFAULT_CHECKPOINT,
355
  example["path"],
 
356
  example["url"],
357
+ example["use_url"],
358
  DEFAULT_CONFIDENCE_THRESHOLD,
359
  ]
360
  for example in IMAGE_EXAMPLES
361
  ],
362
  inputs=[
363
+ image_model_checkpoint,
364
  image_input,
 
365
  url_input,
366
+ use_url,
367
  image_confidence_threshold,
368
  ],
369
  outputs=[image_output],
370
  fn=process_image,
 
371
  label="Select an image example to populate inputs",
372
+ cache_examples=True,
373
+ cache_mode="lazy",
374
  )
375
 
376
  with gr.Tab("Video"):
 
397
  inputs=[video_input, video_checkpoint, video_confidence_threshold],
398
  outputs=[video_output],
399
  fn=process_video,
400
+ cache_examples=True,
401
+ cache_mode="lazy",
402
  label="Select a video example to populate inputs",
403
  )
404
 
 
452
  image_model_checkpoint,
453
  image_input,
454
  url_input,
455
+ use_url,
456
  image_confidence_threshold,
457
  ],
458
  outputs=[image_output],
examples/images/dogs.jpg ADDED

Git LFS Details

  • SHA256: 77e136877488dc3d9f1a4860dbeaa962c166eb33fbd786150a9ce33d796ee53d
  • Pointer size: 131 Bytes
  • Size of remote file: 423 kB
examples/images/nascar.jpg ADDED

Git LFS Details

  • SHA256: 6b8f544d41abcd178dc791e4ca1605ce62f23eedadcbb2489be25d25427cce55
  • Pointer size: 131 Bytes
  • Size of remote file: 758 kB
examples/images/tennis.jpg ADDED

Git LFS Details

  • SHA256: 9ba13f176092037fcd65bf0038af7c498e24ce83b8f33a416e2e7b04dbde0a5d
  • Pointer size: 131 Bytes
  • Size of remote file: 121 kB
examples/videos/dogs_running.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:043c1a28bddcd9beeddbab946c38d1a91de2a18da3ae114d307cd01b30b64ca2
3
+ size 22119043