opsiclear-admin commited on
Commit
4d953ab
·
verified ·
1 Parent(s): 61dad38

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +67 -10
app.py CHANGED
@@ -103,14 +103,30 @@ DEFAULT_STEP = 3
103
 
104
 
105
  css = """
106
- /* Minimal color overrides for dark theme */
107
  :root {
 
 
 
 
 
 
 
 
 
108
  --color-accent: #b8b8b8 !important;
109
  --color-accent-soft: rgba(184, 184, 184, 0.15) !important;
 
 
110
  }
111
 
 
 
 
 
112
  /* Previewer (required for custom HTML viewer) */
113
  .previewer-container {
 
114
  position: relative;
115
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
116
  width: 100%;
@@ -404,8 +420,35 @@ def get_seed(randomize_seed: bool, seed: int) -> int:
404
  return np.random.randint(0, MAX_SEED) if randomize_seed else seed
405
 
406
 
407
- def prepare_examples() -> List[List[str]]:
408
- """Prepare multi-image examples as lists of image paths."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409
  example_dir = "assets/example_multi_image"
410
  if not os.path.exists(example_dir):
411
  return []
@@ -419,7 +462,8 @@ def prepare_examples() -> List[List[str]]:
419
  if os.path.exists(img_path):
420
  case_images.append(img_path)
421
  if case_images:
422
- examples.append(case_images)
 
423
  return examples
424
 
425
 
@@ -663,19 +707,32 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
663
  download_btn = gr.DownloadButton(label="Download GLB")
664
  gr.Markdown("*GLB extraction may take 30+ seconds.*")
665
 
666
- with gr.Column(scale=1, min_width=172):
667
  gr.Markdown("### Multi-View Examples")
668
  example_data = prepare_examples()
669
- for i, example_paths in enumerate(example_data[:12]):
 
670
  case_name = os.path.basename(example_paths[0]).split('_')[0]
671
- btn = gr.Button(f"{case_name} ({len(example_paths)} views)", size="sm")
672
- btn.click(
673
- fn=lambda paths=example_paths: load_example(paths),
674
- outputs=[image_prompt]
 
 
 
675
  )
 
 
676
 
677
  output_buf = gr.State()
678
 
 
 
 
 
 
 
 
679
  # Handlers
680
  demo.load(start_session)
681
  demo.unload(end_session)
 
103
 
104
 
105
  css = """
106
+ /* ColmapView Dark Theme */
107
  :root {
108
+ --body-background-fill: #0a0a0a !important;
109
+ --background-fill-primary: #0f0f0f !important;
110
+ --background-fill-secondary: #161616 !important;
111
+ --block-background-fill: #161616 !important;
112
+ --input-background-fill: #1a1a1a !important;
113
+ --body-text-color: #e8e8e8 !important;
114
+ --block-label-text-color: #8a8a8a !important;
115
+ --block-title-text-color: #e8e8e8 !important;
116
+ --border-color-primary: #2a2a2a !important;
117
  --color-accent: #b8b8b8 !important;
118
  --color-accent-soft: rgba(184, 184, 184, 0.15) !important;
119
+ --button-primary-background-fill: #b8b8b8 !important;
120
+ --button-primary-text-color: #0a0a0a !important;
121
  }
122
 
123
+ body { background: #0a0a0a !important; }
124
+ .gradio-container { background: #0f0f0f !important; }
125
+ .dark { background: #0f0f0f !important; }
126
+
127
  /* Previewer (required for custom HTML viewer) */
128
  .previewer-container {
129
+ background: #0a0a0a;
130
  position: relative;
131
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
132
  width: 100%;
 
420
  return np.random.randint(0, MAX_SEED) if randomize_seed else seed
421
 
422
 
423
+ def create_example_thumbnail(image_paths: List[str], thumb_size: int = 80) -> Image.Image:
424
+ """Create a composite thumbnail from multiple images."""
425
+ images = [Image.open(p) for p in image_paths[:3]] # Use first 3 images
426
+ n = len(images)
427
+
428
+ # Resize each image to thumbnail size
429
+ thumbs = []
430
+ for img in images:
431
+ img = img.convert('RGBA')
432
+ img.thumbnail((thumb_size, thumb_size), Image.Resampling.LANCZOS)
433
+ thumbs.append(img)
434
+
435
+ # Create composite image
436
+ width = thumb_size * n + (n - 1) * 4 # 4px gap between images
437
+ height = thumb_size
438
+ composite = Image.new('RGBA', (width, height), (0, 0, 0, 0))
439
+
440
+ x = 0
441
+ for thumb in thumbs:
442
+ # Center vertically
443
+ y = (height - thumb.height) // 2
444
+ composite.paste(thumb, (x + (thumb_size - thumb.width) // 2, y), thumb)
445
+ x += thumb_size + 4
446
+
447
+ return composite
448
+
449
+
450
+ def prepare_examples() -> List[Tuple[List[str], Image.Image]]:
451
+ """Prepare multi-image examples with thumbnails."""
452
  example_dir = "assets/example_multi_image"
453
  if not os.path.exists(example_dir):
454
  return []
 
462
  if os.path.exists(img_path):
463
  case_images.append(img_path)
464
  if case_images:
465
+ thumbnail = create_example_thumbnail(case_images)
466
+ examples.append((case_images, thumbnail))
467
  return examples
468
 
469
 
 
707
  download_btn = gr.DownloadButton(label="Download GLB")
708
  gr.Markdown("*GLB extraction may take 30+ seconds.*")
709
 
710
+ with gr.Column(scale=1, min_width=200):
711
  gr.Markdown("### Multi-View Examples")
712
  example_data = prepare_examples()
713
+ example_buttons = []
714
+ for i, (example_paths, thumbnail) in enumerate(example_data[:12]):
715
  case_name = os.path.basename(example_paths[0]).split('_')[0]
716
+ gr.Image(
717
+ value=thumbnail,
718
+ show_label=False,
719
+ height=60,
720
+ container=False,
721
+ show_download_button=False,
722
+ show_fullscreen_button=False,
723
  )
724
+ btn = gr.Button(f"{case_name} ({len(example_paths)} views)", size="sm")
725
+ example_buttons.append((btn, example_paths))
726
 
727
  output_buf = gr.State()
728
 
729
+ # Connect example buttons
730
+ for btn, paths in example_buttons:
731
+ btn.click(
732
+ fn=lambda p=paths: load_example(p),
733
+ outputs=[image_prompt]
734
+ )
735
+
736
  # Handlers
737
  demo.load(start_session)
738
  demo.unload(end_session)