"""The CheckJSON HF2 Space. On ZeroGPU the corrector loads on cuda at start, and only its chat() call takes GPU time. Run it on your own computer with `python app.py`. Set CHECKJSON_RULES_ONLY=1 to run without a model. """ import os try: import spaces # must be imported before torch on ZeroGPU except ImportError: spaces = None from checkjson import TransformersBackend from checkjson.ui.studio import LAUNCH, build_studio def corrector(): if os.environ.get("CHECKJSON_RULES_ONLY") == "1": return None backend = TransformersBackend(device="cuda" if spaces else None) if spaces: backend.wrap(spaces.GPU(duration=30)) return backend demo = build_studio(engine=corrector(), public=bool(os.environ.get("SPACE_ID"))) if __name__ == "__main__": demo.launch(**LAUNCH)