Spaces:
Running
on
Zero
Running
on
Zero
Fix CUDA initialization error in texture generation for API endpoints
Browse files- Added generate_texture() GPU function to properly handle CUDA initialization
- Modified process_generation_job to use GPU function for texture generation
- Resolves 'CUDA must not be initialized in the main process' error
- Enables full texture generation for API endpoints while maintaining compatibility
- gradio_app.py +23 -7
gradio_app.py
CHANGED
@@ -185,17 +185,18 @@ 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 |
-
|
|
|
189 |
mesh_path=reduced_mesh_path,
|
190 |
image_path=main_image,
|
191 |
-
output_mesh_path=text_path
|
192 |
-
save_glb=False
|
193 |
)
|
194 |
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
|
|
199 |
|
200 |
except Exception as e:
|
201 |
logger.error(f"Texture generation failed: {e}")
|
@@ -630,6 +631,21 @@ def generation_all(
|
|
630 |
seed,
|
631 |
)
|
632 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
633 |
@spaces.GPU(duration=60)
|
634 |
def shape_generation(
|
635 |
caption=None,
|
|
|
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 = generate_texture(
|
190 |
mesh_path=reduced_mesh_path,
|
191 |
image_path=main_image,
|
192 |
+
output_mesh_path=text_path
|
|
|
193 |
)
|
194 |
|
195 |
+
if textured_mesh_path:
|
196 |
+
# Convert to GLB
|
197 |
+
glb_path_textured = os.path.join(save_folder, 'textured_mesh.glb')
|
198 |
+
quick_convert_with_obj2gltf(textured_mesh_path, glb_path_textured)
|
199 |
+
textured_mesh_path = glb_path_textured
|
200 |
|
201 |
except Exception as e:
|
202 |
logger.error(f"Texture generation failed: {e}")
|
|
|
631 |
seed,
|
632 |
)
|
633 |
|
634 |
+
@spaces.GPU(duration=60)
|
635 |
+
def generate_texture(mesh_path, image_path, output_mesh_path):
|
636 |
+
"""Generate texture for a mesh using GPU function."""
|
637 |
+
try:
|
638 |
+
textured_mesh_path = tex_pipeline(
|
639 |
+
mesh_path=mesh_path,
|
640 |
+
image_path=image_path,
|
641 |
+
output_mesh_path=output_mesh_path,
|
642 |
+
save_glb=False
|
643 |
+
)
|
644 |
+
return textured_mesh_path
|
645 |
+
except Exception as e:
|
646 |
+
logger.error(f"Texture generation failed: {e}")
|
647 |
+
return None
|
648 |
+
|
649 |
@spaces.GPU(duration=60)
|
650 |
def shape_generation(
|
651 |
caption=None,
|