Spaces:
Running on Zero
Running on Zero
PradhaanSBhat commited on
Commit ·
70b3ce2
1
Parent(s): f469697
Update to gradio 6.30.0
Browse files
demo.py
CHANGED
|
@@ -22,13 +22,8 @@ os.environ.setdefault("HF_ENDPOINT", "https://huggingface.co")
|
|
| 22 |
os.environ["GRADIO_TEMP_DIR"] = os.environ.get("GRADIO_TEMP_DIR") or "/tmp/gradio_tib"
|
| 23 |
os.makedirs(os.environ["GRADIO_TEMP_DIR"], exist_ok=True)
|
| 24 |
|
| 25 |
-
import
|
| 26 |
-
|
| 27 |
-
import torch
|
| 28 |
-
from diffusers import DiffusionPipeline
|
| 29 |
-
from PIL import Image
|
| 30 |
-
|
| 31 |
-
# ZeroGPU decorator; no-op fallback so this file also runs locally without `spaces`.
|
| 32 |
try:
|
| 33 |
import spaces
|
| 34 |
except Exception:
|
|
@@ -40,6 +35,12 @@ except Exception:
|
|
| 40 |
return deco
|
| 41 |
spaces = SimpleNamespace(GPU=_gpu)
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
HERE = Path(__file__).resolve().parent
|
| 44 |
EDITOR_HTML = HERE / "box-editor.html"
|
| 45 |
|
|
@@ -334,12 +335,12 @@ def _editor_srcdoc():
|
|
| 334 |
|
| 335 |
def build_demo():
|
| 336 |
iframe = _editor_srcdoc()
|
| 337 |
-
with gr.Blocks(title="Thinking in Boxes"
|
| 338 |
cube = ('<svg class="tib-cube {c}" viewBox="0 0 100 100" fill="none" stroke="#C0604A" '
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
cubes = "".join(cube.format(c=f"c{i}") for i in range(1, 7))
|
| 344 |
gr.HTML(f'<div id="tib-header">{cubes}'
|
| 345 |
'<div class="v">NeurIPS 2026</div>'
|
|
@@ -354,12 +355,12 @@ def build_demo():
|
|
| 354 |
with gr.Row(equal_height=True):
|
| 355 |
src_prev = gr.Image(label="Source boxes", elem_classes="tib-sq", show_label=True)
|
| 356 |
tgt_prev = gr.Image(label="Target boxes", elem_classes="tib-sq", show_label=True)
|
| 357 |
-
image_u = gr.Textbox(
|
| 358 |
-
tgt_u = gr.Textbox(
|
| 359 |
randomize = gr.Checkbox(value=True, label="🎲 Randomize seed")
|
| 360 |
gen = gr.Button("Generate", variant="primary", elem_classes="tib-step tib-step2")
|
| 361 |
out = gr.Gallery(label="Generated edit", columns=1, object_fit="contain",
|
| 362 |
-
|
| 363 |
seed_used = gr.Markdown()
|
| 364 |
|
| 365 |
detect_payload = gr.Textbox(elem_id="tib-detect-payload", elem_classes="tib-hidden")
|
|
@@ -373,9 +374,9 @@ def build_demo():
|
|
| 373 |
with gr.Row():
|
| 374 |
height = gr.Slider(256, 1536, value=DEFAULT_HEIGHT, step=16, label="Height")
|
| 375 |
width = gr.Slider(256, 1536, value=DEFAULT_WIDTH, step=16, label="Width")
|
| 376 |
-
guidance = gr.Number(value=DEFAULT_GUIDANCE,
|
| 377 |
-
true_cfg = gr.Number(value=DEFAULT_TRUE_CFG,
|
| 378 |
-
lora_scale = gr.Number(value=DEFAULT_SCALE,
|
| 379 |
|
| 380 |
grab.click(None, None, [image_u, src_u, tgt_u, status_u], js=GRAB_JS).then(
|
| 381 |
grab_show, [status_u, src_u, tgt_u], [src_prev, tgt_prev])
|
|
@@ -383,9 +384,9 @@ def build_demo():
|
|
| 383 |
None, [detect_result], None, js=DETECT_RESULT_JS)
|
| 384 |
demo.load(None, None, None, js=DETECT_BRIDGE_JS)
|
| 385 |
gen.click(generate,
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
return demo
|
| 390 |
|
| 391 |
try:
|
|
@@ -397,4 +398,5 @@ except Exception:
|
|
| 397 |
demo = build_demo()
|
| 398 |
|
| 399 |
if __name__ == "__main__":
|
| 400 |
-
demo.launch(
|
|
|
|
|
|
| 22 |
os.environ["GRADIO_TEMP_DIR"] = os.environ.get("GRADIO_TEMP_DIR") or "/tmp/gradio_tib"
|
| 23 |
os.makedirs(os.environ["GRADIO_TEMP_DIR"], exist_ok=True)
|
| 24 |
|
| 25 |
+
# ZeroGPU: import spaces BEFORE torch — it patches torch's CUDA at import time,
|
| 26 |
+
# and ZeroGPU detects @spaces.GPU functions through that patch.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
try:
|
| 28 |
import spaces
|
| 29 |
except Exception:
|
|
|
|
| 35 |
return deco
|
| 36 |
spaces = SimpleNamespace(GPU=_gpu)
|
| 37 |
|
| 38 |
+
import gradio as gr
|
| 39 |
+
import numpy as np
|
| 40 |
+
import torch
|
| 41 |
+
from diffusers import DiffusionPipeline
|
| 42 |
+
from PIL import Image
|
| 43 |
+
|
| 44 |
HERE = Path(__file__).resolve().parent
|
| 45 |
EDITOR_HTML = HERE / "box-editor.html"
|
| 46 |
|
|
|
|
| 335 |
|
| 336 |
def build_demo():
|
| 337 |
iframe = _editor_srcdoc()
|
| 338 |
+
with gr.Blocks(title="Thinking in Boxes") as demo:
|
| 339 |
cube = ('<svg class="tib-cube {c}" viewBox="0 0 100 100" fill="none" stroke="#C0604A" '
|
| 340 |
+
'stroke-width="4" stroke-linejoin="round">'
|
| 341 |
+
'<path d="M20 35 L50 20 L80 35 L50 50 Z"/>'
|
| 342 |
+
'<path d="M20 35 L20 70 L50 85 L50 50 Z"/>'
|
| 343 |
+
'<path d="M80 35 L80 70 L50 85 L50 50 Z"/></svg>')
|
| 344 |
cubes = "".join(cube.format(c=f"c{i}") for i in range(1, 7))
|
| 345 |
gr.HTML(f'<div id="tib-header">{cubes}'
|
| 346 |
'<div class="v">NeurIPS 2026</div>'
|
|
|
|
| 355 |
with gr.Row(equal_height=True):
|
| 356 |
src_prev = gr.Image(label="Source boxes", elem_classes="tib-sq", show_label=True)
|
| 357 |
tgt_prev = gr.Image(label="Target boxes", elem_classes="tib-sq", show_label=True)
|
| 358 |
+
image_u = gr.Textbox(elem_classes="tib-hidden"); src_u = gr.Textbox(elem_classes="tib-hidden")
|
| 359 |
+
tgt_u = gr.Textbox(elem_classes="tib-hidden"); status_u = gr.Textbox(elem_classes="tib-hidden")
|
| 360 |
randomize = gr.Checkbox(value=True, label="🎲 Randomize seed")
|
| 361 |
gen = gr.Button("Generate", variant="primary", elem_classes="tib-step tib-step2")
|
| 362 |
out = gr.Gallery(label="Generated edit", columns=1, object_fit="contain",
|
| 363 |
+
show_label=True, elem_classes="tib-out")
|
| 364 |
seed_used = gr.Markdown()
|
| 365 |
|
| 366 |
detect_payload = gr.Textbox(elem_id="tib-detect-payload", elem_classes="tib-hidden")
|
|
|
|
| 374 |
with gr.Row():
|
| 375 |
height = gr.Slider(256, 1536, value=DEFAULT_HEIGHT, step=16, label="Height")
|
| 376 |
width = gr.Slider(256, 1536, value=DEFAULT_WIDTH, step=16, label="Width")
|
| 377 |
+
guidance = gr.Number(value=DEFAULT_GUIDANCE, elem_classes="tib-hidden")
|
| 378 |
+
true_cfg = gr.Number(value=DEFAULT_TRUE_CFG, elem_classes="tib-hidden")
|
| 379 |
+
lora_scale = gr.Number(value=DEFAULT_SCALE, elem_classes="tib-hidden")
|
| 380 |
|
| 381 |
grab.click(None, None, [image_u, src_u, tgt_u, status_u], js=GRAB_JS).then(
|
| 382 |
grab_show, [status_u, src_u, tgt_u], [src_prev, tgt_prev])
|
|
|
|
| 384 |
None, [detect_result], None, js=DETECT_RESULT_JS)
|
| 385 |
demo.load(None, None, None, js=DETECT_BRIDGE_JS)
|
| 386 |
gen.click(generate,
|
| 387 |
+
[image_u, src_u, tgt_u, steps, guidance, true_cfg, lora_scale,
|
| 388 |
+
randomize, height, width, num_images],
|
| 389 |
+
[out, seed_used])
|
| 390 |
return demo
|
| 391 |
|
| 392 |
try:
|
|
|
|
| 398 |
demo = build_demo()
|
| 399 |
|
| 400 |
if __name__ == "__main__":
|
| 401 |
+
demo.launch(theme=THEME, css=CSS, ssr_mode=False,
|
| 402 |
+
favicon_path=str(HERE / "assets" / "favicon.svg"),share=True)
|