Spaces:
Running on Zero
Running on Zero
Keep generation prompts inside CLIP budget
Browse files
README.md
CHANGED
|
@@ -64,6 +64,8 @@ SSD-1B is an Apache-2.0 distilled SDXL model. The LCM adapter enables low-step g
|
|
| 64 |
|
| 65 |
Sprites and backgrounds are generated directly from their written prompts. No procedurally drawn sprite, palette, silhouette, camera guide, or background layout is passed into the production model. Sprite prompts use a portrait canvas and positive single-subject composition language; the negative prompt separately rejects sheets, lineups, repeated subjects, and multiple views. After transparency extraction, sprites with zero or multiple significant foreground components are regenerated with a new seed up to `PRIMARY_SPRITE_ATTEMPTS` times. If every attempt fails, the deployed Space returns an explicit model-generation error rather than returning a contact sheet. Background negative prompts reject characters and generic particle overlays.
|
| 66 |
|
|
|
|
|
|
|
| 67 |
The deployed Space is fail-closed: if the primary neural model cannot run, generation stops with a visible error instead of silently returning procedural art and calling it model output. The procedural renderer remains available for local development and diagnostics only and cannot influence successful public generations.
|
| 68 |
|
| 69 |
ZeroGPU is free for eligible personal accounts, but it is quota-limited rather than unlimited: free accounts currently receive five minutes of GPU time per day. Queueing or a quota message is therefore possible even though no inference credits or payment are required.
|
|
|
|
| 64 |
|
| 65 |
Sprites and backgrounds are generated directly from their written prompts. No procedurally drawn sprite, palette, silhouette, camera guide, or background layout is passed into the production model. Sprite prompts use a portrait canvas and positive single-subject composition language; the negative prompt separately rejects sheets, lineups, repeated subjects, and multiple views. After transparency extraction, sprites with zero or multiple significant foreground components are regenerated with a new seed up to `PRIMARY_SPRITE_ATTEMPTS` times. If every attempt fails, the deployed Space returns an explicit model-generation error rather than returning a contact sheet. Background negative prompts reject characters and generic particle overlays.
|
| 66 |
|
| 67 |
+
SSD-1B's CLIP text encoder has a 77-token context window. Production prompts therefore use a conservative word budget, place the camera and single-subject contract first, and compact the free-form description. This prevents those critical constraints from being silently truncated behind verbose style text.
|
| 68 |
+
|
| 69 |
The deployed Space is fail-closed: if the primary neural model cannot run, generation stops with a visible error instead of silently returning procedural art and calling it model output. The procedural renderer remains available for local development and diagnostics only and cannot influence successful public generations.
|
| 70 |
|
| 71 |
ZeroGPU is free for eligible personal accounts, but it is quota-limited rather than unlimited: free accounts currently receive five minutes of GPU time per day. Queueing or a quota message is therefore possible even though no inference credits or payment are required.
|
app.py
CHANGED
|
@@ -220,6 +220,28 @@ def camera_prompt_contract(camera: str, is_background: bool) -> str:
|
|
| 220 |
return "Use one internally consistent game camera angle appropriate to the role."
|
| 221 |
|
| 222 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
def interpret_style_hint(style_hint: str) -> StylePlan:
|
| 224 |
text = (style_hint or "").lower()
|
| 225 |
tags: list[str] = []
|
|
@@ -1597,13 +1619,6 @@ def diffusion_dimensions(spec: AssetSpec) -> tuple[int, int]:
|
|
| 1597 |
|
| 1598 |
|
| 1599 |
def diffusion_negative_prompt(spec: AssetSpec) -> str:
|
| 1600 |
-
common = (
|
| 1601 |
-
"texture map, material texture, seamless texture, tiled pattern, uv map, uv unwrap, "
|
| 1602 |
-
"3d model texture, normal map, roughness map, diffuse map, sprite sheet, atlas, "
|
| 1603 |
-
"character sheet, model sheet, turnaround, lineup, comparison, alternate views, multiple views, "
|
| 1604 |
-
"duplicate subject, repeated subject, pair, group, multiple objects, cropped subject, close-up surface, "
|
| 1605 |
-
"fabric swatch, text, watermark"
|
| 1606 |
-
)
|
| 1607 |
if is_background_spec(spec):
|
| 1608 |
camera_negative = {
|
| 1609 |
"top_down": ", sky, horizon, eye-level view, front view, front-facing facade, vanishing point",
|
|
@@ -1611,15 +1626,15 @@ def diffusion_negative_prompt(spec: AssetSpec) -> str:
|
|
| 1611 |
"side_view": ", overhead view, top-down view, isometric view",
|
| 1612 |
}.get(spec.camera, "")
|
| 1613 |
return (
|
| 1614 |
-
|
| 1615 |
-
|
| 1616 |
-
"
|
| 1617 |
+ camera_negative
|
| 1618 |
)
|
| 1619 |
return (
|
| 1620 |
-
|
| 1621 |
-
|
| 1622 |
-
"trees, foliage, ground, floor,
|
| 1623 |
)
|
| 1624 |
|
| 1625 |
|
|
@@ -1711,18 +1726,18 @@ def initialize_primary_image_model() -> None:
|
|
| 1711 |
|
| 1712 |
|
| 1713 |
def primary_diffusion_prompt(spec: AssetSpec) -> str:
|
|
|
|
| 1714 |
if is_background_spec(spec):
|
|
|
|
| 1715 |
return (
|
| 1716 |
-
f"{
|
| 1717 |
-
"
|
| 1718 |
-
"Use connected environmental forms and clean terrain structure. No characters and no decorative overlay."
|
| 1719 |
)
|
|
|
|
|
|
|
| 1720 |
return (
|
| 1721 |
-
f"{
|
| 1722 |
-
"
|
| 1723 |
-
"with broad empty margin on every side. Derive the anatomy, body shape, pose, costume, equipment, materials, "
|
| 1724 |
-
"and recognizable details directly from the written description. Use a plain uniform white studio field, a "
|
| 1725 |
-
"readable silhouette, and a clean unlabeled presentation."
|
| 1726 |
)
|
| 1727 |
|
| 1728 |
|
|
@@ -2301,6 +2316,7 @@ def model_configuration_summary() -> str:
|
|
| 2301 |
f"remote image fallback: `{remote_fallback}` 路 neural image models: `{neural_status}` 路 "
|
| 2302 |
f"neural enforcement: `{enforcement}` 路 primary readiness: `{readiness}`. "
|
| 2303 |
"Every production image is generated directly from its written prompt by the primary text-to-image model. "
|
|
|
|
| 2304 |
"Sprite outputs must pass single-subject alpha-component validation and are regenerated with a new seed up to "
|
| 2305 |
f"{PRIMARY_SPRITE_ATTEMPTS} times. No procedural guide is supplied to the model. The procedural renderer is "
|
| 2306 |
"development-only and is blocked in the deployed Space when the primary model fails."
|
|
|
|
| 220 |
return "Use one internally consistent game camera angle appropriate to the role."
|
| 221 |
|
| 222 |
|
| 223 |
+
def compact_prompt_words(text: str, limit: int) -> str:
|
| 224 |
+
"""Keep model prompts inside CLIP's small token window without tokenizer coupling."""
|
| 225 |
+
words = re.findall(r"\S+", re.sub(r"\s+", " ", text or "").strip())
|
| 226 |
+
return " ".join(words[:limit])
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def primary_camera_phrase(camera: str, is_background: bool) -> str:
|
| 230 |
+
if camera == "top_down":
|
| 231 |
+
return "Strict orthographic overhead view directly from above."
|
| 232 |
+
if camera == "isometric":
|
| 233 |
+
return "Strict isometric three-quarter projection with parallel axes."
|
| 234 |
+
if camera == "side_view":
|
| 235 |
+
return "Strict side-profile view for a 2D platformer."
|
| 236 |
+
if camera == "first_person":
|
| 237 |
+
return "Strict first-person viewpoint aligned to the player eye line."
|
| 238 |
+
if camera == "front_view":
|
| 239 |
+
return "Strict front-facing view oriented toward the camera."
|
| 240 |
+
if is_background:
|
| 241 |
+
return "One consistent playable 2D game camera projection."
|
| 242 |
+
return "One consistent camera direction for the complete subject."
|
| 243 |
+
|
| 244 |
+
|
| 245 |
def interpret_style_hint(style_hint: str) -> StylePlan:
|
| 246 |
text = (style_hint or "").lower()
|
| 247 |
tags: list[str] = []
|
|
|
|
| 1619 |
|
| 1620 |
|
| 1621 |
def diffusion_negative_prompt(spec: AssetSpec) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1622 |
if is_background_spec(spec):
|
| 1623 |
camera_negative = {
|
| 1624 |
"top_down": ", sky, horizon, eye-level view, front view, front-facing facade, vanishing point",
|
|
|
|
| 1626 |
"side_view": ", overhead view, top-down view, isometric view",
|
| 1627 |
}.get(spec.camera, "")
|
| 1628 |
return (
|
| 1629 |
+
"person, character, player, hero, creature, monster, vehicle, mascot, foreground subject, "
|
| 1630 |
+
"particle effect, particles, confetti, sparkles, floating dots, glowing orbs, embers, lens flare, "
|
| 1631 |
+
"texture map, tiled pattern, uv map, text, watermark"
|
| 1632 |
+ camera_negative
|
| 1633 |
)
|
| 1634 |
return (
|
| 1635 |
+
"multiple subjects, duplicate character, repeated character, character sheet, model sheet, turnaround, "
|
| 1636 |
+
"lineup, alternate views, multiple poses, multiple views, pair, group, cropped body, scenery, landscape, "
|
| 1637 |
+
"room, trees, foliage, ground, floor, background props, drop shadow, texture map, tiled pattern, text, watermark"
|
| 1638 |
)
|
| 1639 |
|
| 1640 |
|
|
|
|
| 1726 |
|
| 1727 |
|
| 1728 |
def primary_diffusion_prompt(spec: AssetSpec) -> str:
|
| 1729 |
+
camera = primary_camera_phrase(spec.camera, is_background_spec(spec))
|
| 1730 |
if is_background_spec(spec):
|
| 1731 |
+
description = compact_prompt_words(spec.prompt, 34)
|
| 1732 |
return (
|
| 1733 |
+
f"{camera} Empty playable 2D game environment with connected terrain and clear gameplay space. "
|
| 1734 |
+
f"{description}"
|
|
|
|
| 1735 |
)
|
| 1736 |
+
description = compact_prompt_words(spec.prompt, 24)
|
| 1737 |
+
subject = spec.role.replace("_", " ")
|
| 1738 |
return (
|
| 1739 |
+
f"{camera} Single isolated {subject} subject. One complete body, one pose, centered and fully visible with "
|
| 1740 |
+
f"broad empty margins on a uniform white field. {description}"
|
|
|
|
|
|
|
|
|
|
| 1741 |
)
|
| 1742 |
|
| 1743 |
|
|
|
|
| 2316 |
f"remote image fallback: `{remote_fallback}` 路 neural image models: `{neural_status}` 路 "
|
| 2317 |
f"neural enforcement: `{enforcement}` 路 primary readiness: `{readiness}`. "
|
| 2318 |
"Every production image is generated directly from its written prompt by the primary text-to-image model. "
|
| 2319 |
+
"Critical camera and subject constraints are placed first inside a conservative CLIP prompt budget. "
|
| 2320 |
"Sprite outputs must pass single-subject alpha-component validation and are regenerated with a new seed up to "
|
| 2321 |
f"{PRIMARY_SPRITE_ATTEMPTS} times. No procedural guide is supplied to the model. The procedural renderer is "
|
| 2322 |
"development-only and is blocked in the deployed Space when the primary model fails."
|