aether-garden / scripts /app_shot.py
kavyabhand's picture
Deploy Aether Garden — full feature build
b3ca9de verified
Raw
History Blame Contribute Delete
2.22 kB
"""Full-app visual check: launch the real Gradio app, open Explore, enter a
place, and screenshot the live 3D diorama as a visitor would see it."""
from __future__ import annotations
import os
import sys
import time
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
os.environ.setdefault("USE_MOCK_AI", "true")
from playwright.sync_api import sync_playwright # noqa: E402
ROOT = Path(__file__).resolve().parent.parent
PORT = 7866
def main():
import app as appmod
from ui import assets
demo = appmod.build_app()
kwargs = {"server_name": "127.0.0.1", "server_port": PORT, "share": False,
"allowed_paths": assets.allowed_paths(), "prevent_thread_lock": True}
if appmod.GRADIO_MAJOR >= 6:
kwargs["css"] = appmod.CUSTOM_CSS
kwargs["theme"] = appmod.REALM_THEME
demo.launch(**kwargs)
time.sleep(3)
url = f"http://127.0.0.1:{PORT}/"
with sync_playwright() as pw:
browser = pw.chromium.launch(args=["--use-gl=swiftshader", "--enable-webgl", "--ignore-gpu-blocklist"])
page = browser.new_page(viewport={"width": 1280, "height": 900})
errors = []
page.on("pageerror", lambda e: errors.append(str(e)))
page.goto(url, wait_until="domcontentloaded")
page.wait_for_timeout(4000)
# open Explore tab
page.get_by_role("tab", name="Explore").click()
page.wait_for_timeout(1500)
# click the Ember Crossroads (6th place) so we land on the bonfire scene
items = page.locator(".places-gallery button, .places-gallery .thumbnail-item, .places-gallery img")
n = items.count()
(items.nth(5) if n > 5 else items.first).click()
page.wait_for_timeout(8000) # let three.js + iframe load
frame = page.locator(".diorama-frame")
if frame.count():
frame.scroll_into_view_if_needed()
page.wait_for_timeout(3000)
out = ROOT / "assets" / "_app_shot.png"
page.screenshot(path=str(out), full_page=False)
print("pageerrors:", errors if errors else "none")
print("shot:", out)
browser.close()
demo.close()
if __name__ == "__main__":
main()