HarnessLab / app.py
Pota019's picture
Disable SSR proxy to serve the evaluation workspace
2aa53de verified
Raw History Blame Contribute Delete
1.8 kB
"""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()