File size: 1,825 Bytes
f209a8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1fefce0
 
 
 
 
 
 
 
 
 
 
f209a8f
 
 
 
 
 
 
1fefce0
771e544
1fefce0
 
f209a8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Hugging Face Space entrypoint for ResearchHarness."""

from __future__ import annotations

import os
from pathlib import Path

import uvicorn

from frontend.local_server import app, configure_frontend


def _int_env(name: str, default: int) -> int:
    raw = os.getenv(name, "").strip()
    if not raw:
        return default
    try:
        return int(raw)
    except ValueError as exc:
        raise ValueError(f"{name} must be an integer, got {raw!r}") from exc


def _bool_env(name: str, default: bool) -> bool:
    raw = os.getenv(name, "").strip().lower()
    if not raw:
        return default
    if raw in {"1", "true", "yes", "on"}:
        return True
    if raw in {"0", "false", "no", "off"}:
        return False
    raise ValueError(f"{name} must be a boolean, got {raw!r}")


def configure_space() -> None:
    runs_dir = Path(os.getenv("RH_SPACE_RUNS_DIR", "/tmp/researchharness_space/runs")).expanduser()
    configure_frontend(
        managed_runs_dir=str(runs_dir),
        cleanup_retention_seconds=_int_env("RH_SPACE_RETENTION_SECONDS", 6 * 60 * 60),
        cleanup_max_runs=_int_env("RH_SPACE_MAX_RUNS", 40),
        cleanup_interval_seconds=_int_env("RH_SPACE_CLEANUP_INTERVAL_SECONDS", 15 * 60),
        collection_enabled=_bool_env("RH_COLLECTION_ENABLED", True),
        collection_dataset_repo=os.getenv("RH_COLLECTION_DATASET_REPO", "InternScience/ResearchHarness-Data"),
        collection_batch_size=_int_env("RH_COLLECTION_BATCH_SIZE", 5),
        collection_max_bundle_bytes=_int_env("RH_COLLECTION_MAX_BUNDLE_BYTES", 20 * 1024 * 1024),
    )


configure_space()


def main() -> int:
    host = os.getenv("HOST", "0.0.0.0")
    port = _int_env("PORT", 7860)
    uvicorn.run(app, host=host, port=port, reload=False)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())