Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,6 +51,27 @@ def gen_save_folder(max_size=200):
|
|
| 51 |
|
| 52 |
return new_folder
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
@spaces.GPU
|
| 55 |
def handle_text_prompt(input_prompt, use_bbox = True, bbox_x=1.0, bbox_y=1.0, bbox_z=1.0, hi_res=False, guidance_scale=3.0):
|
| 56 |
# Create debug info
|
|
@@ -75,25 +96,10 @@ def handle_text_prompt(input_prompt, use_bbox = True, bbox_x=1.0, bbox_y=1.0, bb
|
|
| 75 |
|
| 76 |
print(f"prompt: {input_prompt}, use_bbox: {use_bbox}, bbox_x: {bbox_x}, bbox_y: {bbox_y}, bbox_z: {bbox_z}, hi_res: {hi_res}, guidance_scale: {guidance_scale}")
|
| 77 |
|
| 78 |
-
# EngineFast captures its CUDA graph for the doubled (cond+uncond) batch, so
|
| 79 |
-
#
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
"Guidance scale must be greater than 0 with the fast engine. "
|
| 83 |
-
"Fully disabling classifier-free guidance (0.0) requires the non-fast Engine."
|
| 84 |
-
)
|
| 85 |
-
|
| 86 |
-
if "engine_fast" not in GLOBAL_STATE:
|
| 87 |
-
config_path = GLOBAL_STATE["config_path"]
|
| 88 |
-
gpt_ckpt_path = "./model_weights/shape_gpt.safetensors"
|
| 89 |
-
shape_ckpt_path = "./model_weights/shape_tokenizer.safetensors"
|
| 90 |
-
engine_fast = EngineFast(
|
| 91 |
-
config_path,
|
| 92 |
-
gpt_ckpt_path,
|
| 93 |
-
shape_ckpt_path,
|
| 94 |
-
device=torch.device("cuda"),
|
| 95 |
-
)
|
| 96 |
-
GLOBAL_STATE["engine_fast"] = engine_fast
|
| 97 |
|
| 98 |
# Determine bounding box size based on option
|
| 99 |
bbox_size = None
|
|
@@ -104,7 +110,7 @@ def handle_text_prompt(input_prompt, use_bbox = True, bbox_x=1.0, bbox_y=1.0, bb
|
|
| 104 |
normalized_bbox = normalize_bbox(bbox_size) if bbox_size is not None else None
|
| 105 |
|
| 106 |
resolution_base = 9.0 if hi_res else 8.0
|
| 107 |
-
mesh_v_f =
|
| 108 |
# save output
|
| 109 |
vertices, faces = mesh_v_f[0][0], mesh_v_f[0][1]
|
| 110 |
|
|
@@ -179,7 +185,7 @@ def build_interface():
|
|
| 179 |
step=0.5,
|
| 180 |
value=3.0,
|
| 181 |
label="Guidance Scale",
|
| 182 |
-
info="Classifier-free guidance strength. Higher = stronger prompt adherence. 0 disables CFG (
|
| 183 |
)
|
| 184 |
with gr.Row():
|
| 185 |
submit_button = gr.Button("Submit", variant="primary")
|
|
@@ -246,4 +252,4 @@ if __name__=="__main__":
|
|
| 246 |
repo_id="Roblox/cube3d-v0.5",
|
| 247 |
local_dir="./model_weights"
|
| 248 |
)
|
| 249 |
-
generate(args)
|
|
|
|
| 51 |
|
| 52 |
return new_folder
|
| 53 |
|
| 54 |
+
def get_engine(use_fast):
|
| 55 |
+
"""Lazily build and cache the requested engine.
|
| 56 |
+
|
| 57 |
+
EngineFast captures a CUDA graph for the doubled (cond+uncond) batch and so
|
| 58 |
+
cannot run with guidance_scale == 0 (CFG disabled); Engine is used in that case.
|
| 59 |
+
Both are cached separately so switching between them doesn't reload weights.
|
| 60 |
+
"""
|
| 61 |
+
key = "engine_fast" if use_fast else "engine"
|
| 62 |
+
if key not in GLOBAL_STATE:
|
| 63 |
+
config_path = GLOBAL_STATE["config_path"]
|
| 64 |
+
gpt_ckpt_path = "./model_weights/shape_gpt.safetensors"
|
| 65 |
+
shape_ckpt_path = "./model_weights/shape_tokenizer.safetensors"
|
| 66 |
+
engine_cls = EngineFast if use_fast else Engine
|
| 67 |
+
GLOBAL_STATE[key] = engine_cls(
|
| 68 |
+
config_path,
|
| 69 |
+
gpt_ckpt_path,
|
| 70 |
+
shape_ckpt_path,
|
| 71 |
+
device=torch.device("cuda"),
|
| 72 |
+
)
|
| 73 |
+
return GLOBAL_STATE[key]
|
| 74 |
+
|
| 75 |
@spaces.GPU
|
| 76 |
def handle_text_prompt(input_prompt, use_bbox = True, bbox_x=1.0, bbox_y=1.0, bbox_z=1.0, hi_res=False, guidance_scale=3.0):
|
| 77 |
# Create debug info
|
|
|
|
| 96 |
|
| 97 |
print(f"prompt: {input_prompt}, use_bbox: {use_bbox}, bbox_x: {bbox_x}, bbox_y: {bbox_y}, bbox_z: {bbox_z}, hi_res: {hi_res}, guidance_scale: {guidance_scale}")
|
| 98 |
|
| 99 |
+
# EngineFast captures its CUDA graph for the doubled (cond+uncond) batch, so it
|
| 100 |
+
# cannot run with guidance_scale == 0 (CFG disabled). Fall back to Engine there.
|
| 101 |
+
use_fast = guidance_scale > 0.0
|
| 102 |
+
engine = get_engine(use_fast)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
# Determine bounding box size based on option
|
| 105 |
bbox_size = None
|
|
|
|
| 110 |
normalized_bbox = normalize_bbox(bbox_size) if bbox_size is not None else None
|
| 111 |
|
| 112 |
resolution_base = 9.0 if hi_res else 8.0
|
| 113 |
+
mesh_v_f = engine.t2s([input_prompt], use_kv_cache=True, resolution_base=resolution_base, bounding_box_xyz=normalized_bbox, guidance_scale=guidance_scale)
|
| 114 |
# save output
|
| 115 |
vertices, faces = mesh_v_f[0][0], mesh_v_f[0][1]
|
| 116 |
|
|
|
|
| 185 |
step=0.5,
|
| 186 |
value=3.0,
|
| 187 |
label="Guidance Scale",
|
| 188 |
+
info="Classifier-free guidance strength. Higher = stronger prompt adherence. 0 disables CFG (uses the slower non-fast engine).",
|
| 189 |
)
|
| 190 |
with gr.Row():
|
| 191 |
submit_button = gr.Button("Submit", variant="primary")
|
|
|
|
| 252 |
repo_id="Roblox/cube3d-v0.5",
|
| 253 |
local_dir="./model_weights"
|
| 254 |
)
|
| 255 |
+
generate(args)
|