Spaces:
Paused
Paused
Download services/refine/profiles.py from modventures/room-visualizer: direct link, hf CLI and curl.
- Browser
- Download file 21.7 kB
-
https://huggingface.co/spaces/modventures/room-visualizer/resolve/main/services/refine/profiles.py
- Command line
-
hf download hf://spaces/modventures/room-visualizer/services/refine/profiles.py
-
curl -L -o profiles.py https://huggingface.co/spaces/modventures/room-visualizer/resolve/main/services/refine/profiles.py
21.7 kB
| """Per-material diffusion tuning and prompt text. | |
| Structure | |
| --------- | |
| Each entry in MATERIALS carries the numeric tuning for that material -- how | |
| much of the image diffusion may change (diffusion_strength), how hard it is | |
| pushed toward the prompt (guidance), how strongly depth constrains it | |
| (controlnet), and the step count. Those numbers are the tuned part and are | |
| shared between floors and walls: marble responds the same way to diffusion | |
| whichever plane it sits on. | |
| What differs by plane is the *wording*. SDXL follows prompts literally, so | |
| telling it to preserve "plank positions" and "floor contact shadows" while it | |
| looks at a wall makes it fight the geometry. Every material therefore has a | |
| "floor" and a "wall" prompt pair under one set of numbers. | |
| The floor text is the tuned original and should be treated as such. The wall | |
| text mirrors it clause for clause -- same preserve-the-product framing, same | |
| realism vocabulary -- with floor nouns swapped for wall nouns and the | |
| floor-specific negatives (contact shadows, plank layouts, mirror floor) | |
| replaced by wall-specific ones. | |
| """ | |
| from __future__ import annotations | |
| MASK_THRESHOLD = 128 | |
| # Diffusion is kept away from the mask boundary; see masks.prepare_safe_diffusion_mask. | |
| DIFFUSION_EDGE_GUARD = 8 | |
| # Lighting transfer | |
| LIGHTING_BLUR_SIGMA = 35 | |
| LIGHTING_TRANSFER_STRENGTH = 0.50 | |
| MIN_LIGHT_RATIO = 0.74 | |
| MAX_LIGHT_RATIO = 1.14 | |
| # Shadow transfer | |
| SHADOW_BLUR_SIGMA = 22 | |
| SHADOW_TRANSFER_STRENGTH = 0.58 | |
| MIN_SHADOW_RATIO = 0.58 | |
| # Shadow restoration after diffusion, gentler than the pre-pass above. | |
| POST_SHADOW_BLUR_SIGMA = 16 | |
| POST_SHADOW_TRANSFER_STRENGTH = 0.25 | |
| # Post-diffusion detail recovery, per material family. | |
| DETAIL_RECOVERY = { | |
| "wood": {"fine": 0.20, "pattern": 0.42}, | |
| "marble": {"fine": 0.14, "pattern": 0.32}, | |
| "default": {"fine": 0.15, "pattern": 0.25}, | |
| } | |
| CAMERA_NOISE_SIGMA = 0.20 | |
| SURFACE_KINDS = ("floor", "wall") | |
| BASE_PROMPTS = { | |
| "floor": """ | |
| real camera photograph of an existing interior, | |
| the flooring shown in the input is already completely finished | |
| and is the exact final flooring product, | |
| preserve the exact existing flooring, | |
| preserve exact floor pattern, | |
| preserve exact material design, | |
| preserve exact veins, | |
| preserve exact plank positions, | |
| preserve exact grain, | |
| preserve exact tile positions, | |
| preserve exact grout positions, | |
| preserve exact floor perspective, | |
| preserve exact scale, | |
| preserve exact orientation, | |
| preserve exact colors, | |
| do not redesign the floor, | |
| do not replace the floor, | |
| do not generate another flooring product, | |
| only reproduce realistic photographic material response, | |
| natural inherited room illumination, | |
| subtle realistic exposure variation, | |
| subtle natural surface roughness, | |
| soft realistic reflections, | |
| soft indirect illumination, | |
| subtle ambient occlusion, | |
| natural floor contact shadows, | |
| soft photographic highlight response, | |
| real optical camera photograph | |
| """, | |
| "wall": """ | |
| real camera photograph of an existing interior, | |
| the wall surface shown in the input is already completely finished | |
| and is the exact final wall covering product, | |
| preserve the exact existing wall surface, | |
| preserve exact wall pattern, | |
| preserve exact material design, | |
| preserve exact veins, | |
| preserve exact panel positions, | |
| preserve exact grain, | |
| preserve exact tile positions, | |
| preserve exact grout positions, | |
| preserve exact wall perspective, | |
| preserve exact scale, | |
| preserve exact orientation, | |
| preserve exact colors, | |
| do not redesign the wall, | |
| do not replace the wall covering, | |
| do not generate another wall product, | |
| only reproduce realistic photographic material response, | |
| natural inherited room illumination, | |
| subtle realistic exposure variation, | |
| subtle natural surface roughness, | |
| soft realistic reflections, | |
| soft indirect illumination, | |
| subtle ambient occlusion, | |
| soft contact shading where the wall meets floor and ceiling, | |
| soft photographic highlight response, | |
| real optical camera photograph | |
| """, | |
| } | |
| BASE_NEGATIVES = { | |
| "floor": """ | |
| new flooring, | |
| different flooring, | |
| replacement floor, | |
| redesigned floor, | |
| changed floor pattern, | |
| new planks, | |
| new boards, | |
| new tiles, | |
| new marble veins, | |
| new wood grain, | |
| new seams, | |
| new grout, | |
| parquet, | |
| herringbone, | |
| checkerboard, | |
| square wood tiles, | |
| decorative plank layout, | |
| basket weave, | |
| mosaic wood, | |
| generated floor, | |
| procedural texture, | |
| artificial pattern, | |
| synthetic floor, | |
| cgi, | |
| 3d render, | |
| plastic surface, | |
| mask seam, | |
| edge halo, | |
| black border, | |
| white border, | |
| dark outline, | |
| bright outline, | |
| floor bleeding into wall, | |
| floor bleeding into furniture, | |
| floor bleeding into doorway, | |
| changed wall, | |
| changed furniture, | |
| changed television, | |
| changed cabinet, | |
| changed speaker, | |
| changed chair | |
| """, | |
| "wall": """ | |
| new wall covering, | |
| different wall covering, | |
| replacement wall, | |
| redesigned wall, | |
| changed wall pattern, | |
| new panels, | |
| new boards, | |
| new tiles, | |
| new marble veins, | |
| new wood grain, | |
| new seams, | |
| new grout, | |
| wallpaper pattern, | |
| decorative mural, | |
| painted feature wall, | |
| brick pattern, | |
| stone cladding pattern, | |
| mosaic feature panel, | |
| generated wall, | |
| procedural texture, | |
| artificial pattern, | |
| synthetic wall, | |
| cgi, | |
| 3d render, | |
| plastic surface, | |
| mask seam, | |
| edge halo, | |
| black border, | |
| white border, | |
| dark outline, | |
| bright outline, | |
| wall bleeding into ceiling, | |
| wall bleeding into floor, | |
| wall bleeding into furniture, | |
| wall bleeding into window, | |
| wall bleeding into doorway, | |
| changed ceiling, | |
| changed floor, | |
| changed furniture, | |
| changed television, | |
| changed cabinet, | |
| changed artwork, | |
| changed window frame | |
| """, | |
| } | |
| MATERIALS: dict[str, dict] = { | |
| "marble": { | |
| "diffusion_strength": 0.46, | |
| "guidance": 3.0, | |
| "controlnet": 0.25, | |
| "steps": 28, | |
| "microdetail": 0.12, | |
| "local_contrast": 0.045, | |
| "floor": { | |
| "prompt": """ | |
| existing installed natural marble flooring, | |
| preserve the recognizable marble design, | |
| preserve the major existing marble veins, | |
| preserve the flooring perspective, | |
| preserve flooring placement and geometry, | |
| preserve overall marble colors, | |
| preserve clearly visible existing marble veining, | |
| preserve medium-scale mineral pattern definition, | |
| natural flowing veins with soft organic transitions, | |
| veins should remain clearly defined without becoming harsh, | |
| preserve subtle tonal boundaries within the marble, | |
| do not blur or wash out the marble pattern, | |
| convert the existing projected flooring into a physically realistic | |
| photographed marble surface, | |
| real polished stone surface, | |
| natural microscopic stone texture, | |
| subtle surface roughness variation, | |
| realistic polished marble reflections, | |
| soft broken reflections from the room, | |
| natural reflection falloff with viewing angle, | |
| subtle local exposure variations, | |
| realistic indirect illumination, | |
| realistic material response, | |
| soft contact shading, | |
| natural ambient occlusion, | |
| subtle imperfections in polish, | |
| fine photographic material detail, | |
| real marble photographed with a real camera | |
| """, | |
| "negative": """ | |
| different marble product, | |
| completely different marble pattern, | |
| major new veins, | |
| dramatic new veins, | |
| different flooring geometry, | |
| different perspective, | |
| different tile layout, | |
| changed room, | |
| changed furniture, | |
| plastic marble, | |
| flat texture, | |
| uniform lighting, | |
| uniform surface, | |
| cgi, | |
| 3d render, | |
| synthetic texture, | |
| overly glossy floor, | |
| mirror floor, | |
| fake reflections | |
| """, | |
| }, | |
| "wall": { | |
| "prompt": """ | |
| existing installed natural marble wall cladding, | |
| preserve the recognizable marble design, | |
| preserve the major existing marble veins, | |
| preserve the wall perspective, | |
| preserve slab placement and geometry, | |
| preserve overall marble colors, | |
| preserve clearly visible existing marble veining, | |
| preserve medium-scale mineral pattern definition, | |
| natural flowing veins with soft organic transitions, | |
| veins should remain clearly defined without becoming harsh, | |
| preserve subtle tonal boundaries within the marble, | |
| do not blur or wash out the marble pattern, | |
| convert the existing projected wall covering into a physically realistic | |
| photographed marble surface, | |
| real polished stone surface, | |
| natural microscopic stone texture, | |
| subtle surface roughness variation, | |
| realistic polished marble reflections, | |
| soft grazing reflections along the wall, | |
| natural reflection falloff with viewing angle, | |
| subtle local exposure variations, | |
| realistic indirect illumination, | |
| realistic material response, | |
| soft contact shading at wall edges, | |
| natural ambient occlusion in corners, | |
| subtle imperfections in polish, | |
| fine photographic material detail, | |
| real marble wall photographed with a real camera | |
| """, | |
| "negative": """ | |
| different marble product, | |
| completely different marble pattern, | |
| major new veins, | |
| dramatic new veins, | |
| different wall geometry, | |
| different perspective, | |
| different slab layout, | |
| changed room, | |
| changed furniture, | |
| plastic marble, | |
| flat texture, | |
| uniform lighting, | |
| uniform surface, | |
| cgi, | |
| 3d render, | |
| synthetic texture, | |
| overly glossy wall, | |
| mirror wall, | |
| fake reflections | |
| """, | |
| }, | |
| }, | |
| "wood": { | |
| "diffusion_strength": 0.36, | |
| "guidance": 3.0, | |
| "controlnet": 0.15, | |
| "steps": 24, | |
| "microdetail": 0.12, | |
| "local_contrast": 0.015, | |
| "floor": { | |
| "prompt": """ | |
| existing real wooden floor, | |
| existing flooring product is already correct, | |
| preserve every exact existing plank, | |
| preserve exact plank positions, | |
| preserve plank widths, | |
| preserve plank lengths, | |
| preserve plank direction, | |
| preserve clearly visible existing wood grain, | |
| preserve medium-scale wood grain patterns, | |
| preserve grain lines and tonal variation, | |
| preserve knots and natural wood character when present, | |
| wood grain must remain visually defined, | |
| do not smooth away the wood grain, | |
| do not blur grain boundaries, | |
| keep the wooden texture, | |
| realistic natural timber microtexture, | |
| natural satin material response, | |
| subtle room reflections, | |
| real wooden flooring photographed indoors | |
| """, | |
| "negative": """ | |
| new wood floor, | |
| different wood, | |
| new planks, | |
| different planks, | |
| new wood grain, | |
| changed wood grain, | |
| parquet, | |
| herringbone, | |
| checkerboard, | |
| square wood tiles, | |
| decorative plank layout, | |
| warped boards, | |
| fake grain, | |
| plastic wood, | |
| blurred wood grain, | |
| washed out grain, | |
| smoothed wood texture, | |
| featureless wood, | |
| soft blurry grain, | |
| lost wood grain, | |
| """, | |
| }, | |
| "wall": { | |
| "prompt": """ | |
| existing real wood wall panelling, | |
| existing wall product is already correct, | |
| preserve every exact existing board, | |
| preserve exact board positions, | |
| preserve board widths, | |
| preserve board lengths, | |
| preserve board direction, | |
| preserve clearly visible existing wood grain, | |
| preserve medium-scale wood grain patterns, | |
| preserve grain lines and tonal variation, | |
| preserve knots and natural wood character when present, | |
| wood grain must remain visually defined, | |
| do not smooth away the wood grain, | |
| do not blur grain boundaries, | |
| keep the wooden texture, | |
| realistic natural timber microtexture, | |
| natural satin material response, | |
| subtle grazing light along the panelling, | |
| real wood wall panelling photographed indoors | |
| """, | |
| "negative": """ | |
| new wood panelling, | |
| different wood, | |
| new boards, | |
| different boards, | |
| new wood grain, | |
| changed wood grain, | |
| slatted acoustic panel, | |
| shiplap pattern, | |
| chevron panelling, | |
| decorative board layout, | |
| warped boards, | |
| fake grain, | |
| plastic wood, | |
| blurred wood grain, | |
| washed out grain, | |
| smoothed wood texture, | |
| featureless wood, | |
| soft blurry grain, | |
| lost wood grain, | |
| """, | |
| }, | |
| }, | |
| "porcelain": { | |
| "diffusion_strength": 0.09, | |
| "guidance": 1.8, | |
| "controlnet": 0.15, | |
| "steps": 24, | |
| "microdetail": 0.025, | |
| "local_contrast": 0.010, | |
| "floor": { | |
| "prompt": """ | |
| existing real porcelain flooring, | |
| preserve exact tile product, | |
| preserve exact tile pattern, | |
| preserve exact tile positions, | |
| preserve exact grout, | |
| preserve exact tile dimensions, | |
| preserve exact colors, | |
| very subtle ceramic texture, | |
| restrained realistic reflection, | |
| real porcelain photographed indoors | |
| """, | |
| "negative": """ | |
| new tiles, | |
| different tiles, | |
| changed tiles, | |
| new grout, | |
| changed grout, | |
| new tile pattern, | |
| checkerboard, | |
| different flooring, | |
| plastic porcelain, | |
| mirror floor | |
| """, | |
| }, | |
| "wall": { | |
| "prompt": """ | |
| existing real porcelain wall tiling, | |
| preserve exact tile product, | |
| preserve exact tile pattern, | |
| preserve exact tile positions, | |
| preserve exact grout, | |
| preserve exact tile dimensions, | |
| preserve exact colors, | |
| very subtle ceramic texture, | |
| restrained realistic reflection, | |
| real porcelain wall tiling photographed indoors | |
| """, | |
| "negative": """ | |
| new tiles, | |
| different tiles, | |
| changed tiles, | |
| new grout, | |
| changed grout, | |
| new tile pattern, | |
| subway tile pattern, | |
| different wall covering, | |
| plastic porcelain, | |
| mirror wall | |
| """, | |
| }, | |
| }, | |
| "ceramic": { | |
| "diffusion_strength": 0.09, | |
| "guidance": 1.8, | |
| "controlnet": 0.15, | |
| "steps": 24, | |
| "microdetail": 0.03, | |
| "local_contrast": 0.012, | |
| "floor": { | |
| "prompt": """ | |
| existing real ceramic flooring, | |
| preserve exact tile layout, | |
| preserve exact tile design, | |
| preserve exact grout positions, | |
| preserve exact colors, | |
| subtle ceramic microtexture, | |
| natural indoor material response | |
| """, | |
| "negative": """ | |
| new tiles, | |
| different tiles, | |
| new grout, | |
| changed grout, | |
| new floor pattern, | |
| plastic ceramic, | |
| mirror surface | |
| """, | |
| }, | |
| "wall": { | |
| "prompt": """ | |
| existing real ceramic wall tiling, | |
| preserve exact tile layout, | |
| preserve exact tile design, | |
| preserve exact grout positions, | |
| preserve exact colors, | |
| subtle ceramic microtexture, | |
| natural indoor material response | |
| """, | |
| "negative": """ | |
| new tiles, | |
| different tiles, | |
| new grout, | |
| changed grout, | |
| new wall pattern, | |
| subway tile pattern, | |
| plastic ceramic, | |
| mirror surface | |
| """, | |
| }, | |
| }, | |
| "stone": { | |
| "diffusion_strength": 0.10, | |
| "guidance": 1.8, | |
| "controlnet": 0.15, | |
| "steps": 24, | |
| "microdetail": 0.04, | |
| "local_contrast": 0.015, | |
| "floor": { | |
| "prompt": """ | |
| existing real natural stone flooring, | |
| preserve exact stone pattern, | |
| preserve exact mineral structure, | |
| preserve exact existing texture, | |
| subtle natural pores, | |
| natural stone response, | |
| real stone photographed indoors | |
| """, | |
| "negative": """ | |
| new stone pattern, | |
| new cracks, | |
| new veins, | |
| different stone, | |
| changed texture layout, | |
| artificial stone, | |
| plastic stone | |
| """, | |
| }, | |
| "wall": { | |
| "prompt": """ | |
| existing real natural stone wall cladding, | |
| preserve exact stone pattern, | |
| preserve exact mineral structure, | |
| preserve exact existing texture, | |
| subtle natural pores, | |
| natural stone response, | |
| real stone wall photographed indoors | |
| """, | |
| "negative": """ | |
| new stone pattern, | |
| new cracks, | |
| new veins, | |
| different stone, | |
| changed texture layout, | |
| dry stone wall, | |
| stacked stone pattern, | |
| artificial stone, | |
| plastic stone | |
| """, | |
| }, | |
| }, | |
| "laminate": { | |
| "diffusion_strength": 0.09, | |
| "guidance": 1.8, | |
| "controlnet": 0.15, | |
| "steps": 24, | |
| "microdetail": 0.03, | |
| "local_contrast": 0.012, | |
| "floor": { | |
| "prompt": """ | |
| existing laminate flooring, | |
| preserve exact existing flooring product, | |
| preserve exact plank positions, | |
| preserve exact printed pattern, | |
| preserve exact direction, | |
| subtle embossed surface detail, | |
| natural satin indoor response | |
| """, | |
| "negative": """ | |
| new laminate, | |
| new boards, | |
| changed boards, | |
| new floor pattern, | |
| parquet, | |
| herringbone, | |
| checkerboard, | |
| square tiles, | |
| plastic appearance | |
| """, | |
| }, | |
| "wall": { | |
| "prompt": """ | |
| existing laminate wall panelling, | |
| preserve exact existing panel product, | |
| preserve exact panel positions, | |
| preserve exact printed pattern, | |
| preserve exact direction, | |
| subtle embossed surface detail, | |
| natural satin indoor response | |
| """, | |
| "negative": """ | |
| new laminate, | |
| new panels, | |
| changed panels, | |
| new wall pattern, | |
| shiplap pattern, | |
| chevron panelling, | |
| square tiles, | |
| plastic appearance | |
| """, | |
| }, | |
| }, | |
| "vinyl": { | |
| "diffusion_strength": 0.09, | |
| "guidance": 1.8, | |
| "controlnet": 0.15, | |
| "steps": 24, | |
| "microdetail": 0.025, | |
| "local_contrast": 0.010, | |
| "floor": { | |
| "prompt": """ | |
| existing vinyl flooring, | |
| preserve exact existing floor design, | |
| preserve exact floor geometry, | |
| preserve exact pattern, | |
| subtle realistic embossing, | |
| restrained material response, | |
| real vinyl photographed indoors | |
| """, | |
| "negative": """ | |
| new vinyl pattern, | |
| changed floor, | |
| different floor design, | |
| plastic toy surface, | |
| excessive gloss | |
| """, | |
| }, | |
| "wall": { | |
| "prompt": """ | |
| existing vinyl wall covering, | |
| preserve exact existing wall design, | |
| preserve exact wall geometry, | |
| preserve exact pattern, | |
| subtle realistic embossing, | |
| restrained material response, | |
| real vinyl wall covering photographed indoors | |
| """, | |
| "negative": """ | |
| new vinyl pattern, | |
| changed wall, | |
| different wall design, | |
| wallpaper seam, | |
| plastic toy surface, | |
| excessive gloss | |
| """, | |
| }, | |
| }, | |
| "carpet": { | |
| "diffusion_strength": 0.12, | |
| "guidance": 2.0, | |
| "controlnet": 0.14, | |
| "steps": 24, | |
| "microdetail": 0.08, | |
| "local_contrast": 0.025, | |
| "floor": { | |
| "prompt": """ | |
| existing real carpet, | |
| preserve exact carpet product, | |
| preserve exact carpet pattern, | |
| preserve exact carpet color, | |
| subtle natural fibers, | |
| subtle textile microstructure, | |
| real carpet photographed indoors | |
| """, | |
| "negative": """ | |
| new carpet, | |
| different carpet, | |
| changed pattern, | |
| changed color, | |
| plastic fibers, | |
| artificial carpet | |
| """, | |
| }, | |
| "wall": { | |
| "prompt": """ | |
| existing real textile wall covering, | |
| preserve exact textile product, | |
| preserve exact textile pattern, | |
| preserve exact textile color, | |
| subtle natural fibers, | |
| subtle woven microstructure, | |
| real fabric wall covering photographed indoors | |
| """, | |
| "negative": """ | |
| new textile, | |
| different textile, | |
| changed pattern, | |
| changed color, | |
| hanging curtain folds, | |
| draped fabric, | |
| plastic fibers, | |
| artificial fabric | |
| """, | |
| }, | |
| }, | |
| "concrete": { | |
| "diffusion_strength": 0.10, | |
| "guidance": 1.8, | |
| "controlnet": 0.15, | |
| "steps": 24, | |
| "microdetail": 0.04, | |
| "local_contrast": 0.015, | |
| "floor": { | |
| "prompt": """ | |
| existing real concrete flooring, | |
| preserve exact existing concrete appearance, | |
| preserve exact tonal pattern, | |
| fine natural mineral texture, | |
| tiny natural pores, | |
| natural matte response, | |
| real concrete photographed indoors | |
| """, | |
| "negative": """ | |
| new concrete texture, | |
| new cracks, | |
| new stains, | |
| different concrete, | |
| changed floor, | |
| plastic concrete | |
| """, | |
| }, | |
| "wall": { | |
| "prompt": """ | |
| existing real concrete wall surface, | |
| preserve exact existing concrete appearance, | |
| preserve exact tonal pattern, | |
| fine natural mineral texture, | |
| tiny natural pores, | |
| natural matte response, | |
| real concrete wall photographed indoors | |
| """, | |
| "negative": """ | |
| new concrete texture, | |
| new cracks, | |
| new stains, | |
| different concrete, | |
| board formed pattern, | |
| tie hole pattern, | |
| changed wall, | |
| plastic concrete | |
| """, | |
| }, | |
| }, | |
| "generic": { | |
| "diffusion_strength": 0.09, | |
| "guidance": 1.8, | |
| "controlnet": 0.15, | |
| "steps": 24, | |
| "microdetail": 0.025, | |
| "local_contrast": 0.010, | |
| "floor": { | |
| "prompt": """ | |
| existing real flooring, | |
| the flooring product is already completely correct, | |
| preserve exact flooring design, | |
| preserve exact geometry, | |
| preserve exact pattern, | |
| preserve exact texture layout, | |
| subtle realistic material response, | |
| real floor photographed inside a real room | |
| """, | |
| "negative": """ | |
| new floor, | |
| different floor, | |
| changed floor, | |
| new floor pattern, | |
| changed texture, | |
| synthetic flooring, | |
| plastic material | |
| """, | |
| }, | |
| "wall": { | |
| "prompt": """ | |
| existing real wall surface, | |
| the wall product is already completely correct, | |
| preserve exact wall design, | |
| preserve exact geometry, | |
| preserve exact pattern, | |
| preserve exact texture layout, | |
| subtle realistic material response, | |
| real wall photographed inside a real room | |
| """, | |
| "negative": """ | |
| new wall, | |
| different wall, | |
| changed wall, | |
| new wall pattern, | |
| changed texture, | |
| synthetic wall covering, | |
| plastic material | |
| """, | |
| }, | |
| }, | |
| } | |
| def normalize_material_type(material_type: str | None) -> str: | |
| """Map an arbitrary catalogue value onto a known profile key. | |
| Unknown materials fall back to "generic" rather than raising: a tile the | |
| catalogue has not annotated yet should still refine, just conservatively. | |
| """ | |
| if not material_type: | |
| return "generic" | |
| key = str(material_type).strip().lower() | |
| return key if key in MATERIALS else "generic" | |
| def normalize_surface_kind(surface_kind: str | None) -> str: | |
| key = str(surface_kind or "floor").strip().lower() | |
| return key if key in SURFACE_KINDS else "floor" | |
| def detail_recovery_for(material_type: str | None) -> dict: | |
| return DETAIL_RECOVERY.get(normalize_material_type(material_type), DETAIL_RECOVERY["default"]) | |
| def build_prompts( | |
| material_type: str | None, | |
| surface_kind: str | None = "floor", | |
| material_description: str = "", | |
| ) -> tuple[str, str, dict]: | |
| """Return (prompt, negative_prompt, profile) for one material on one plane.""" | |
| key = normalize_material_type(material_type) | |
| kind = normalize_surface_kind(surface_kind) | |
| profile = MATERIALS[key] | |
| variant = profile[kind] | |
| description_block = ( | |
| f"\nExisting {kind} material:\n\n{material_description.strip()}\n" | |
| if material_description and material_description.strip() | |
| else "" | |
| ) | |
| prompt = f""" | |
| {BASE_PROMPTS[kind]} | |
| {description_block} | |
| Material specific instructions: | |
| {variant["prompt"]} | |
| """ | |
| negative_prompt = f""" | |
| {BASE_NEGATIVES[kind]} | |
| Material specific restrictions: | |
| {variant["negative"]} | |
| """ | |
| return prompt, negative_prompt, profile | |