| """HF Spaces (Gradio SDK + ZeroGPU) 진입점. |
| |
| HF Spaces 빌더가 자동으로 `python app.py` 를 실행한다. 로컬에서도 같은 |
| 파일로 미리보기 가능: |
| |
| pip install -e ".[dev,llm,hf]" |
| KPAA_LLM_BACKEND=llama_cpp python app.py # 로컬 GGUF 로 UI 만 미리보기 |
| # → http://127.0.0.1:7860 |
| |
| HF Spaces 환경에서는 자동으로 `SPACE_ID` 가 잡혀 ZeroGPU 백엔드가 활성화된다. |
| LAW_OC 는 Space Settings > Secrets 에 등록. |
| """ |
| from __future__ import annotations |
|
|
| import os |
| import sys |
| from pathlib import Path |
|
|
| |
| |
| |
| sys.path.insert(0, str(Path(__file__).resolve().parent / "src")) |
|
|
|
|
| |
| |
| |
| |
| import gradio_client.utils as _gc_utils |
|
|
| _orig_get_type = _gc_utils.get_type |
| _orig_jstpt = _gc_utils._json_schema_to_python_type |
|
|
|
|
| def _safe_get_type(schema): |
| if not isinstance(schema, dict): |
| return "" |
| return _orig_get_type(schema) |
|
|
|
|
| def _safe_jstpt(schema, defs): |
| if not isinstance(schema, dict): |
| return "Any" |
| return _orig_jstpt(schema, defs) |
|
|
|
|
| _gc_utils.get_type = _safe_get_type |
| _gc_utils._json_schema_to_python_type = _safe_jstpt |
| |
|
|
|
|
| |
| |
| |
| |
| |
| |
| try: |
| import spaces |
|
|
| @spaces.GPU(duration=1) |
| def _zerogpu_startup_canary() -> None: |
| """HF Spaces ZeroGPU detector 통과용 sentinel.""" |
| return None |
| except ImportError: |
| pass |
| |
|
|
|
|
| from kpaa.ui.gradio import build_app |
|
|
|
|
| def main() -> None: |
| app = build_app() |
| |
| port = int(os.environ.get("PORT", "7860")) |
| |
| |
| |
| app.queue(max_size=20).launch( |
| server_name="0.0.0.0", |
| server_port=port, |
| show_error=True, |
| ssr_mode=False, |
| show_api=False, |
| ) |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|