Premium dark UI: Inter font, indigo accent, card layout, 600px preview
Browse files- Custom gr.themes.Base() with electric indigo (#6366f1) accent, Inter/JetBrains
Mono fonts, dark backgrounds, themed buttons/inputs/sliders/checkboxes
- Injected CSS: root design tokens, card groups (.tg-card), gradient Generate
button with glow hover, example pills as rounded chips, styled tab bar,
transparent container cleanup, custom thin scrollbars, mobile media query
- Layout: proper header with SVG cube logo + tagline, controls in three labeled
cards (Describe / Render style / Post-processing), preview column scale 7 β
dominates at 600px iframe height
- Glow strength slider rescaled 0β20 (step 1, default 10); generate/rerender
divide by 10 before passing to compiler so 10 = previous default 1.0
- scene.py/compiler.py untouched; css+theme passed via launch() per Gradio 6 API
|
@@ -47,15 +47,14 @@ EXAMPLES = [
|
|
| 47 |
"a molten-gold torus knot, high metalness, low roughness",
|
| 48 |
"three glowing neon-green cubes stacked into a tower",
|
| 49 |
"a chrome icosahedron orbited by small glowing purple spheres",
|
| 50 |
-
"a
|
| 51 |
-
"a
|
|
|
|
|
|
|
| 52 |
]
|
| 53 |
|
| 54 |
-
|
| 55 |
_NESTED_SPHERE_PATTERNS = ("wireframe sphere inside", "sphere inside", "nested sphere")
|
| 56 |
|
| 57 |
-
# Detect "a <shape> badge with the text <WORD>" patterns deterministically.
|
| 58 |
-
# Group 1 = shape, group 2 = text word (converted to uppercase).
|
| 59 |
_BADGE_TEXT_RE = re.compile(
|
| 60 |
r'\b(star|shield|hexagon|badge|heart)\b.{0,60}'
|
| 61 |
r'\b(?:text|saying|word|label)\b\s*["\']?([A-Za-z0-9]{1,20})["\']?',
|
|
@@ -64,13 +63,14 @@ _BADGE_TEXT_RE = re.compile(
|
|
| 64 |
|
| 65 |
|
| 66 |
def _detect_badge_template(prompt: str):
|
| 67 |
-
"""Return (shape, text) if prompt matches badge-with-text, else (None, None)."""
|
| 68 |
m = _BADGE_TEXT_RE.search(prompt)
|
| 69 |
if m:
|
| 70 |
return m.group(1).lower(), m.group(2).upper()
|
| 71 |
return None, None
|
| 72 |
|
| 73 |
|
|
|
|
|
|
|
| 74 |
def generate(prompt: str, glow: bool, glow_strength: float, style: str, motion: str,
|
| 75 |
lighting: str, shadows: bool):
|
| 76 |
prompt = (prompt or "").strip()
|
|
@@ -80,6 +80,7 @@ def generate(prompt: str, glow: bool, glow_strength: float, style: str, motion:
|
|
| 80 |
return gr.update(), gr.update(), gr.update(), f"Prompt too long β keep it under {MAX_PROMPT_CHARS} chars.", None
|
| 81 |
|
| 82 |
lo = prompt.lower()
|
|
|
|
| 83 |
|
| 84 |
badge_shape, badge_text = _detect_badge_template(lo)
|
| 85 |
if badge_shape and badge_text:
|
|
@@ -135,85 +136,539 @@ def generate(prompt: str, glow: bool, glow_strength: float, style: str, motion:
|
|
| 135 |
|
| 136 |
if motion != "auto":
|
| 137 |
scene.animation.type = motion
|
| 138 |
-
html = compile_html(scene, glow=glow, glow_strength=
|
| 139 |
style=style, lighting=lighting, shadows=shadows)
|
| 140 |
pretty = json.dumps(scene.model_dump(), indent=2)
|
| 141 |
-
return iframe(html), html, pretty, note, scene
|
| 142 |
|
| 143 |
|
| 144 |
def rerender(scene, glow: bool, glow_strength: float, style: str, motion: str,
|
| 145 |
lighting: str, shadows: bool):
|
| 146 |
if scene is None:
|
| 147 |
return gr.update(), gr.update(), "Generate a scene first."
|
|
|
|
| 148 |
if motion != "auto":
|
| 149 |
s = scene.model_copy(deep=True)
|
| 150 |
s.animation.type = motion
|
| 151 |
else:
|
| 152 |
s = scene
|
| 153 |
-
html = compile_html(s, glow=glow, glow_strength=
|
| 154 |
style=style, lighting=lighting, shadows=shadows)
|
| 155 |
-
return iframe(html), html, "Re-rendered."
|
| 156 |
|
| 157 |
|
| 158 |
def _initial():
|
| 159 |
raw = mock_scene_json("a glass torus knot floating in the dark")
|
| 160 |
scene = build_scene(extract_json(raw))
|
| 161 |
html = compile_html(scene)
|
| 162 |
-
return iframe(html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
-
|
| 178 |
-
with gr.Column(scale=
|
| 179 |
-
prompt = gr.Textbox(
|
| 180 |
-
label="Describe a 3D scene", lines=3,
|
| 181 |
-
placeholder="neon low-poly tree, slowly rotating",
|
| 182 |
-
)
|
| 183 |
-
btn = gr.Button("Generate", variant="primary")
|
| 184 |
-
with gr.Row():
|
| 185 |
-
glow = gr.Checkbox(label="Glow", value=True)
|
| 186 |
-
glow_strength = gr.Slider(0.0, 2.0, value=1.0, step=0.1, label="Glow strength")
|
| 187 |
-
with gr.Row():
|
| 188 |
-
style = gr.Dropdown(
|
| 189 |
-
["realistic", "flat", "wireframe", "toon"],
|
| 190 |
-
value="realistic", label="Style")
|
| 191 |
-
motion = gr.Dropdown(
|
| 192 |
-
["auto", "none", "rotate", "float", "orbit"],
|
| 193 |
-
value="auto", label="Motion")
|
| 194 |
-
with gr.Row():
|
| 195 |
-
lighting = gr.Dropdown(
|
| 196 |
-
["studio", "soft", "neon", "dramatic"],
|
| 197 |
-
value="studio", label="Lighting")
|
| 198 |
-
shadows = gr.Checkbox(label="Shadows", value=True)
|
| 199 |
-
gr.Examples(examples=EXAMPLES, inputs=prompt)
|
| 200 |
-
status = gr.Markdown("")
|
| 201 |
-
|
| 202 |
-
with gr.Column(scale=6):
|
| 203 |
with gr.Tabs():
|
| 204 |
with gr.Tab("Preview"):
|
| 205 |
-
preview = gr.HTML()
|
| 206 |
with gr.Tab("Code"):
|
| 207 |
code = gr.Code(
|
| 208 |
language="html",
|
| 209 |
-
label="
|
|
|
|
| 210 |
)
|
| 211 |
|
| 212 |
-
|
| 213 |
-
|
|
|
|
| 214 |
|
| 215 |
scene_state = gr.State(None)
|
| 216 |
|
|
|
|
| 217 |
gen_inputs = [prompt, glow, glow_strength, style, motion, lighting, shadows]
|
| 218 |
gen_outputs = [preview, code, scene_json, status, scene_state]
|
| 219 |
btn.click(generate, gen_inputs, gen_outputs)
|
|
@@ -231,4 +686,4 @@ with gr.Blocks(title="ThreeGen", theme=gr.themes.Soft()) as demo:
|
|
| 231 |
|
| 232 |
|
| 233 |
if __name__ == "__main__":
|
| 234 |
-
demo.launch()
|
|
|
|
| 47 |
"a molten-gold torus knot, high metalness, low roughness",
|
| 48 |
"three glowing neon-green cubes stacked into a tower",
|
| 49 |
"a chrome icosahedron orbited by small glowing purple spheres",
|
| 50 |
+
"a row of three gold coins side by side",
|
| 51 |
+
"a tall trophy: a star on top of a golden column",
|
| 52 |
+
"a star badge with the text PRO",
|
| 53 |
+
"a shield badge with the text NEW",
|
| 54 |
]
|
| 55 |
|
|
|
|
| 56 |
_NESTED_SPHERE_PATTERNS = ("wireframe sphere inside", "sphere inside", "nested sphere")
|
| 57 |
|
|
|
|
|
|
|
| 58 |
_BADGE_TEXT_RE = re.compile(
|
| 59 |
r'\b(star|shield|hexagon|badge|heart)\b.{0,60}'
|
| 60 |
r'\b(?:text|saying|word|label)\b\s*["\']?([A-Za-z0-9]{1,20})["\']?',
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
def _detect_badge_template(prompt: str):
|
|
|
|
| 66 |
m = _BADGE_TEXT_RE.search(prompt)
|
| 67 |
if m:
|
| 68 |
return m.group(1).lower(), m.group(2).upper()
|
| 69 |
return None, None
|
| 70 |
|
| 71 |
|
| 72 |
+
# ---- Generation ----
|
| 73 |
+
|
| 74 |
def generate(prompt: str, glow: bool, glow_strength: float, style: str, motion: str,
|
| 75 |
lighting: str, shadows: bool):
|
| 76 |
prompt = (prompt or "").strip()
|
|
|
|
| 80 |
return gr.update(), gr.update(), gr.update(), f"Prompt too long β keep it under {MAX_PROMPT_CHARS} chars.", None
|
| 81 |
|
| 82 |
lo = prompt.lower()
|
| 83 |
+
_glow = glow_strength / 10.0 # slider is 0-20; compiler expects 0.0-2.0
|
| 84 |
|
| 85 |
badge_shape, badge_text = _detect_badge_template(lo)
|
| 86 |
if badge_shape and badge_text:
|
|
|
|
| 136 |
|
| 137 |
if motion != "auto":
|
| 138 |
scene.animation.type = motion
|
| 139 |
+
html = compile_html(scene, glow=glow, glow_strength=_glow,
|
| 140 |
style=style, lighting=lighting, shadows=shadows)
|
| 141 |
pretty = json.dumps(scene.model_dump(), indent=2)
|
| 142 |
+
return iframe(html, height=600), html, pretty, note, scene
|
| 143 |
|
| 144 |
|
| 145 |
def rerender(scene, glow: bool, glow_strength: float, style: str, motion: str,
|
| 146 |
lighting: str, shadows: bool):
|
| 147 |
if scene is None:
|
| 148 |
return gr.update(), gr.update(), "Generate a scene first."
|
| 149 |
+
_glow = glow_strength / 10.0
|
| 150 |
if motion != "auto":
|
| 151 |
s = scene.model_copy(deep=True)
|
| 152 |
s.animation.type = motion
|
| 153 |
else:
|
| 154 |
s = scene
|
| 155 |
+
html = compile_html(s, glow=glow, glow_strength=_glow,
|
| 156 |
style=style, lighting=lighting, shadows=shadows)
|
| 157 |
+
return iframe(html, height=600), html, "Re-rendered."
|
| 158 |
|
| 159 |
|
| 160 |
def _initial():
|
| 161 |
raw = mock_scene_json("a glass torus knot floating in the dark")
|
| 162 |
scene = build_scene(extract_json(raw))
|
| 163 |
html = compile_html(scene)
|
| 164 |
+
return (iframe(html, height=600), html,
|
| 165 |
+
json.dumps(scene.model_dump(), indent=2), "Demo scene.", scene)
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
# ---- Theme ----------------------------------------------------------------
|
| 169 |
+
|
| 170 |
+
def _build_theme():
|
| 171 |
+
return gr.themes.Base(
|
| 172 |
+
primary_hue=gr.themes.colors.indigo,
|
| 173 |
+
secondary_hue=gr.themes.colors.purple,
|
| 174 |
+
neutral_hue=gr.themes.colors.slate,
|
| 175 |
+
font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
|
| 176 |
+
font_mono=[gr.themes.GoogleFont("JetBrains Mono"), "ui-monospace", "monospace"],
|
| 177 |
+
spacing_size=gr.themes.sizes.md,
|
| 178 |
+
radius_size=gr.themes.sizes.md,
|
| 179 |
+
).set(
|
| 180 |
+
# Page / body
|
| 181 |
+
body_background_fill="#06060e",
|
| 182 |
+
body_background_fill_dark="#06060e",
|
| 183 |
+
background_fill_primary="#06060e",
|
| 184 |
+
background_fill_primary_dark="#06060e",
|
| 185 |
+
background_fill_secondary="#0d0d1a",
|
| 186 |
+
background_fill_secondary_dark="#0d0d1a",
|
| 187 |
+
|
| 188 |
+
# Blocks / panels
|
| 189 |
+
block_background_fill="#0f0f1c",
|
| 190 |
+
block_background_fill_dark="#0f0f1c",
|
| 191 |
+
block_border_color="rgba(255,255,255,0.07)",
|
| 192 |
+
block_border_color_dark="rgba(255,255,255,0.07)",
|
| 193 |
+
block_border_width="1px",
|
| 194 |
+
block_label_background_fill="#0f0f1c",
|
| 195 |
+
block_label_background_fill_dark="#0f0f1c",
|
| 196 |
+
block_label_text_color="#6d6d96",
|
| 197 |
+
block_label_text_color_dark="#6d6d96",
|
| 198 |
+
block_title_text_color="#8080aa",
|
| 199 |
+
block_title_text_color_dark="#8080aa",
|
| 200 |
+
block_shadow="0 4px 24px rgba(0,0,0,0.4)",
|
| 201 |
+
block_shadow_dark="0 4px 24px rgba(0,0,0,0.4)",
|
| 202 |
+
block_radius="14px",
|
| 203 |
+
block_padding="20px",
|
| 204 |
+
|
| 205 |
+
# Body text
|
| 206 |
+
body_text_color="#ddddf0",
|
| 207 |
+
body_text_color_dark="#ddddf0",
|
| 208 |
+
body_text_color_subdued="#7070a0",
|
| 209 |
+
body_text_color_subdued_dark="#7070a0",
|
| 210 |
+
|
| 211 |
+
# Inputs
|
| 212 |
+
input_background_fill="#14142a",
|
| 213 |
+
input_background_fill_dark="#14142a",
|
| 214 |
+
input_background_fill_focus="#1a1a32",
|
| 215 |
+
input_background_fill_focus_dark="#1a1a32",
|
| 216 |
+
input_border_color="rgba(255,255,255,0.09)",
|
| 217 |
+
input_border_color_dark="rgba(255,255,255,0.09)",
|
| 218 |
+
input_border_color_focus="#6366f1",
|
| 219 |
+
input_border_color_focus_dark="#6366f1",
|
| 220 |
+
input_shadow_focus="0 0 0 3px rgba(99,102,241,0.22)",
|
| 221 |
+
input_shadow_focus_dark="0 0 0 3px rgba(99,102,241,0.22)",
|
| 222 |
+
input_placeholder_color="#3d3d60",
|
| 223 |
+
input_placeholder_color_dark="#3d3d60",
|
| 224 |
+
input_radius="10px",
|
| 225 |
+
|
| 226 |
+
# Primary button (Generate)
|
| 227 |
+
button_primary_background_fill="linear-gradient(135deg,#6366f1 0%,#8b5cf6 100%)",
|
| 228 |
+
button_primary_background_fill_dark="linear-gradient(135deg,#6366f1 0%,#8b5cf6 100%)",
|
| 229 |
+
button_primary_background_fill_hover="linear-gradient(135deg,#818cf8 0%,#a78bfa 100%)",
|
| 230 |
+
button_primary_background_fill_hover_dark="linear-gradient(135deg,#818cf8 0%,#a78bfa 100%)",
|
| 231 |
+
button_primary_text_color="#ffffff",
|
| 232 |
+
button_primary_text_color_dark="#ffffff",
|
| 233 |
+
button_primary_border_color="transparent",
|
| 234 |
+
button_primary_border_color_dark="transparent",
|
| 235 |
+
button_primary_shadow="0 4px 20px rgba(99,102,241,0.4)",
|
| 236 |
+
button_primary_shadow_dark="0 4px 20px rgba(99,102,241,0.4)",
|
| 237 |
+
button_primary_shadow_hover="0 6px 28px rgba(99,102,241,0.55)",
|
| 238 |
+
button_primary_shadow_hover_dark="0 6px 28px rgba(99,102,241,0.55)",
|
| 239 |
+
button_transform_hover="translateY(-1px)",
|
| 240 |
+
button_large_padding="14px 24px",
|
| 241 |
+
button_large_text_size="15px",
|
| 242 |
+
button_large_text_weight="600",
|
| 243 |
+
button_medium_text_weight="500",
|
| 244 |
+
|
| 245 |
+
# Secondary button
|
| 246 |
+
button_secondary_background_fill="#161630",
|
| 247 |
+
button_secondary_background_fill_dark="#161630",
|
| 248 |
+
button_secondary_background_fill_hover="#1c1c3a",
|
| 249 |
+
button_secondary_background_fill_hover_dark="#1c1c3a",
|
| 250 |
+
button_secondary_text_color="#c0c0e0",
|
| 251 |
+
button_secondary_text_color_dark="#c0c0e0",
|
| 252 |
+
button_secondary_border_color="rgba(255,255,255,0.08)",
|
| 253 |
+
button_secondary_border_color_dark="rgba(255,255,255,0.08)",
|
| 254 |
+
|
| 255 |
+
# Slider
|
| 256 |
+
slider_color="#6366f1",
|
| 257 |
+
slider_color_dark="#6366f1",
|
| 258 |
+
|
| 259 |
+
# Checkbox
|
| 260 |
+
checkbox_background_color="#14142a",
|
| 261 |
+
checkbox_background_color_dark="#14142a",
|
| 262 |
+
checkbox_border_color="rgba(255,255,255,0.14)",
|
| 263 |
+
checkbox_border_color_dark="rgba(255,255,255,0.14)",
|
| 264 |
+
checkbox_background_color_selected="#6366f1",
|
| 265 |
+
checkbox_background_color_selected_dark="#6366f1",
|
| 266 |
+
checkbox_border_color_selected="#6366f1",
|
| 267 |
+
checkbox_border_color_selected_dark="#6366f1",
|
| 268 |
+
checkbox_border_color_focus="#6366f1",
|
| 269 |
+
checkbox_border_color_focus_dark="#6366f1",
|
| 270 |
+
checkbox_label_background_fill="#14142a",
|
| 271 |
+
checkbox_label_background_fill_dark="#14142a",
|
| 272 |
+
checkbox_label_background_fill_hover="#1a1a32",
|
| 273 |
+
checkbox_label_background_fill_hover_dark="#1a1a32",
|
| 274 |
+
checkbox_label_text_color="#c0c0e0",
|
| 275 |
+
checkbox_label_text_color_dark="#c0c0e0",
|
| 276 |
+
|
| 277 |
+
# Accent
|
| 278 |
+
color_accent="#6366f1",
|
| 279 |
+
color_accent_soft="rgba(99,102,241,0.15)",
|
| 280 |
+
color_accent_soft_dark="rgba(99,102,241,0.15)",
|
| 281 |
+
border_color_accent="#6366f1",
|
| 282 |
+
border_color_accent_dark="#6366f1",
|
| 283 |
+
border_color_primary="rgba(255,255,255,0.07)",
|
| 284 |
+
border_color_primary_dark="rgba(255,255,255,0.07)",
|
| 285 |
+
|
| 286 |
+
# Panel
|
| 287 |
+
panel_background_fill="#0d0d1a",
|
| 288 |
+
panel_background_fill_dark="#0d0d1a",
|
| 289 |
+
panel_border_color="rgba(255,255,255,0.07)",
|
| 290 |
+
panel_border_color_dark="rgba(255,255,255,0.07)",
|
| 291 |
+
|
| 292 |
+
# Code
|
| 293 |
+
code_background_fill="#0a0a18",
|
| 294 |
+
code_background_fill_dark="#0a0a18",
|
| 295 |
+
|
| 296 |
+
# Shadows
|
| 297 |
+
shadow_drop="0 2px 8px rgba(0,0,0,0.4)",
|
| 298 |
+
shadow_drop_lg="0 8px 32px rgba(0,0,0,0.6)",
|
| 299 |
+
)
|
| 300 |
|
| 301 |
|
| 302 |
+
# ---- CSS ------------------------------------------------------------------
|
| 303 |
+
|
| 304 |
+
_CSS = """
|
| 305 |
+
/* ββ Google Fonts ββ */
|
| 306 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
|
| 307 |
+
|
| 308 |
+
/* ββ Root tokens ββ */
|
| 309 |
+
:root {
|
| 310 |
+
--tg-accent: #6366f1;
|
| 311 |
+
--tg-accent-hi: #818cf8;
|
| 312 |
+
--tg-accent-glow: rgba(99, 102, 241, 0.35);
|
| 313 |
+
--tg-accent-soft: rgba(99, 102, 241, 0.13);
|
| 314 |
+
--tg-bg: #06060e;
|
| 315 |
+
--tg-card: #0f0f1c;
|
| 316 |
+
--tg-elevated: #161630;
|
| 317 |
+
--tg-border: rgba(255, 255, 255, 0.07);
|
| 318 |
+
--tg-border-hi: rgba(255, 255, 255, 0.12);
|
| 319 |
+
--tg-text: #ddddf0;
|
| 320 |
+
--tg-text-dim: #7070a0;
|
| 321 |
+
--tg-text-muted: #38385a;
|
| 322 |
+
--tg-r: 14px;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
/* ββ Foundation ββ */
|
| 326 |
+
body {
|
| 327 |
+
background: var(--tg-bg) !important;
|
| 328 |
+
font-family: 'Inter', -apple-system, sans-serif !important;
|
| 329 |
+
}
|
| 330 |
+
footer { display: none !important; }
|
| 331 |
+
.built-with { display: none !important; }
|
| 332 |
+
.gradio-container {
|
| 333 |
+
max-width: 1460px !important;
|
| 334 |
+
background: transparent !important;
|
| 335 |
+
font-family: 'Inter', -apple-system, sans-serif !important;
|
| 336 |
+
padding: 0 28px !important;
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
/* ββ Header ββ */
|
| 340 |
+
#tg-header {
|
| 341 |
+
background: transparent !important;
|
| 342 |
+
border-bottom: 1px solid var(--tg-border) !important;
|
| 343 |
+
margin-bottom: 28px !important;
|
| 344 |
+
padding: 0 !important;
|
| 345 |
+
}
|
| 346 |
+
#tg-header > * { background: transparent !important; border: none !important; }
|
| 347 |
+
#tg-header .prose, #tg-header .block { background: transparent !important; }
|
| 348 |
+
|
| 349 |
+
/* ββ Card groups ββ */
|
| 350 |
+
.tg-card {
|
| 351 |
+
background: var(--tg-card) !important;
|
| 352 |
+
border: 1px solid var(--tg-border) !important;
|
| 353 |
+
border-radius: var(--tg-r) !important;
|
| 354 |
+
box-shadow: 0 4px 28px rgba(0,0,0,0.4) !important;
|
| 355 |
+
overflow: hidden !important;
|
| 356 |
+
margin-bottom: 12px !important;
|
| 357 |
+
}
|
| 358 |
+
.tg-card .block,
|
| 359 |
+
.tg-card .form,
|
| 360 |
+
.tg-card .gap { background: transparent !important; border: none !important; }
|
| 361 |
+
|
| 362 |
+
/* Section header labels inside cards */
|
| 363 |
+
.tg-card .tg-lbl {
|
| 364 |
+
display: block !important;
|
| 365 |
+
font-size: 10px !important;
|
| 366 |
+
font-weight: 700 !important;
|
| 367 |
+
letter-spacing: 0.1em !important;
|
| 368 |
+
text-transform: uppercase !important;
|
| 369 |
+
color: var(--tg-text-dim) !important;
|
| 370 |
+
padding: 14px 20px 10px !important;
|
| 371 |
+
border-bottom: 1px solid var(--tg-border) !important;
|
| 372 |
+
margin-bottom: 2px !important;
|
| 373 |
+
background: transparent !important;
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
/* ββ Transparent misc containers ββ */
|
| 377 |
+
.block, .form, .gap { background: transparent !important; }
|
| 378 |
+
|
| 379 |
+
/* ββ Generate button ββ */
|
| 380 |
+
#tg-generate {
|
| 381 |
+
background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%) !important;
|
| 382 |
+
border: none !important;
|
| 383 |
+
border-radius: 10px !important;
|
| 384 |
+
color: #fff !important;
|
| 385 |
+
font-size: 15px !important;
|
| 386 |
+
font-weight: 600 !important;
|
| 387 |
+
letter-spacing: 0.025em !important;
|
| 388 |
+
padding: 14px 24px !important;
|
| 389 |
+
width: 100% !important;
|
| 390 |
+
box-shadow: 0 4px 20px rgba(99,102,241,0.42) !important;
|
| 391 |
+
transition: all 0.2s ease !important;
|
| 392 |
+
}
|
| 393 |
+
#tg-generate:hover {
|
| 394 |
+
background: linear-gradient(135deg, #818cf8 0%, #a78bfa 100%) !important;
|
| 395 |
+
box-shadow: 0 6px 32px rgba(99,102,241,0.6) !important;
|
| 396 |
+
transform: translateY(-1px) !important;
|
| 397 |
+
}
|
| 398 |
+
#tg-generate:active { transform: translateY(0) !important; }
|
| 399 |
+
|
| 400 |
+
/* ββ Prompt textarea ββ */
|
| 401 |
+
#tg-prompt textarea {
|
| 402 |
+
min-height: 80px !important;
|
| 403 |
+
font-size: 14px !important;
|
| 404 |
+
line-height: 1.6 !important;
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
/* ββ All labels / block titles ββ */
|
| 408 |
+
.block > .label-wrap span,
|
| 409 |
+
.block > label > span,
|
| 410 |
+
span.svelte-1gfkn6j,
|
| 411 |
+
.block-label span {
|
| 412 |
+
font-size: 11px !important;
|
| 413 |
+
font-weight: 600 !important;
|
| 414 |
+
letter-spacing: 0.06em !important;
|
| 415 |
+
text-transform: uppercase !important;
|
| 416 |
+
color: var(--tg-text-dim) !important;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
/* ββ Examples as chips ββ */
|
| 420 |
+
.examples { background: transparent !important; }
|
| 421 |
+
.examples table {
|
| 422 |
+
background: transparent !important;
|
| 423 |
+
border-spacing: 5px !important;
|
| 424 |
+
border-collapse: separate !important;
|
| 425 |
+
}
|
| 426 |
+
.examples thead, .examples th { display: none !important; }
|
| 427 |
+
.examples td {
|
| 428 |
+
padding: 2px !important;
|
| 429 |
+
background: transparent !important;
|
| 430 |
+
border: none !important;
|
| 431 |
+
}
|
| 432 |
+
.examples td button,
|
| 433 |
+
.examples .example {
|
| 434 |
+
background: var(--tg-elevated) !important;
|
| 435 |
+
border: 1px solid var(--tg-border) !important;
|
| 436 |
+
border-radius: 999px !important;
|
| 437 |
+
color: var(--tg-text-dim) !important;
|
| 438 |
+
font-family: 'Inter', sans-serif !important;
|
| 439 |
+
font-size: 12px !important;
|
| 440 |
+
font-weight: 400 !important;
|
| 441 |
+
padding: 5px 14px !important;
|
| 442 |
+
white-space: nowrap !important;
|
| 443 |
+
cursor: pointer !important;
|
| 444 |
+
transition: all 0.15s ease !important;
|
| 445 |
+
}
|
| 446 |
+
.examples td button:hover,
|
| 447 |
+
.examples .example:hover {
|
| 448 |
+
background: var(--tg-accent-soft) !important;
|
| 449 |
+
border-color: rgba(99,102,241,0.4) !important;
|
| 450 |
+
color: var(--tg-text) !important;
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
/* ββ Slider thumb ββ */
|
| 454 |
+
input[type="range"]::-webkit-slider-thumb {
|
| 455 |
+
background: var(--tg-accent) !important;
|
| 456 |
+
box-shadow: 0 0 8px var(--tg-accent-glow) !important;
|
| 457 |
+
}
|
| 458 |
+
input[type="range"]::-moz-range-thumb {
|
| 459 |
+
background: var(--tg-accent) !important;
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
/* ββ Tab bar ββ */
|
| 463 |
+
.tab-nav {
|
| 464 |
+
background: transparent !important;
|
| 465 |
+
border-bottom: 1px solid var(--tg-border) !important;
|
| 466 |
+
padding: 0 6px !important;
|
| 467 |
+
}
|
| 468 |
+
.tab-nav button {
|
| 469 |
+
background: transparent !important;
|
| 470 |
+
border: none !important;
|
| 471 |
+
border-bottom: 2px solid transparent !important;
|
| 472 |
+
border-radius: 0 !important;
|
| 473 |
+
color: var(--tg-text-dim) !important;
|
| 474 |
+
font-family: 'Inter', sans-serif !important;
|
| 475 |
+
font-size: 13px !important;
|
| 476 |
+
font-weight: 500 !important;
|
| 477 |
+
padding: 11px 18px !important;
|
| 478 |
+
margin-bottom: -1px !important;
|
| 479 |
+
transition: color 0.15s, border-color 0.15s !important;
|
| 480 |
+
}
|
| 481 |
+
.tab-nav button.selected {
|
| 482 |
+
color: var(--tg-accent-hi) !important;
|
| 483 |
+
border-bottom-color: var(--tg-accent) !important;
|
| 484 |
+
}
|
| 485 |
+
.tab-nav button:hover:not(.selected) {
|
| 486 |
+
color: var(--tg-text) !important;
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
/* ββ Preview panel container ββ */
|
| 490 |
+
#tg-preview-col > .block {
|
| 491 |
+
background: transparent !important;
|
| 492 |
+
border: none !important;
|
| 493 |
+
}
|
| 494 |
+
#tg-preview-col .tabs {
|
| 495 |
+
background: var(--tg-card) !important;
|
| 496 |
+
border: 1px solid var(--tg-border) !important;
|
| 497 |
+
border-radius: var(--tg-r) !important;
|
| 498 |
+
box-shadow: 0 8px 40px rgba(0,0,0,0.5) !important;
|
| 499 |
+
overflow: hidden !important;
|
| 500 |
+
}
|
| 501 |
+
#tg-preview-col .tabitem {
|
| 502 |
+
background: transparent !important;
|
| 503 |
+
border: none !important;
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
/* ββ Preview iframe ββ */
|
| 507 |
+
#tg-preview .gr-html,
|
| 508 |
+
#tg-preview > div {
|
| 509 |
+
background: #000 !important;
|
| 510 |
+
border-radius: 0 !important;
|
| 511 |
+
}
|
| 512 |
+
#tg-preview iframe {
|
| 513 |
+
display: block !important;
|
| 514 |
+
border-radius: 0 !important;
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
/* ββ Status line ββ */
|
| 518 |
+
#tg-status .prose, #tg-status p {
|
| 519 |
+
color: var(--tg-text-muted) !important;
|
| 520 |
+
font-size: 12px !important;
|
| 521 |
+
line-height: 1.4 !important;
|
| 522 |
+
font-variant-numeric: tabular-nums !important;
|
| 523 |
+
background: transparent !important;
|
| 524 |
+
}
|
| 525 |
+
|
| 526 |
+
/* ββ Scene JSON accordion ββ */
|
| 527 |
+
#tg-json {
|
| 528 |
+
background: var(--tg-card) !important;
|
| 529 |
+
border: 1px solid var(--tg-border) !important;
|
| 530 |
+
border-radius: var(--tg-r) !important;
|
| 531 |
+
margin-top: 16px !important;
|
| 532 |
+
box-shadow: 0 4px 24px rgba(0,0,0,0.35) !important;
|
| 533 |
+
}
|
| 534 |
+
#tg-json > * { background: transparent !important; }
|
| 535 |
+
|
| 536 |
+
/* ββ Code block ββ */
|
| 537 |
+
.codemirror-wrapper, .cm-editor {
|
| 538 |
+
background: #08081a !important;
|
| 539 |
+
border-radius: 10px !important;
|
| 540 |
+
}
|
| 541 |
+
|
| 542 |
+
/* ββ Thin scrollbars ββ */
|
| 543 |
+
* { scrollbar-width: thin; scrollbar-color: var(--tg-elevated) transparent; }
|
| 544 |
+
::-webkit-scrollbar { width: 5px; height: 5px; }
|
| 545 |
+
::-webkit-scrollbar-track { background: transparent; }
|
| 546 |
+
::-webkit-scrollbar-thumb { background: var(--tg-elevated); border-radius: 3px; }
|
| 547 |
+
::-webkit-scrollbar-thumb:hover { background: var(--tg-accent); }
|
| 548 |
+
|
| 549 |
+
/* ββ Mobile ββ */
|
| 550 |
+
@media (max-width: 768px) {
|
| 551 |
+
.gradio-container { padding: 0 12px !important; }
|
| 552 |
+
#tg-header { margin-bottom: 18px !important; }
|
| 553 |
+
.tg-card { border-radius: 10px !important; }
|
| 554 |
+
.gradio-container .row { flex-wrap: wrap !important; }
|
| 555 |
+
}
|
| 556 |
+
"""
|
| 557 |
|
| 558 |
+
# ---- HTML fragments -------------------------------------------------------
|
| 559 |
+
|
| 560 |
+
_HEADER_HTML = """
|
| 561 |
+
<div id="tg-header" style="display:flex;align-items:center;gap:18px;padding:28px 0 24px;">
|
| 562 |
+
<svg width="42" height="42" viewBox="0 0 42 42" fill="none" xmlns="http://www.w3.org/2000/svg">
|
| 563 |
+
<rect width="42" height="42" rx="11" fill="url(#hg)"/>
|
| 564 |
+
<!-- hexagon representing a cube face -->
|
| 565 |
+
<polygon points="21,7 34,14.5 34,27.5 21,35 8,27.5 8,14.5"
|
| 566 |
+
fill="none" stroke="rgba(255,255,255,0.85)" stroke-width="1.8"/>
|
| 567 |
+
<!-- inner depth lines -->
|
| 568 |
+
<line x1="21" y1="7" x2="21" y2="21" stroke="rgba(255,255,255,0.45)" stroke-width="1.4"/>
|
| 569 |
+
<line x1="34" y1="14.5" x2="21" y2="21" stroke="rgba(255,255,255,0.45)" stroke-width="1.4"/>
|
| 570 |
+
<line x1="8" y1="14.5" x2="21" y2="21" stroke="rgba(255,255,255,0.45)" stroke-width="1.4"/>
|
| 571 |
+
<defs>
|
| 572 |
+
<linearGradient id="hg" x1="0" y1="0" x2="42" y2="42" gradientUnits="userSpaceOnUse">
|
| 573 |
+
<stop offset="0%" stop-color="#6366f1"/>
|
| 574 |
+
<stop offset="100%" stop-color="#8b5cf6"/>
|
| 575 |
+
</linearGradient>
|
| 576 |
+
</defs>
|
| 577 |
+
</svg>
|
| 578 |
+
<div>
|
| 579 |
+
<div style="font-size:22px;font-weight:700;color:#e2e2f8;letter-spacing:-0.02em;
|
| 580 |
+
line-height:1;font-family:'Inter',sans-serif;">ThreeGen</div>
|
| 581 |
+
<div style="margin-top:5px;font-size:13px;color:#5a5a8a;font-weight:400;
|
| 582 |
+
font-family:'Inter',sans-serif;letter-spacing:0.01em;">
|
| 583 |
+
Describe a 3D scene — get sharable Three.js in seconds
|
| 584 |
+
</div>
|
| 585 |
+
</div>
|
| 586 |
+
</div>
|
| 587 |
+
"""
|
| 588 |
+
|
| 589 |
+
_CARD_DESCRIBE = '<span class="tg-lbl">Describe</span>'
|
| 590 |
+
_CARD_RENDER = '<span class="tg-lbl">Render style</span>'
|
| 591 |
+
_CARD_POST = '<span class="tg-lbl">Post-processing</span>'
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
# ---- UI -------------------------------------------------------------------
|
| 595 |
+
|
| 596 |
+
with gr.Blocks(title="ThreeGen") as demo:
|
| 597 |
+
|
| 598 |
+
# Header
|
| 599 |
+
gr.HTML(_HEADER_HTML, elem_id="tg-header")
|
| 600 |
+
|
| 601 |
+
with gr.Row(equal_height=False):
|
| 602 |
+
|
| 603 |
+
# ββ Controls column ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 604 |
+
with gr.Column(scale=5, min_width=320):
|
| 605 |
+
|
| 606 |
+
# Card: Describe
|
| 607 |
+
with gr.Group(elem_classes="tg-card"):
|
| 608 |
+
gr.HTML(_CARD_DESCRIBE)
|
| 609 |
+
prompt = gr.Textbox(
|
| 610 |
+
label="",
|
| 611 |
+
lines=3,
|
| 612 |
+
placeholder="neon low-poly tree, slowly rotatingβ¦",
|
| 613 |
+
elem_id="tg-prompt",
|
| 614 |
+
show_label=False,
|
| 615 |
+
)
|
| 616 |
+
btn = gr.Button("Generate", variant="primary",
|
| 617 |
+
elem_id="tg-generate", size="lg")
|
| 618 |
+
gr.Examples(
|
| 619 |
+
examples=EXAMPLES,
|
| 620 |
+
inputs=prompt,
|
| 621 |
+
label="",
|
| 622 |
+
)
|
| 623 |
+
|
| 624 |
+
# Card: Render style
|
| 625 |
+
with gr.Group(elem_classes="tg-card"):
|
| 626 |
+
gr.HTML(_CARD_RENDER)
|
| 627 |
+
with gr.Row():
|
| 628 |
+
style = gr.Dropdown(
|
| 629 |
+
["realistic", "flat", "wireframe", "toon"],
|
| 630 |
+
value="realistic", label="Style", scale=1)
|
| 631 |
+
motion = gr.Dropdown(
|
| 632 |
+
["auto", "none", "rotate", "float", "orbit"],
|
| 633 |
+
value="auto", label="Motion", scale=1)
|
| 634 |
+
with gr.Row():
|
| 635 |
+
lighting = gr.Dropdown(
|
| 636 |
+
["studio", "soft", "neon", "dramatic"],
|
| 637 |
+
value="studio", label="Lighting", scale=1)
|
| 638 |
+
shadows = gr.Checkbox(label="Shadows", value=True, scale=1)
|
| 639 |
+
|
| 640 |
+
# Card: Post-processing
|
| 641 |
+
with gr.Group(elem_classes="tg-card"):
|
| 642 |
+
gr.HTML(_CARD_POST)
|
| 643 |
+
with gr.Row():
|
| 644 |
+
glow = gr.Checkbox(label="Bloom / glow", value=True, scale=0)
|
| 645 |
+
glow_strength = gr.Slider(
|
| 646 |
+
0, 20, value=10, step=1,
|
| 647 |
+
label="Glow strength (10 = default)",
|
| 648 |
+
scale=2,
|
| 649 |
+
)
|
| 650 |
+
|
| 651 |
+
status = gr.Markdown("", elem_id="tg-status")
|
| 652 |
|
| 653 |
+
# ββ Preview column βββββββββββββββββββββββββββββββββββββββββββββββ
|
| 654 |
+
with gr.Column(scale=7, min_width=400, elem_id="tg-preview-col"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 655 |
with gr.Tabs():
|
| 656 |
with gr.Tab("Preview"):
|
| 657 |
+
preview = gr.HTML(elem_id="tg-preview")
|
| 658 |
with gr.Tab("Code"):
|
| 659 |
code = gr.Code(
|
| 660 |
language="html",
|
| 661 |
+
label="",
|
| 662 |
+
show_label=False,
|
| 663 |
)
|
| 664 |
|
| 665 |
+
# Scene JSON (collapsed)
|
| 666 |
+
with gr.Accordion("Scene JSON (raw model output)", open=False, elem_id="tg-json"):
|
| 667 |
+
scene_json = gr.Code(language="json", label="", show_label=False)
|
| 668 |
|
| 669 |
scene_state = gr.State(None)
|
| 670 |
|
| 671 |
+
# ββ Wire events βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 672 |
gen_inputs = [prompt, glow, glow_strength, style, motion, lighting, shadows]
|
| 673 |
gen_outputs = [preview, code, scene_json, status, scene_state]
|
| 674 |
btn.click(generate, gen_inputs, gen_outputs)
|
|
|
|
| 686 |
|
| 687 |
|
| 688 |
if __name__ == "__main__":
|
| 689 |
+
demo.launch(theme=_build_theme(), css=_CSS)
|