Download server/scripts/create_demo_gallery.py from Manojd99/LumenX: direct link, hf CLI and curl.
- Browser
- Download file 5.46 kB
-
https://huggingface.co/spaces/Manojd99/LumenX/resolve/main/server/scripts/create_demo_gallery.py
- Command line
-
hf download hf://spaces/Manojd99/LumenX/server/scripts/create_demo_gallery.py
-
curl -L -o create_demo_gallery.py https://huggingface.co/spaces/Manojd99/LumenX/resolve/main/server/scripts/create_demo_gallery.py
5.46 kB
| """Create two labeled synthetic demo scenes for the local gallery.""" | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| from PIL import Image, ImageDraw, ImageFilter | |
| ROOT = Path(__file__).resolve().parents[1] | |
| GALLERY = ROOT / "gallery" | |
| def _scene(kind: str, seed: int) -> Image.Image: | |
| rng = np.random.default_rng(seed) | |
| width, height = 768, 480 | |
| base = np.zeros((height, width, 3), dtype=np.float32) | |
| y = np.linspace(0, 1, height, dtype=np.float32)[:, None, None] | |
| base[:] = np.array([5, 9, 18], dtype=np.float32) | |
| if kind == "street": | |
| base += y * np.array([16, 19, 30], dtype=np.float32) | |
| horizon = 205 | |
| else: | |
| base += y * np.array([18, 20, 25], dtype=np.float32) | |
| horizon = 270 | |
| noise = rng.normal(0, 1.8, base.shape).astype(np.float32) | |
| image = Image.fromarray(np.uint8(np.clip(base + noise, 0, 255)), mode="RGB") | |
| draw = ImageDraw.Draw(image, "RGBA") | |
| if kind == "street": | |
| draw.polygon([(0, 0), (260, 0), (300, horizon), (0, 370)], fill=(8, 12, 21, 255)) | |
| draw.polygon([(768, 0), (500, 0), (470, horizon), (768, 370)], fill=(12, 11, 19, 255)) | |
| draw.polygon([(0, 480), (0, 355), (310, horizon), (458, horizon), (768, 365), (768, 480)], fill=(20, 23, 31, 255)) | |
| draw.line([(0, 355), (310, horizon)], fill=(92, 90, 95, 140), width=3) | |
| draw.line([(768, 365), (458, horizon)], fill=(92, 90, 95, 140), width=3) | |
| for side in ("left", "right"): | |
| for index, depth in enumerate((0, 1, 2)): | |
| scale = 1 / (1 + depth * 0.55) | |
| if side == "left": | |
| x0 = int(15 + index * 83) | |
| else: | |
| x0 = int(753 - index * 83) | |
| top = int(15 + depth * 37) | |
| bw = int(75 * scale) | |
| bh = int((285 - depth * 22) * scale) | |
| x1 = min(width - 1, x0 + bw) if side == "left" else max(0, x0 - bw) | |
| draw.rectangle((min(x0, x1), top, max(x0, x1), top + bh), fill=(18, 22, 31, 255), outline=(50, 55, 64, 220), width=2) | |
| wx = min(x0, x1) + max(4, bw // 5) | |
| wy = top + max(8, bh // 4) | |
| draw.rectangle((wx, wy, wx + max(7, bw // 5), wy + max(12, bh // 5)), fill=(158, 48, 59, 210)) | |
| for offset in (0, 1): | |
| draw.line((wx + offset * 12, wy, wx + offset * 12, wy + 30), fill=(255, 132, 90, 110), width=1) | |
| for x, yy, color in ((340, 177, (255, 225, 175, 255)), (478, 191, (90, 218, 255, 255))): | |
| draw.line((x, yy, x - 15, 300), fill=color, width=3) | |
| draw.ellipse((x - 9, yy - 8, x + 9, yy + 8), fill=color) | |
| draw.line((378, 310, 382, 415), fill=(215, 198, 165, 95), width=2) | |
| draw.text((340, 35), "LUMEN", fill=(255, 72, 105, 245), stroke_width=1, stroke_fill=(80, 12, 25, 255)) | |
| else: | |
| draw.polygon([(0, 0), (768, 0), (650, 255), (120, 255)], fill=(18, 20, 27, 255)) | |
| draw.polygon([(0, 480), (130, 250), (650, 250), (768, 480)], fill=(22, 24, 28, 255)) | |
| for x in (70, 698): | |
| draw.rectangle((x - 26, 95, x + 26, 255), fill=(10, 14, 21, 255), outline=(55, 59, 65, 255), width=3) | |
| draw.rectangle((x - 20, 115, x + 20, 185), fill=(164, 76, 46, 205)) | |
| for x in range(190, 620, 90): | |
| draw.line((x, 30, x, 70), fill=(54, 58, 64, 255), width=3) | |
| draw.ellipse((x - 10, 66, x + 10, 82), fill=(255, 202, 128, 235)) | |
| draw.rectangle((320, 225, 448, 430), fill=(13, 17, 23, 255), outline=(70, 72, 76, 230), width=3) | |
| draw.rectangle((338, 247, 430, 315), fill=(48, 69, 82, 235)) | |
| draw.ellipse((350, 390, 365, 407), fill=(166, 110, 83, 220)) | |
| draw.line((358, 407, 358, 451), fill=(166, 110, 83, 230), width=5) | |
| image = image.filter(ImageFilter.GaussianBlur(0.35)) | |
| glow = Image.new("RGBA", image.size, (0, 0, 0, 0)) | |
| glow_draw = ImageDraw.Draw(glow) | |
| for x, yy, color in ((340, 177, (255, 80, 70, 85)), (478, 191, (70, 200, 255, 70))) if kind == "street" else ((382, 74, (255, 198, 120, 75)), (470, 74, (255, 198, 120, 65))): | |
| radius = 48 if kind == "street" else 38 | |
| glow_draw.ellipse((x - radius, yy - radius, x + radius, yy + radius), fill=color) | |
| glow = glow.filter(ImageFilter.GaussianBlur(30)) | |
| image = Image.alpha_composite(image.convert("RGBA"), glow).convert("RGB") | |
| return image | |
| def main() -> None: | |
| GALLERY.mkdir(parents=True, exist_ok=True) | |
| entries = [ | |
| {"id": "synthetic-street", "title": "Synthetic night street", "why_hard": "Dark facades, small lamps, and uneven red and blue light.", "attribution": "Synthetic illustration generated by the LumenX demo script.", "image": "synthetic_night_street.png"}, | |
| {"id": "synthetic-hall", "title": "Synthetic indoor hall", "why_hard": "Dark corners, warm practical lights, and shadow detail.", "attribution": "Synthetic illustration generated by the LumenX demo script.", "image": "synthetic_indoor_hall.png"}, | |
| ] | |
| _scene("street", 17).save(GALLERY / entries[0]["image"], optimize=True) | |
| _scene("hall", 29).save(GALLERY / entries[1]["image"], optimize=True) | |
| (GALLERY / "metadata.json").write_text(json.dumps(entries, indent=2), encoding="utf-8") | |
| print(f"Wrote {len(entries)} synthetic gallery images to {GALLERY}") | |
| if __name__ == "__main__": | |
| main() | |