Spaces:
Running
on
Zero
Running
on
Zero
Implement lazy texture initialization for API endpoints
Browse files- Added generate_texture_lazy() GPU function with lazy initialization
- Texture pipeline is now initialized inside GPU function to avoid CUDA startup issues
- Enables full texture generation for API endpoints
- Resolves CUDA initialization errors while maintaining texturing capability
- gradio_app.py +18 -5
gradio_app.py
CHANGED
@@ -185,8 +185,8 @@ def process_generation_job(job_id: str, images: Dict[str, str], options: Dict[st
|
|
185 |
if should_texture and HAS_TEXTUREGEN:
|
186 |
try:
|
187 |
text_path = os.path.join(save_folder, 'textured_mesh.obj')
|
188 |
-
# Use GPU function for texture generation
|
189 |
-
textured_mesh_path =
|
190 |
mesh_path=reduced_mesh_path,
|
191 |
image_path=main_image,
|
192 |
output_mesh_path=text_path
|
@@ -631,11 +631,24 @@ def generation_all(
|
|
631 |
seed,
|
632 |
)
|
633 |
|
|
|
634 |
@spaces.GPU(duration=60)
|
635 |
-
def
|
636 |
-
"""Generate texture for a mesh using
|
637 |
try:
|
638 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
639 |
mesh_path=mesh_path,
|
640 |
image_path=image_path,
|
641 |
output_mesh_path=output_mesh_path,
|
|
|
185 |
if should_texture and HAS_TEXTUREGEN:
|
186 |
try:
|
187 |
text_path = os.path.join(save_folder, 'textured_mesh.obj')
|
188 |
+
# Use GPU function for texture generation with lazy initialization
|
189 |
+
textured_mesh_path = generate_texture_lazy(
|
190 |
mesh_path=reduced_mesh_path,
|
191 |
image_path=main_image,
|
192 |
output_mesh_path=text_path
|
|
|
631 |
seed,
|
632 |
)
|
633 |
|
634 |
+
|
635 |
@spaces.GPU(duration=60)
|
636 |
+
def generate_texture_lazy(mesh_path, image_path, output_mesh_path):
|
637 |
+
"""Generate texture for a mesh using lazy initialization to avoid CUDA startup issues."""
|
638 |
try:
|
639 |
+
# Lazy initialization of texture pipeline inside GPU function
|
640 |
+
from hy3dpaint.textureGenPipeline import Hunyuan3DPaintPipeline, Hunyuan3DPaintConfig
|
641 |
+
|
642 |
+
conf = Hunyuan3DPaintConfig(max_num_view=8, resolution=768)
|
643 |
+
conf.realesrgan_ckpt_path = "hy3dpaint/ckpt/RealESRGAN_x4plus.pth"
|
644 |
+
conf.multiview_cfg_path = "hy3dpaint/cfgs/hunyuan-paint-pbr.yaml"
|
645 |
+
conf.custom_pipeline = "hy3dpaint/hunyuanpaintpbr"
|
646 |
+
|
647 |
+
# Initialize texture pipeline inside GPU function
|
648 |
+
local_tex_pipeline = Hunyuan3DPaintPipeline(conf)
|
649 |
+
|
650 |
+
# Generate texture
|
651 |
+
textured_mesh_path = local_tex_pipeline(
|
652 |
mesh_path=mesh_path,
|
653 |
image_path=image_path,
|
654 |
output_mesh_path=output_mesh_path,
|