hetest / settings.py
jkkim
Add classifier/anonymization/learning pipeline + Genesis design + Lucide icons
8485d6e
Raw
History Blame Contribute Delete
2.93 kB
"""λŸ°νƒ€μž„ μ„€μ • β€” `settings.json` μ˜μ†.
UI 의 "μ„€μ •" νŽ˜μ΄μ§€μ—μ„œ SHAP ν™œμ„±, ensemble Ξ±, 둜그 레벨 등을 μ‘°μ •.
변경은 μ¦‰μ‹œ 반영 (각 λͺ¨λ“ˆμ΄ settings.get() 으둜 쑰회).
"""
from __future__ import annotations
import json
from pathlib import Path
from threading import Lock
SETTINGS_FILE = Path(__file__).resolve().parent / "settings.json"
_lock = Lock()
# κΈ°λ³Έκ°’ β€” ν‚€λŠ” μ—¬κΈ° λ“±λ‘λœ κ²ƒλ§Œ ν—ˆμš© (UI μž…λ ₯ κ²€μ¦μš©)
DEFAULTS: dict = {
"shap_enabled": False, # λΆ„λ₯˜ μΉ΄λ“œμ˜ SHAP λ²„νŠΌ λ…ΈμΆœ
"shap_max_evals": 60, # PartitionExplainer 평가 횟수 (속도/정확도)
"ensemble_alpha": 0.5, # rule vs neural blend (0=neural only, 1=rule only)
"log_level": "INFO", # DEBUG/INFO/WARNING/ERROR
"perf_collect": True, # μš”μ²­ timing μˆ˜μ§‘ μ—¬λΆ€
"dashboard_refresh_ms": 5000, # λŒ€μ‹œλ³΄λ“œ μžλ™ μƒˆλ‘œκ³ μΉ¨ (0=μˆ˜λ™λ§Œ)
"logs_refresh_ms": 3000,
"neural_auto_load": False, # λΆ€νŒ… μ‹œ 신경망 λͺ¨λΈ μžλ™ λ‘œλ“œ (느림)
"neural_disable": False, # λΆ„λ₯˜ μ‹œ neural 호좜 일괄 λΉ„ν™œμ„±ν™”
# ν•œκ΅­μ–΄ NER 정확도 κ°œμ„  (Bμ•ˆ + Aμ•ˆ)
"ko_ner_enabled": True, # KoELECTRA-NER λ‘œλ“œλ˜λ©΄ μ‚¬μš©
"ko_ner_auto_load": False, # λΆ€νŒ… μ‹œ μžλ™ λ‘œλ“œ (느림)
"drop_spacy_korean_ner": True, # ko_ner κ°€μš© μ‹œ spaCy ν•œκ΅­μ–΄ PERSON/LOC/ORG 폐기
"heuristic_filter": True, # 길이/쑰사/μ–΄λ―Έ νœ΄λ¦¬μŠ€ν‹± ν›„μ²˜λ¦¬
}
ALLOWED_TYPES = {
"shap_enabled": bool,
"shap_max_evals": int,
"ensemble_alpha": float,
"log_level": str,
"perf_collect": bool,
"dashboard_refresh_ms": int,
"logs_refresh_ms": int,
"neural_auto_load": bool,
"neural_disable": bool,
"ko_ner_enabled": bool,
"ko_ner_auto_load": bool,
"drop_spacy_korean_ner": bool,
"heuristic_filter": bool,
}
def load() -> dict:
if not SETTINGS_FILE.exists():
return dict(DEFAULTS)
try:
cur = json.loads(SETTINGS_FILE.read_text(encoding="utf-8"))
return {**DEFAULTS, **(cur if isinstance(cur, dict) else {})}
except Exception:
return dict(DEFAULTS)
def save(updates: dict) -> dict:
"""allowed key 만 적용 ν›„ 파일 μ €μž₯. λ°˜ν™˜ = μ €μž₯ 직후 전체 μƒνƒœ."""
with _lock:
cur = load()
for k, v in (updates or {}).items():
if k not in DEFAULTS:
continue
try:
cur[k] = ALLOWED_TYPES[k](v)
except (TypeError, ValueError):
continue
SETTINGS_FILE.write_text(
json.dumps(cur, ensure_ascii=False, indent=2),
encoding="utf-8",
)
return cur
def get(key: str):
return load().get(key, DEFAULTS.get(key))