Spaces:
Running
Running
File size: 1,278 Bytes
b655c88 | 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 | """
Entrypoint cho Hugging Face Space.
1. Tải dataset runtime nếu cần
2. Tạo thư mục dữ liệu cơ bản
3. Chạy Streamlit
"""
from __future__ import annotations
import os
import subprocess
import sys
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if ROOT_DIR not in sys.path:
sys.path.insert(0, ROOT_DIR)
from backend.runtime_paths import APP_DATA_DIR, PDF_DIR, VECTOR_DIR, ensure_app_dirs
from scripts.bootstrap_space_data import bootstrap_space_data
def main() -> int:
ensure_app_dirs()
dataset_required = os.getenv("HF_DATASET_REQUIRED", "0") == "1"
try:
bootstrap_space_data(force=os.getenv("HF_DATASET_FORCE_SYNC", "0") == "1")
except Exception as exc:
print(f"[SPACE] Bootstrap dataset thất bại: {exc}")
if dataset_required:
return 1
print(f"[SPACE] APP_DATA_DIR = {APP_DATA_DIR}")
print(f"[SPACE] PDF_DIR = {PDF_DIR}")
print(f"[SPACE] VECTOR_DIR = {VECTOR_DIR}")
cmd = [
"streamlit",
"run",
"frontend/app.py",
"--server.port=7860",
"--server.address=0.0.0.0",
]
completed = subprocess.run(cmd, check=False)
return completed.returncode
if __name__ == "__main__":
raise SystemExit(main())
|