import os import gradio as gr import spaces import torch from diffusers import DiffusionPipeline from gradio_client import Client, file try: import diff_gaussian_rasterization # noqa: F401 except ImportError: @spaces.GPU def install_diff_gaussian_rasterization(): os.system("pip install ./diff-gaussian-rasterization") install_diff_gaussian_rasterization() TMP_DIR = "/tmp" os.makedirs(TMP_DIR, exist_ok=True) image_pipeline = DiffusionPipeline.from_pretrained( "ashawkey/imagedream-ipmv-diffusers", custom_pipeline="dylanebert/multi_view_diffusion", torch_dtype=torch.float16, trust_remote_code=True, ).to("cuda") splat_pipeline = DiffusionPipeline.from_pretrained( "dylanebert/LGM", custom_pipeline="dylanebert/LGM", torch_dtype=torch.float16, trust_remote_code=True, ).to("cuda") @spaces.GPU def run(input_image, convert): input_image = input_image.astype("float32") / 255.0 images = image_pipeline( "", input_image, guidance_scale=5, num_inference_steps=30, elevation=0 ) gaussians = splat_pipeline(images) output_ply_path = os.path.join(TMP_DIR, "output.ply") splat_pipeline.save_ply(gaussians, output_ply_path) if convert: output_mesh_path = convert_to_mesh(output_ply_path) return output_mesh_path else: return output_ply_path def convert_to_mesh(input_ply): client = Client("https://dylanebert-splat-to-mesh.hf.space/") output_mesh_path = client.predict(file(input_ply), api_name="/run") client.close() return output_mesh_path _TITLE = """LGM Mini""" _DESCRIPTION = """