File size: 1,798 Bytes
afd5ff0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2aa53de
afd5ff0
 
 
 
 
 
2aa53de
afd5ff0
 
 
 
 
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
"""Gradio Space entrypoint for the packaged HarnessLab workspace."""

import hashlib
import json
import os
from pathlib import Path
import zipfile


def unpack_bundle(root: Path) -> None:
    bundle = root / "harnesslab_bundle.zip"
    manifest = json.loads((root / "manifest.json").read_text(encoding="utf-8"))
    if hashlib.sha256(bundle.read_bytes()).hexdigest() != manifest["bundle_sha256"]:
        raise ValueError("Bundle checksum mismatch")
    with zipfile.ZipFile(bundle) as archive:
        expected = {entry["path"]: entry["sha256"] for entry in manifest["files"]}
        if set(archive.namelist()) != set(expected):
            raise ValueError("Bundle file manifest mismatch")
        for name in archive.namelist():
            target = (root / name).resolve()
            if not target.is_relative_to(root.resolve()):
                raise ValueError("Invalid bundle member path")
            if hashlib.sha256(archive.read(name)).hexdigest() != expected[name]:
                raise ValueError("Bundle member checksum mismatch")
        archive.extractall(root)


def main() -> None:
    root = Path(__file__).resolve().parent
    unpack_bundle(root)
    os.environ.setdefault("GRADIO_ANALYTICS_ENABLED", "False")
    os.environ.setdefault("GRADIO_SSR_MODE", "False")
    import gradio as gr
    import uvicorn
    from space_app import app as workspace

    with gr.Blocks(title="HarnessLab") as info:
        gr.Markdown("# HarnessLab\n[평가 워크스페이스 열기](/)\n\n기존 평가 엔진을 실행하는 프로토타입입니다. GPU 추론은 포함하지 않습니다.")
    application = gr.mount_gradio_app(workspace, info, path="/gradio", ssr_mode=False)
    uvicorn.run(application, host="0.0.0.0", port=7860, workers=1)


if __name__ == "__main__":
    main()