Spaces:
Running
on
Zero
Running
on
Zero
# In appTrellis_fileErrorsFIx.py | |
def text_to_3d( | |
prompt: str, | |
seed: int, | |
ss_guidance_strength: float, | |
ss_sampling_steps: int, | |
slat_guidance_strength: float, | |
slat_sampling_steps: int, | |
req: gr.Request, | |
) -> Tuple[dict, str]: # Return type changed for clarity | |
""" | |
Generates a 3D model (Gaussian and Mesh) from text and returns a | |
serializable state dictionary and a video preview path. | |
""" | |
print(f"[text_to_3d] Received prompt: '{prompt}', Seed: {seed}") | |
user_dir = os.path.join(TMP_DIR, str(req.session_hash)) | |
os.makedirs(user_dir, exist_ok=True) | |
print(f"[text_to_3d] User directory: {user_dir}") | |
# --- Generation Pipeline --- | |
try: | |
print("[text_to_3d] Running Trellis pipeline...") | |
outputs = pipeline.run( | |
prompt, | |
seed=seed, | |
formats=["gaussian", "mesh"], # Ensure both are generated | |
sparse_structure_sampler_params={ | |
"steps": int(ss_sampling_steps), # Ensure steps are int | |
"cfg_strength": float(ss_guidance_strength), | |
}, | |
slat_sampler_params={ | |
"steps": int(slat_sampling_steps), # Ensure steps are int | |
"cfg_strength": float(slat_guidance_strength), | |
}, | |
) | |
print("[text_to_3d] Pipeline run completed.") | |
except Exception as e: | |
print(f"❌ [text_to_3d] Pipeline error: {e}", file=sys.stderr) | |
traceback.print_exc() | |
raise gr.Error(f"Trellis pipeline failed: {e}") | |
# --- Create Serializable State Dictionary --- | |
try: | |
state_dict = pack_state(outputs['gaussian'][0], outputs['mesh'][0]) | |
except Exception as e: | |
print(f"❌ [text_to_3d] pack_state error: {e}", file=sys.stderr) | |
traceback.print_exc() | |
raise gr.Error(f"Failed to pack state: {e}") | |
# --- Render Video Preview (TEMPORARILY DISABLED FOR DEBUGGING) --- | |
video_path = None # Set path to None | |
# try: | |
# print("[text_to_3d] Rendering video preview...") | |
# video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color'] | |
# video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal'] | |
# # Ensure video frames are uint8 | |
# video = [np.concatenate([v.astype(np.uint8), vg.astype(np.uint8)], axis=1) for v, vg in zip(video, video_geo)] | |
# video_path = os.path.join(user_dir, 'sample.mp4') | |
# imageio.mimsave(video_path, video, fps=15, quality=8) # Added quality setting | |
# print(f"[text_to_3d] Video saved to: {video_path}") | |
# except Exception as e: | |
# print(f"❌ [text_to_3d] Video rendering/saving error: {e}", file=sys.stderr) | |
# traceback.print_exc() | |
# # Still return state_dict, but maybe signal video error? Return None for path. | |
# video_path = None # Indicate video failure | |
print("[text_to_3d] Skipping video rendering for debugging.") | |
# --- Cleanup and Return --- | |
if torch.cuda.is_available(): | |
torch.cuda.empty_cache() | |
print("[text_to_3d] Cleared CUDA cache.") | |
# --- Return Serializable Dictionary and None for Video Path --- | |
print("[text_to_3d] Returning state dictionary and None video path.") | |
return state_dict, video_path # Return dict and None video path | |
# --- Gradio UI Definition --- | |
# ... (rest of the file is the same, but you might want to adjust the output mapping if needed) | |
# In the generate_btn.click handler, adjust the outputs if the video component causes issues: | |
# Option 1: Keep Video component, it will just show nothing. | |
# outputs=[output_buf, video_output], # This might be fine | |
# Option 2: Use a dummy hidden component if video_output causes issues receiving None | |
# outputs=[output_buf, gr.Textbox(visible=False)], # Example dummy |