Spaces:
Running on Zero
Running on Zero
Use existing MOSS Base and Next4 for depth-guided composition
Browse filesFiles changed (4)
- README.md+2-2
- app.py+6-4
- composition.py+4-4
- settings.py+1-1
11 unmodified lines1213141516171811 unmodified lines3031323334353611 unmodified lines- Comfy-Org/MoGe- SumomoLee/MOSS-Image-Base-LoRA-r96-next4preload_from_hub:- Comfy-Org/MOSS-Image diffusion_models/moss_image_base_bf16.safetensors,diffusion_models/moss_image_sft_int8_convrot.safetensors,text_encoders/qwen3.5_9b_bf16.safetensors,vae/flux2-vae_small.safetensors,loras/moss_image_color_depth_control.safetensors 2929efe3cdd506c0a430bcfca70a9a8d805cc095- Comfy-Org/MoGe geometry_estimation/moge_3_vitg_fp16.safetensors 1484985258ba7ef45c314144fcf0e90924ffbf44---11 unmodified lines### 构图参考本地工具选择「构图参考」并载入参考图。MOSS-Image SFT 通过 MoGe 3 输出的深度图或轮廓图保持空间结构,从噪声开始按提示词生成。默认使用深度、控制强度 `1.0`、控制结束比例 `0.60`、25 步、CFG 3。改变人物轮廓时可缩短控制时间,或切换到「轮廓」。输出比例与参考图不同时会居中裁剪。可用「按参考图比例」对齐取景。Kaggle 匿名调用 `/generate_from_composition`,每张图提交一个私有 Notebook 版本。PNG 保存有效采样参数、参考图校验值和控制参数。本地工具可从 PNG 恢复设置并复用本机的参考图副本。11 unmodified lines1213141516171811 unmodified lines3031323334353611 unmodified lines- Comfy-Org/MoGe- SumomoLee/MOSS-Image-Base-LoRA-r96-next4preload_from_hub:- Comfy-Org/MOSS-Image diffusion_models/moss_image_base_bf16.safetensors,text_encoders/qwen3.5_9b_bf16.safetensors,vae/flux2-vae_small.safetensors,loras/moss_image_color_depth_control.safetensors 2929efe3cdd506c0a430bcfca70a9a8d805cc095- Comfy-Org/MoGe geometry_estimation/moge_3_vitg_fp16.safetensors 1484985258ba7ef45c314144fcf0e90924ffbf44---11 unmodified lines### 构图参考本地工具选择「构图参考」并载入参考图。使用现有 MOSS-Image Base 和 Next4(强度 `1.0`),再加载构图控制适配器。MoGe 3 输出的深度图或轮廓图约束空间结构,从噪声开始按提示词生成。默认使用深度、控制强度 `1.0`、控制结束比例 `0.60`、25 步、CFG 3。改变人物轮廓时可缩短控制时间,或切换到「轮廓」。输出比例与参考图不同时会居中裁剪。可用「按参考图比例」对齐取景。Kaggle 匿名调用 `/generate_from_composition`,每张图提交一个私有 Notebook 版本。PNG 保存有效采样参数、参考图校验值和控制参数。本地工具可从 PNG 恢复设置并复用本机的参考图副本。
11 unmodified lines1213141516171841 unmodified lines6061626364656667686981 unmodified lines15115215315415515615772 unmodified lines2302312322332342351 unmodified line23723823924024124224311 unmodified linesimport spacesimport gradio as grfrom composition import (CONTROL_ADAPTER, CONTROL_CFG, CONTROL_DEFAULTS, CONTROL_MODEL, CONTROL_STEPS,CONTROL_TYPES, GEOMETRY_MODEL, GEOMETRY_REV, composition_graph, control_settings)from huggingface_hub import hf_hub_downloadfrom png_metadata import save_replay_metadata41 unmodified linesprint(f"Ready: {category}", flush=True)ENCODER = GRAPH["4"]["inputs"]["clip_name"]VAE = GRAPH["9"]["inputs"]["vae_name"]for category, name in (("diffusion_models", GRAPH["1"]["inputs"]["unet_name"]),("text_encoders", ENCODER),("vae", VAE),):81 unmodified lineselse:negative_id = GRAPH["8"]["inputs"]["negative"][0]negative = GRAPH[negative_id]["inputs"]["text"]graph = composition_graph(prompt, negative, values, filename, ENCODER, VAE)return execute_workflow(graph, prompt, values)72 unmodified linesif not values.pop("prompt").strip():raise gr.Error("请输入正向提示词")values.pop("reference_image")try:values.update(control_settings(values))values = normalize({**DEFAULT, **values, **COMPOSITION_FIXED}, adapters)1 unmodified lineraise gr.Error(str(error)) from Nonewith reference_input(reference_image, values, "composition") as filename:try:link_model("diffusion_models", CONTROL_MODEL)link_model("loras", CONTROL_ADAPTER)link_model("geometry_estimation", GEOMETRY_MODEL, "Comfy-Org/MoGe", GEOMETRY_REV)except (OSError, ValueError) as error:11 unmodified lines1213141516171841 unmodified lines606162636465666768697081 unmodified lines15215315415515615715872 unmodified lines2312322332342352362372381 unmodified line24024124224324424511 unmodified linesimport spacesimport gradio as grfrom composition import (CONTROL_ADAPTER, CONTROL_CFG, CONTROL_DEFAULTS, CONTROL_STEPS,CONTROL_TYPES, GEOMETRY_MODEL, GEOMETRY_REV, composition_graph, control_settings)from huggingface_hub import hf_hub_downloadfrom png_metadata import save_replay_metadata41 unmodified linesprint(f"Ready: {category}", flush=True)BASE_LOADER = GRAPH["1"]["inputs"]ENCODER = GRAPH["4"]["inputs"]["clip_name"]VAE = GRAPH["9"]["inputs"]["vae_name"]for category, name in (("diffusion_models", BASE_LOADER["unet_name"]),("text_encoders", ENCODER),("vae", VAE),):81 unmodified lineselse:negative_id = GRAPH["8"]["inputs"]["negative"][0]negative = GRAPH[negative_id]["inputs"]["text"]graph = composition_graph(prompt, negative, values, filename, BASE_LOADER, adapters[values["lora"]], ENCODER, VAE)return execute_workflow(graph, prompt, values)72 unmodified linesif not values.pop("prompt").strip():raise gr.Error("请输入正向提示词")values.pop("reference_image")if COMPOSITION_FIXED["lora"] not in adapters:raise gr.Error("Space 暂时无法加载构图参考所用的 Next4 LoRA,请检查模型挂载。")try:values.update(control_settings(values))values = normalize({**DEFAULT, **values, **COMPOSITION_FIXED}, adapters)1 unmodified lineraise gr.Error(str(error)) from Nonewith reference_input(reference_image, values, "composition") as filename:try:link_model("loras", CONTROL_ADAPTER)link_model("geometry_estimation", GEOMETRY_MODEL, "Comfy-Org/MoGe", GEOMETRY_REV)except (OSError, ValueError) as error:
123456721 unmodified lines2930313233343536373815 unmodified lines545556575859607 unmodified lines6869707172import mathCONTROL_MODEL = "moss_image_sft_int8_convrot.safetensors"CONTROL_ADAPTER = "moss_image_color_depth_control.safetensors"GEOMETRY_MODEL = "moge_3_vitg_fp16.safetensors"GEOMETRY_REV = "1484985258ba7ef45c314144fcf0e90924ffbf44"21 unmodified linesreturn valuesdef composition_graph(prompt, negative, values, filename, encoder, vae):size = {"width": values["width"], "height": values["height"]}nodes = {"1": ("UNETLoader", {"unet_name": CONTROL_MODEL, "weight_dtype": "default"}),"2": ("CLIPLoader", {"clip_name": encoder, "type": "moss_image"}),"3": ("ModelSamplingAuraFlow", {"model": ["16", 0], "shift": 5, "sampling": "flow"}),"4": ("CLIPTextEncode", {"clip": ["2", 0], "text": prompt}),15 unmodified lines"model": ["12", 0], "scheduler": "simple", "steps": values["steps"], "denoise": 1,}),"14": ("SamplerER_SDE", {"solver_type": "ER-SDE", "max_stage": 3, "eta": 1, "s_noise": 1.05}),"15": ("LoraLoaderModelOnly", {"model": ["1", 0], "lora_name": CONTROL_ADAPTER, "strength_model": 1}),"16": ("TemporalScoreRescaling", {"model": ["15", 0], "tsr_k": 0.95, "tsr_sigma": 1}),"17": ("LoadImage", {"image": filename}),"18": ("ImageScale", {"image": ["17", 0], "upscale_method": "lanczos", "crop": "center", **size}),7 unmodified lines"batch_size": 1, "force_projection": True, "apply_mask": True, "refine_steps": 3,}),"22": ("MoGeRender", {"moge_geometry": ["21", 0], "output": values["control_type"]}),}return {key: {"class_type": name, "inputs": inputs} for key, (name, inputs) in nodes.items()}12345621 unmodified lines2829303132333435363715 unmodified lines535455565758597 unmodified lines676869707172import mathCONTROL_ADAPTER = "moss_image_color_depth_control.safetensors"GEOMETRY_MODEL = "moge_3_vitg_fp16.safetensors"GEOMETRY_REV = "1484985258ba7ef45c314144fcf0e90924ffbf44"21 unmodified linesreturn valuesdef composition_graph(prompt, negative, values, filename, base_loader, style_lora, encoder, vae):size = {"width": values["width"], "height": values["height"]}nodes = {"1": ("UNETLoader", dict(base_loader)),"2": ("CLIPLoader", {"clip_name": encoder, "type": "moss_image"}),"3": ("ModelSamplingAuraFlow", {"model": ["16", 0], "shift": 5, "sampling": "flow"}),"4": ("CLIPTextEncode", {"clip": ["2", 0], "text": prompt}),15 unmodified lines"model": ["12", 0], "scheduler": "simple", "steps": values["steps"], "denoise": 1,}),"14": ("SamplerER_SDE", {"solver_type": "ER-SDE", "max_stage": 3, "eta": 1, "s_noise": 1.05}),"15": ("LoraLoaderModelOnly", {"model": ["23", 0], "lora_name": CONTROL_ADAPTER, "strength_model": 1}),"16": ("TemporalScoreRescaling", {"model": ["15", 0], "tsr_k": 0.95, "tsr_sigma": 1}),"17": ("LoadImage", {"image": filename}),"18": ("ImageScale", {"image": ["17", 0], "upscale_method": "lanczos", "crop": "center", **size}),7 unmodified lines"batch_size": 1, "force_projection": True, "apply_mask": True, "refine_steps": 3,}),"22": ("MoGeRender", {"moge_geometry": ["21", 0], "output": values["control_type"]}),"23": ("LoraLoaderModelOnly", {"model": ["1", 0], "lora_name": style_lora, "strength_model": values["strength"]}),}return {key: {"class_type": name, "inputs": inputs} for key, (name, inputs) in nodes.items()}
8 unmodified lines91011121314158 unmodified linesSCHEDULERS = ["sgm_uniform", "normal", "simple", "karras", "exponential", "beta"]NEGATIVE_MODES = ["沿用工作流", "自定义"]COMPOSITION_FIXED = {"lora": NO_LORA, "strength": 0, "sampler": "er_sde", "scheduler": "simple", "shift": 5,"rescale": 0, "single_layers": "24", "double_layers": "", "slg_start": 0, "slg_end": 1,}8 unmodified lines91011121314158 unmodified linesSCHEDULERS = ["sgm_uniform", "normal", "simple", "karras", "exponential", "beta"]NEGATIVE_MODES = ["沿用工作流", "自定义"]COMPOSITION_FIXED = {"lora": "Next4", "strength": 1, "sampler": "er_sde", "scheduler": "simple", "shift": 5,"rescale": 0, "single_layers": "24", "double_layers": "", "slg_start": 0, "slg_end": 1,}
README.md+2-2
app.py+6-4
composition.py+4-4
settings.py+1-1