Spaces:
Sleeping
Sleeping
| # 🛠️ Claude's Local Pipeline Reference (DarkMedia-X) | |
| ## 1. SDXL Base Generator (Torch/Diffusers) | |
| ```python | |
| import torch | |
| from diffusers import DiffusionPipeline | |
| model_id = "stabilityai/stable-diffusion-xl-base-1.0" | |
| pipe = DiffusionPipeline.from_pretrained( | |
| model_id, | |
| torch_dtype=torch.float16, | |
| variant="fp16", | |
| use_safetensors=True | |
| ).to("cuda") | |
| def generate_local_image(prompt, output_path): | |
| image = pipe( | |
| prompt=prompt, | |
| num_inference_steps=30, | |
| guidance_scale=7.5 | |
| ).images[0] | |
| image.save(output_path) | |
| ``` | |
| ## 2. Depth Anything V2 (Relief 3D) | |
| ```python | |
| import torch | |
| from transformers import pipeline | |
| from PIL import Image | |
| depth_pipe = pipeline( | |
| task="depth-estimation", | |
| model="depth-anything/Depth-Anything-V2-Base-hf", | |
| device=0 | |
| ) | |
| def generate_depth_map(img_path, depth_path): | |
| image = Image.open(img_path) | |
| depth_result = depth_pipe(image)["depth"] | |
| depth_result.save(depth_path) | |
| ``` | |
| ## 3. Blender 3D Scene Setup (Relief mapping) | |
| ```python | |
| import bpy | |
| import sys | |
| # 🛠️ Usage: blender --background --python this_script.py -- color.png depth.png output.png | |
| argv = sys.argv[sys.argv.index("--") + 1:] | |
| img_path, depth_path, out_path = argv | |
| bpy.ops.wm.read_factory_settings(use_empty=True) | |
| bpy.ops.mesh.primitive_plane_add(size=10) | |
| plane = bpy.context.object | |
| # 🛠️ Relief | |
| subdiv = plane.modifiers.new(name="Subdiv", type='SUBSURF') | |
| subdiv.subdivision_type = 'SIMPLE' | |
| subdiv.levels = 6 | |
| tex = bpy.data.textures.new('DepthTex', type='IMAGE') | |
| tex.image = bpy.data.images.load(depth_path) | |
| disp = plane.modifiers.new("Displace", type='DISPLACE') | |
| disp.texture = tex | |
| disp.strength = 1.5 | |
| # 🛠️ Material | |
| mat = bpy.data.materials.new(name="ImageMat") | |
| mat.use_nodes = True | |
| nodes = mat.node_tree.nodes | |
| links = mat.node_tree.links | |
| nodes.clear() | |
| node_tex = nodes.new(type='ShaderNodeTexImage') | |
| node_tex.image = bpy.data.images.load(img_path) | |
| node_bsdf = nodes.new(type='ShaderNodeBsdfPrincipled') | |
| node_out = nodes.new(type='ShaderNodeOutputMaterial') | |
| links.new(node_tex.outputs['Color'], node_bsdf.inputs['Base Color']) | |
| links.new(node_bsdf.outputs['BSDF'], node_out.inputs['Surface']) | |
| plane.data.materials.append(mat) | |
| bpy.context.scene.render.filepath = out_path | |
| bpy.ops.render.render(write_still=True) | |
| ``` | |