ysharma HF Staff commited on
Commit
f8f0519
Β·
verified Β·
1 Parent(s): 20d3846

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -50
app.py CHANGED
@@ -20,7 +20,7 @@ MAX_SEED = np.iinfo(np.int32).max
20
  dtype = torch.bfloat16
21
  device = "cuda" if torch.cuda.is_available() else "cpu"
22
 
23
- # MODEL LOADING ON ZEROGPU
24
  pipe = QwenImageEditPlusPipeline.from_pretrained(
25
  "Qwen/Qwen-Image-Edit-2511",
26
  torch_dtype=dtype,
@@ -39,7 +39,7 @@ pipe.load_lora_weights(
39
  pipe.set_adapters(["lightning", "angles"], adapter_weights=[1.0, 1.0])
40
 
41
 
42
- # Camera parameter tables
43
  AZIMUTH_MAP = {
44
  0: "front view",
45
  45: "front-right quarter view",
@@ -90,7 +90,7 @@ def pil_to_data_url(img: Image.Image) -> str:
90
  return f"data:{mime};base64,{b64}"
91
 
92
 
93
- # Inference
94
  @spaces.GPU(duration=120)
95
  def infer_camera_edit(
96
  image, azimuth, elevation, distance,
@@ -115,12 +115,11 @@ def infer_camera_edit(
115
  return result, seed, prompt
116
 
117
 
118
- # gr.HTML templates
119
  # Using plain gr.HTML (no subclass) with a dict value.
120
  #
121
  # Gradio 6 passes the dict as `value` to the template; all keys (img, az, el,
122
  # dist) are accessible as value.img, value.az, etc. in both ${} and {{}} syntax.
123
-
124
  HTML_TEMPLATE = """
125
  <div class="cv-wrap">
126
  {{#if value.img}}
@@ -314,12 +313,11 @@ element.addEventListener('click', function(e) {
314
  """
315
 
316
 
317
- # Global Gradio CSS
318
  GLOBAL_CSS = """
319
- /* ── Page ── */
320
- .gradio-container { max-width: 1160px !important; margin: 0 auto !important; }
321
-
322
- /* Force the main two-column row to never wrap, regardless of viewport */
323
  .gradio-container .row {
324
  flex-wrap: nowrap !important;
325
  }
@@ -398,29 +396,12 @@ GLOBAL_CSS = """
398
  color: #6b7280 !important;
399
  }
400
 
401
- /* ── Gallery section ── */
402
- .gallery-heading {
403
- display: flex; align-items: center; gap: 10px;
404
- padding: 16px 0 10px;
405
- border-top: 1px solid #e5e7eb;
406
- margin-top: 8px;
407
- }
408
- .gallery-heading span {
409
- font-size: 14px; font-weight: 600; color: #374151;
410
- }
411
- .gallery-heading .count-badge {
412
- background: #f3f4f6;
413
- border: 1px solid #e5e7eb;
414
- border-radius: 999px;
415
- padding: 1px 8px;
416
- font-size: 11px; color: #9ca3af;
417
- }
418
  """
419
 
420
  GRADIO_THEME = gr.themes.Default()
421
 
422
 
423
- # App
424
  def create_app():
425
 
426
  # FIX: theme and css are now passed to launch(), not gr.Blocks()
@@ -442,8 +423,8 @@ def create_app():
442
 
443
  with gr.Row():
444
 
445
- # Left column
446
- with gr.Column(scale=4, min_width=260, elem_classes=["controls-col"]):
447
  image_input = gr.Image(
448
  label="Source Image",
449
  type="pil",
@@ -466,8 +447,8 @@ def create_app():
466
  width_sl = gr.Slider(256, 1024, value=1024, step=32, label="Width (px)")
467
  height_sl = gr.Slider(256, 1024, value=1024, step=32, label="Height (px)")
468
 
469
- # Right column
470
- with gr.Column(scale=6, min_width=320):
471
  gr.HTML("""
472
  <div class="viewer-label">
473
  Camera View
@@ -492,24 +473,18 @@ def create_app():
492
  elem_classes=["status-box"],
493
  )
494
 
495
- gr.HTML("""
496
- <div class="gallery-heading">
497
- <span>Generated Views</span>
498
- <span class="count-badge">session</span>
499
- </div>
500
- """)
501
-
502
  gallery_state = gr.State([])
503
- gallery = gr.Gallery(
504
- label="Generated Views",
505
- show_label=True,
506
- columns=4,
507
- height="auto",
508
- object_fit="cover",
509
- allow_preview=True,
510
- )
 
511
 
512
- # Helpers
513
 
514
  def _coerce_view(v):
515
  """Extract (az, el, dist) safely from a dict or default."""
@@ -530,7 +505,7 @@ def create_app():
530
  nw = round(1024 * ar / 32) * 32
531
  return max(256, min(1024, nw)), max(256, min(1024, nh))
532
 
533
- # Event handlers
534
 
535
  def on_image_upload(img, current_view):
536
  nw, nh = _auto_dimensions(img)
@@ -601,4 +576,4 @@ if __name__ == "__main__":
601
  debug=True,
602
  theme=GRADIO_THEME,
603
  css=GLOBAL_CSS,
604
- )
 
20
  dtype = torch.bfloat16
21
  device = "cuda" if torch.cuda.is_available() else "cpu"
22
 
23
+ # ── Model Loading on ZEROGPU
24
  pipe = QwenImageEditPlusPipeline.from_pretrained(
25
  "Qwen/Qwen-Image-Edit-2511",
26
  torch_dtype=dtype,
 
39
  pipe.set_adapters(["lightning", "angles"], adapter_weights=[1.0, 1.0])
40
 
41
 
42
+ # ── Camera parameter tables ────────────────────────────────────────────────────
43
  AZIMUTH_MAP = {
44
  0: "front view",
45
  45: "front-right quarter view",
 
90
  return f"data:{mime};base64,{b64}"
91
 
92
 
93
+ # ── Inference ──────────────────────────────────────────────────────────────────
94
  @spaces.GPU(duration=120)
95
  def infer_camera_edit(
96
  image, azimuth, elevation, distance,
 
115
  return result, seed, prompt
116
 
117
 
118
+ # ── gr.HTML templates ──────────────────────────────────────────────────────────
119
  # Using plain gr.HTML (no subclass) with a dict value.
120
  #
121
  # Gradio 6 passes the dict as `value` to the template; all keys (img, az, el,
122
  # dist) are accessible as value.img, value.az, etc. in both ${} and {{}} syntax.
 
123
  HTML_TEMPLATE = """
124
  <div class="cv-wrap">
125
  {{#if value.img}}
 
313
  """
314
 
315
 
316
+ # ── Global Gradio CSS ──────────────────────────────────────────────────────────
317
  GLOBAL_CSS = """
318
+ /* ── Row: never let the two columns wrap ── */
319
+ /* Gradio 6 renders rows as flex containers with class "flex" */
320
+ .gradio-container .flex.flex-row,
 
321
  .gradio-container .row {
322
  flex-wrap: nowrap !important;
323
  }
 
396
  color: #6b7280 !important;
397
  }
398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
  """
400
 
401
  GRADIO_THEME = gr.themes.Default()
402
 
403
 
404
+ # ── App ────────────────────────────────────────────────────────────────────────
405
  def create_app():
406
 
407
  # FIX: theme and css are now passed to launch(), not gr.Blocks()
 
423
 
424
  with gr.Row():
425
 
426
+ # ── Left column ──────────────────────────────────────────────────
427
+ with gr.Column(scale=4, min_width=200, elem_classes=["controls-col"]):
428
  image_input = gr.Image(
429
  label="Source Image",
430
  type="pil",
 
447
  width_sl = gr.Slider(256, 1024, value=1024, step=32, label="Width (px)")
448
  height_sl = gr.Slider(256, 1024, value=1024, step=32, label="Height (px)")
449
 
450
+ # ── Right column ─────────────────────────────────────────────────
451
+ with gr.Column(scale=6, min_width=280):
452
  gr.HTML("""
453
  <div class="viewer-label">
454
  Camera View
 
473
  elem_classes=["status-box"],
474
  )
475
 
 
 
 
 
 
 
 
476
  gallery_state = gr.State([])
477
+ with gr.Accordion("πŸ–Ό Generated Views", open=False):
478
+ gallery = gr.Gallery(
479
+ label="",
480
+ show_label=False,
481
+ columns=4,
482
+ height="auto",
483
+ object_fit="cover",
484
+ allow_preview=True,
485
+ )
486
 
487
+ # ── Helpers ──────────────────────────────────────────────────────────
488
 
489
  def _coerce_view(v):
490
  """Extract (az, el, dist) safely from a dict or default."""
 
505
  nw = round(1024 * ar / 32) * 32
506
  return max(256, min(1024, nw)), max(256, min(1024, nh))
507
 
508
+ # ── Event handlers ────────────────────────────────────────────────────
509
 
510
  def on_image_upload(img, current_view):
511
  nw, nh = _auto_dimensions(img)
 
576
  debug=True,
577
  theme=GRADIO_THEME,
578
  css=GLOBAL_CSS,
579
+ )