Spaces:
Paused
Paused
Deploy Loopable
Browse files- aios_grid_component/index.html +0 -0
- aios_grid_embed.html +0 -0
- core/assets.py +70 -10
aios_grid_component/index.html
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
aios_grid_embed.html
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
core/assets.py
CHANGED
|
@@ -24,8 +24,10 @@ from pathlib import Path
|
|
| 24 |
|
| 25 |
DEFAULT_REPO = 'royal-imports/product-assets'
|
| 26 |
_MANIFEST_TTL = 300
|
| 27 |
-
#: (fetched_at, {"CODE": {"
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
def repo_id():
|
|
@@ -36,21 +38,33 @@ def _token():
|
|
| 36 |
return os.environ.get('HF_TOKEN') or None
|
| 37 |
|
| 38 |
|
| 39 |
-
def
|
| 40 |
-
"""{CODE: {'ext': '.png'}} for the configured asset repo, or {} when unreachable."""
|
| 41 |
now = time.time()
|
| 42 |
if _MANIFEST['codes'] is not None and now - _MANIFEST['at'] < _MANIFEST_TTL:
|
| 43 |
-
return
|
| 44 |
try:
|
| 45 |
import json
|
| 46 |
|
| 47 |
from huggingface_hub import hf_hub_download
|
| 48 |
p = hf_hub_download(repo_id(), 'manifest.json', repo_type='dataset', token=_token())
|
| 49 |
-
|
|
|
|
|
|
|
| 50 |
except Exception:
|
| 51 |
-
codes = {}
|
| 52 |
-
_MANIFEST.update(at=now, codes=codes)
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
def fetch(code, quality='web'):
|
|
@@ -68,6 +82,52 @@ def fetch(code, quality='web'):
|
|
| 68 |
return None
|
| 69 |
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
def reset_cache():
|
| 72 |
"""Drop the memoized manifest β for gates and for a post-ingest refresh."""
|
| 73 |
-
_MANIFEST.update(at=0.0, codes=None)
|
|
|
|
| 24 |
|
| 25 |
DEFAULT_REPO = 'royal-imports/product-assets'
|
| 26 |
_MANIFEST_TTL = 300
|
| 27 |
+
#: (fetched_at, {"CODE": {...}}, {"slug": {...}}) β one manifest read per process per TTL.
|
| 28 |
+
#: DEBT-5 (2026-08-04): the same manifest.json now carries a second, NON-SKU half under
|
| 29 |
+
#: "editorial" β full-bleed lifestyle imagery for catalog gallery pages, keyed by slug.
|
| 30 |
+
_MANIFEST = {'at': 0.0, 'codes': None, 'editorial': None}
|
| 31 |
|
| 32 |
|
| 33 |
def repo_id():
|
|
|
|
| 38 |
return os.environ.get('HF_TOKEN') or None
|
| 39 |
|
| 40 |
|
| 41 |
+
def _load():
|
|
|
|
| 42 |
now = time.time()
|
| 43 |
if _MANIFEST['codes'] is not None and now - _MANIFEST['at'] < _MANIFEST_TTL:
|
| 44 |
+
return
|
| 45 |
try:
|
| 46 |
import json
|
| 47 |
|
| 48 |
from huggingface_hub import hf_hub_download
|
| 49 |
p = hf_hub_download(repo_id(), 'manifest.json', repo_type='dataset', token=_token())
|
| 50 |
+
man = json.loads(Path(p).read_text(encoding='utf-8')) or {}
|
| 51 |
+
codes = man.get('codes') or {}
|
| 52 |
+
editorial_ = man.get('editorial') or {}
|
| 53 |
except Exception:
|
| 54 |
+
codes, editorial_ = {}, {}
|
| 55 |
+
_MANIFEST.update(at=now, codes=codes, editorial=editorial_)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def manifest():
|
| 59 |
+
"""{CODE: {'ext': '.png'}} for the configured asset repo, or {} when unreachable."""
|
| 60 |
+
_load()
|
| 61 |
+
return _MANIFEST['codes']
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def editorial():
|
| 65 |
+
"""{slug: {'ext': ...}} β the editorial (non-SKU) half of the manifest; {} when unreachable."""
|
| 66 |
+
_load()
|
| 67 |
+
return _MANIFEST['editorial'] or {}
|
| 68 |
|
| 69 |
|
| 70 |
def fetch(code, quality='web'):
|
|
|
|
| 82 |
return None
|
| 83 |
|
| 84 |
|
| 85 |
+
def fetch_editorial(slug, quality='web'):
|
| 86 |
+
"""A local Path to one EDITORIAL asset, or None β same shape as fetch()."""
|
| 87 |
+
meta = editorial().get(slug)
|
| 88 |
+
if not meta:
|
| 89 |
+
return None
|
| 90 |
+
rel = (f'assets/editorial/web/{slug}.png' if quality == 'web'
|
| 91 |
+
else f"assets/editorial/orig/{slug}{meta.get('ext', '.png')}")
|
| 92 |
+
try:
|
| 93 |
+
from huggingface_hub import hf_hub_download
|
| 94 |
+
return Path(hf_hub_download(repo_id(), rel, repo_type='dataset', token=_token()))
|
| 95 |
+
except Exception:
|
| 96 |
+
return None
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def put_editorial(slug, orig_bytes, ext, web_png):
|
| 100 |
+
"""Store one editorial image: the original, its web derivative and the updated manifest in
|
| 101 |
+
ONE commit (a partial upload can never leave a listed-but-unfetchable slug). Raises on
|
| 102 |
+
failure β the route turns that into an honest 503, never a silent success.
|
| 103 |
+
|
| 104 |
+
β manifest.json is read-modify-write with no lock; two admins uploading in the same
|
| 105 |
+
second could drop one entry. Accepted for an admin-rare action; the fix (a server-side
|
| 106 |
+
merge) rides the day uploads become routine."""
|
| 107 |
+
import json
|
| 108 |
+
|
| 109 |
+
from huggingface_hub import CommitOperationAdd, HfApi, hf_hub_download
|
| 110 |
+
api = HfApi(token=_token())
|
| 111 |
+
try:
|
| 112 |
+
p = hf_hub_download(repo_id(), 'manifest.json', repo_type='dataset', token=_token(),
|
| 113 |
+
force_download=True)
|
| 114 |
+
man = json.loads(Path(p).read_text(encoding='utf-8')) or {}
|
| 115 |
+
except Exception:
|
| 116 |
+
man = {}
|
| 117 |
+
man.setdefault('editorial', {})[slug] = {'ext': ext}
|
| 118 |
+
api.create_commit(
|
| 119 |
+
repo_id(), repo_type='dataset',
|
| 120 |
+
operations=[
|
| 121 |
+
CommitOperationAdd(f'assets/editorial/orig/{slug}{ext}', orig_bytes),
|
| 122 |
+
CommitOperationAdd(f'assets/editorial/web/{slug}.png', web_png),
|
| 123 |
+
CommitOperationAdd('manifest.json',
|
| 124 |
+
json.dumps(man, indent=1, sort_keys=True).encode('utf-8')),
|
| 125 |
+
],
|
| 126 |
+
commit_message=f'editorial asset: {slug}')
|
| 127 |
+
reset_cache()
|
| 128 |
+
return True
|
| 129 |
+
|
| 130 |
+
|
| 131 |
def reset_cache():
|
| 132 |
"""Drop the memoized manifest β for gates and for a post-ingest refresh."""
|
| 133 |
+
_MANIFEST.update(at=0.0, codes=None, editorial=None)
|