File size: 1,490 Bytes
1cfc9e8
 
 
ed8368e
 
1cfc9e8
 
 
 
2166489
 
f277e91
 
 
 
 
 
 
 
 
aefe605
 
2166489
1cfc9e8
aefe605
 
 
 
 
 
 
 
 
 
 
 
2166489
 
f277e91
 
 
 
 
 
 
 
 
aefe605
2166489
3808104
2166489
 
 
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
52
53
# 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()