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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""InteriorFusion CLI entry point."""
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
import torch
|
| 9 |
+
from PIL import Image
|
| 10 |
+
|
| 11 |
+
from .pipelines import InteriorFusionPipeline
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def parse_args():
|
| 15 |
+
parser = argparse.ArgumentParser(
|
| 16 |
+
description="InteriorFusion: Single image to 3D interior scene"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
parser.add_argument(
|
| 20 |
+
"--image", "-i",
|
| 21 |
+
type=str,
|
| 22 |
+
required=True,
|
| 23 |
+
help="Path to input interior image",
|
| 24 |
+
)
|
| 25 |
+
parser.add_argument(
|
| 26 |
+
"--output", "-o",
|
| 27 |
+
type=str,
|
| 28 |
+
default="./output",
|
| 29 |
+
help="Output directory for generated 3D files",
|
| 30 |
+
)
|
| 31 |
+
parser.add_argument(
|
| 32 |
+
"--model-size",
|
| 33 |
+
type=str,
|
| 34 |
+
default="L",
|
| 35 |
+
choices=["S", "L", "XL"],
|
| 36 |
+
help="Model size: S (fast), L (balanced), XL (quality)",
|
| 37 |
+
)
|
| 38 |
+
parser.add_argument(
|
| 39 |
+
"--device",
|
| 40 |
+
type=str,
|
| 41 |
+
default="cuda" if torch.cuda.is_available() else "cpu",
|
| 42 |
+
help="Device for inference",
|
| 43 |
+
)
|
| 44 |
+
parser.add_argument(
|
| 45 |
+
"--dtype",
|
| 46 |
+
type=str,
|
| 47 |
+
default="float16",
|
| 48 |
+
choices=["float16", "bfloat16", "float32"],
|
| 49 |
+
help="Data type for inference",
|
| 50 |
+
)
|
| 51 |
+
parser.add_argument(
|
| 52 |
+
"--room-type",
|
| 53 |
+
type=str,
|
| 54 |
+
default=None,
|
| 55 |
+
help="Optional room type hint (living_room, bedroom, kitchen, etc.)",
|
| 56 |
+
)
|
| 57 |
+
parser.add_argument(
|
| 58 |
+
"--style",
|
| 59 |
+
type=str,
|
| 60 |
+
default=None,
|
| 61 |
+
help="Optional style hint (modern, scandinavian, luxury, etc.)",
|
| 62 |
+
)
|
| 63 |
+
parser.add_argument(
|
| 64 |
+
"--formats",
|
| 65 |
+
type=str,
|
| 66 |
+
default="glb,ply",
|
| 67 |
+
help="Comma-separated export formats (glb,fbx,obj,usdz,ply)",
|
| 68 |
+
)
|
| 69 |
+
parser.add_argument(
|
| 70 |
+
"--interactive",
|
| 71 |
+
action="store_true",
|
| 72 |
+
help="Launch interactive editing mode",
|
| 73 |
+
)
|
| 74 |
+
parser.add_argument(
|
| 75 |
+
"--no-pbr",
|
| 76 |
+
action="store_true",
|
| 77 |
+
help="Disable PBR material generation (faster)",
|
| 78 |
+
)
|
| 79 |
+
parser.add_argument(
|
| 80 |
+
"--no-gaussian",
|
| 81 |
+
action="store_true",
|
| 82 |
+
help="Disable Gaussian Splatting output",
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
return parser.parse_args()
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def main():
|
| 89 |
+
args = parse_args()
|
| 90 |
+
|
| 91 |
+
# Validate input
|
| 92 |
+
if not os.path.exists(args.image):
|
| 93 |
+
print(f"Error: Image not found: {args.image}", file=sys.stderr)
|
| 94 |
+
sys.exit(1)
|
| 95 |
+
|
| 96 |
+
# Parse dtype
|
| 97 |
+
dtype_map = {
|
| 98 |
+
"float16": torch.float16,
|
| 99 |
+
"bfloat16": torch.bfloat16,
|
| 100 |
+
"float32": torch.float32,
|
| 101 |
+
}
|
| 102 |
+
dtype = dtype_map[args.dtype]
|
| 103 |
+
|
| 104 |
+
# Parse formats
|
| 105 |
+
formats = [f.strip() for f in args.formats.split(",")]
|
| 106 |
+
|
| 107 |
+
print(f"InteriorFusion {args.model_size}")
|
| 108 |
+
print(f" Device: {args.device}")
|
| 109 |
+
print(f" DType: {args.dtype}")
|
| 110 |
+
print(f" Input: {args.image}")
|
| 111 |
+
print(f" Output: {args.output}")
|
| 112 |
+
print(f" Formats: {formats}")
|
| 113 |
+
print()
|
| 114 |
+
|
| 115 |
+
# Load pipeline
|
| 116 |
+
print("Loading pipeline...")
|
| 117 |
+
pipeline = InteriorFusionPipeline(
|
| 118 |
+
model_size=args.model_size,
|
| 119 |
+
device=args.device,
|
| 120 |
+
dtype=dtype,
|
| 121 |
+
use_pbr=not args.no_pbr,
|
| 122 |
+
use_gaussian_splatting=not args.no_gaussian,
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
# Load image
|
| 126 |
+
print("Loading image...")
|
| 127 |
+
image = Image.open(args.image).convert("RGB")
|
| 128 |
+
print(f" Size: {image.size}")
|
| 129 |
+
|
| 130 |
+
# Generate
|
| 131 |
+
print("\nGenerating 3D scene...")
|
| 132 |
+
output = pipeline(
|
| 133 |
+
image=image,
|
| 134 |
+
room_type_hint=args.room_type,
|
| 135 |
+
style_hint=args.style,
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
# Export
|
| 139 |
+
print("\nExporting...")
|
| 140 |
+
output.export_all(args.output)
|
| 141 |
+
|
| 142 |
+
# Print results
|
| 143 |
+
print(f"\n{'='*50}")
|
| 144 |
+
print("Generation Complete!")
|
| 145 |
+
print(f"{'='*50}")
|
| 146 |
+
print(f" Time: {output.processing_time:.1f}s")
|
| 147 |
+
print(f" Room type: {output.room_type}")
|
| 148 |
+
print(f" Style: {output.style}")
|
| 149 |
+
print(f" Objects: {len(output.object_meshes)}")
|
| 150 |
+
print(f" Materials: {len(output.pbr_materials)}")
|
| 151 |
+
print()
|
| 152 |
+
|
| 153 |
+
# Export paths
|
| 154 |
+
if output.glb_path:
|
| 155 |
+
print(f" GLB: {output.glb_path}")
|
| 156 |
+
if output.fbx_path:
|
| 157 |
+
print(f" FBX: {output.fbx_path}")
|
| 158 |
+
if output.obj_path:
|
| 159 |
+
print(f" OBJ: {output.obj_path}")
|
| 160 |
+
if output.usdz_path:
|
| 161 |
+
print(f" USDZ: {output.usdz_path}")
|
| 162 |
+
if output.ply_path:
|
| 163 |
+
print(f" PLY (3DGS): {output.ply_path}")
|
| 164 |
+
|
| 165 |
+
if args.interactive:
|
| 166 |
+
print("\nInteractive editing not yet implemented in CLI.")
|
| 167 |
+
print("Use the Gradio app for interactive editing.")
|
| 168 |
+
|
| 169 |
+
print(f"\nDone!")
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
if __name__ == "__main__":
|
| 173 |
+
main()
|