AdithyaSK HF Staff commited on
Commit
d992b32
·
verified ·
1 Parent(s): df84e45

Serve Crello corpus aafdb0e86816 from the mounted bucket

Browse files
Files changed (2) hide show
  1. Dockerfile +2 -0
  2. scripts/loadtest.py +24 -0
Dockerfile CHANGED
@@ -32,6 +32,8 @@ RUN if [ -f corpus-manifest.json ]; then \
32
  --validation ${PACK_VALIDATION} --test ${PACK_TEST} && rm -rf /tmp/hf; \
33
  fi
34
  COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
 
 
35
 
36
  # The server only reads /app and /data; no chown, which would copy both into a new layer.
37
  RUN useradd --create-home --uid 1000 user
 
32
  --validation ${PACK_VALIDATION} --test ${PACK_TEST} && rm -rf /tmp/hf; \
33
  fi
34
  COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
35
+ # an upload to the Hub does not keep the executable bit
36
+ RUN chmod 0755 /usr/local/bin/docker-entrypoint.sh
37
 
38
  # The server only reads /app and /data; no chown, which would copy both into a new layer.
39
  RUN useradd --create-home --uid 1000 user
scripts/loadtest.py CHANGED
@@ -36,6 +36,25 @@ except ImportError: # run from the package directory
36
  from design_canvas.core.pack import load_pack
37
 
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  def pct(xs: list[float], q: float) -> float | None:
40
  if not xs:
41
  return None
@@ -96,7 +115,12 @@ def main(argv=None) -> int:
96
  ap.add_argument("--concurrency", type=int, default=16)
97
  ap.add_argument("--steps", type=int, default=5, help="gui: screenshot+click+key rounds per episode")
98
  ap.add_argument("--json", default=None, help="write the results here")
 
99
  a = ap.parse_args(argv)
 
 
 
 
100
 
101
  pack = load_pack()
102
  tasks = [pack.at(a.split, i % pack.count(a.split)) for i in range(a.episodes)]
 
36
  from design_canvas.core.pack import load_pack
37
 
38
 
39
+ def authorize(token: str) -> None:
40
+ """Send an HF token with every request the OpenEnv client makes (a private Space needs it). The client has no
41
+ option for headers, so its WebSocket connect and its HTTP client are wrapped here, in this script only."""
42
+ import functools
43
+
44
+ import httpx
45
+ import openenv.core.env_client as ec
46
+
47
+ auth = {"Authorization": f"Bearer {token}"}
48
+ ec.ws_connect = functools.partial(ec.ws_connect, additional_headers=auth)
49
+ base = httpx.AsyncClient.__init__
50
+
51
+ def init(self, *a, **kw):
52
+ kw["headers"] = {**auth, **(kw.get("headers") or {})}
53
+ base(self, *a, **kw)
54
+
55
+ httpx.AsyncClient.__init__ = init
56
+
57
+
58
  def pct(xs: list[float], q: float) -> float | None:
59
  if not xs:
60
  return None
 
115
  ap.add_argument("--concurrency", type=int, default=16)
116
  ap.add_argument("--steps", type=int, default=5, help="gui: screenshot+click+key rounds per episode")
117
  ap.add_argument("--json", default=None, help="write the results here")
118
+ ap.add_argument("--hf-token-env", default=None, help="env var holding an HF token, for a private Space")
119
  a = ap.parse_args(argv)
120
+ if a.hf_token_env:
121
+ import os
122
+
123
+ authorize(os.environ[a.hf_token_env])
124
 
125
  pack = load_pack()
126
  tasks = [pack.at(a.split, i % pack.count(a.split)) for i in range(a.episodes)]