Spaces:
Running
Running
| # import spacy.cli | |
| # spacy.cli.download("ja_core_news_sm") | |
| # spacy.cli.download("zh_core_web_sm") | |
| import os | |
| os.environ["TF_USE_LEGACY_KERAS"] = "1" | |
| import spacy_udpipe | |
| spacy_udpipe.download("ja") | |
| spacy_udpipe.download("zh") | |
| from ui.layout import build_ui | |
| from logic.data_utils import load_concepts, load_metadata | |
| from logic.user_preferences import PrefsStore | |
| from config.settings import ( | |
| HF_API_TOKEN, | |
| HF_DATASET_NAME, | |
| HF_PREFS_DATASET_NAME, | |
| LOCAL_DS_DIRECTORY_PATH, | |
| LOCAL_PREFS_DIRECTORY_PATH, | |
| ) | |
| from retinaface import RetinaFace | |
| import numpy as np | |
| def warmup_face_detector(): | |
| """Warm up RetinaFace weights to avoid first-call latency.""" | |
| try: | |
| dummy = np.zeros((256, 256, 3), dtype=np.uint8) | |
| RetinaFace.detect_faces(dummy) | |
| except Exception as exc: | |
| # Avoid crashing app startup if warmup fails. | |
| print(f"[warmup] RetinaFace warmup failed: {exc}") | |
| warmup_face_detector() | |
| concepts = load_concepts() | |
| metadata = load_metadata() | |
| prefs_store = PrefsStore( | |
| HF_API_TOKEN, | |
| HF_PREFS_DATASET_NAME, | |
| LOCAL_PREFS_DIRECTORY_PATH, | |
| private=True, | |
| ) | |
| prefs_store.setup(main_ds_folder=LOCAL_DS_DIRECTORY_PATH) | |
| demo = build_ui(concepts, metadata, HF_API_TOKEN, HF_DATASET_NAME, prefs_store) | |
| demo.queue(max_size=30, default_concurrency_limit=3) # Enable queue system with max 30 requests | |
| # demo.launch() | |
| demo.launch(debug=False, allowed_paths=[os.path.join(os.path.dirname(__file__), "data")]) | |
| demo.close() | |
| # gr.close_all() |