Spaces:
Paused
Paused
Bitsage commited on
Commit ·
3099e5a
1
Parent(s): 0aa3063
space: derive NEC display from canon + add pyyaml
Browse files- requirements.txt +1 -0
- shared_necessity_canon.py +49 -0
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
gradio==4.36.1
|
| 2 |
huggingface_hub==0.24.0
|
| 3 |
requests==2.31.0
|
|
|
|
| 4 |
numpy
|
|
|
|
| 1 |
gradio==4.36.1
|
| 2 |
huggingface_hub==0.24.0
|
| 3 |
requests==2.31.0
|
| 4 |
+
pyyaml==6.0.1
|
| 5 |
numpy
|
shared_necessity_canon.py
CHANGED
|
@@ -3,6 +3,11 @@ Shared NECESSITY_CANON definition for Crovia Spaces.
|
|
| 3 |
Used by both CEP Terminal and Omission Oracle to avoid duplication.
|
| 4 |
"""
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
NECESSITY_CANON = {
|
| 7 |
"NEC#1": {"name": "Missing data provenance", "severity": 75, "category": "provenance"},
|
| 8 |
"NEC#2": {"name": "Missing license attribution", "severity": 80, "category": "license"},
|
|
@@ -10,3 +15,47 @@ NECESSITY_CANON = {
|
|
| 10 |
"NEC#10": {"name": "Missing temporal validity", "severity": 40, "category": "validity"},
|
| 11 |
"NEC#13": {"name": "Missing accountable entity", "severity": 70, "category": "identity"},
|
| 12 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
Used by both CEP Terminal and Omission Oracle to avoid duplication.
|
| 4 |
"""
|
| 5 |
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from typing import Any, Dict, Optional
|
| 8 |
+
|
| 9 |
+
import yaml
|
| 10 |
+
|
| 11 |
NECESSITY_CANON = {
|
| 12 |
"NEC#1": {"name": "Missing data provenance", "severity": 75, "category": "provenance"},
|
| 13 |
"NEC#2": {"name": "Missing license attribution", "severity": 80, "category": "license"},
|
|
|
|
| 15 |
"NEC#10": {"name": "Missing temporal validity", "severity": 40, "category": "validity"},
|
| 16 |
"NEC#13": {"name": "Missing accountable entity", "severity": 70, "category": "identity"},
|
| 17 |
}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _find_public_nec_canon_path() -> Optional[Path]:
|
| 21 |
+
candidates = []
|
| 22 |
+
for parent in list(Path(__file__).resolve().parents)[:8]:
|
| 23 |
+
candidates.append(parent / "canon" / "necessities.v1.yaml")
|
| 24 |
+
candidates.append(parent.parent / "canon" / "necessities.v1.yaml")
|
| 25 |
+
for candidate in candidates:
|
| 26 |
+
if candidate.exists():
|
| 27 |
+
return candidate
|
| 28 |
+
return None
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _load_public_nec_canon(path: Path) -> Dict[str, Dict[str, Any]]:
|
| 32 |
+
with open(path, "r", encoding="utf-8") as f:
|
| 33 |
+
data = yaml.safe_load(f)
|
| 34 |
+
nec_list = (data or {}).get("necessities") or []
|
| 35 |
+
out: Dict[str, Dict[str, Any]] = {}
|
| 36 |
+
for nec in nec_list:
|
| 37 |
+
nec_id = (nec or {}).get("id")
|
| 38 |
+
if not nec_id:
|
| 39 |
+
continue
|
| 40 |
+
out[str(nec_id)] = nec
|
| 41 |
+
return out
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def _maybe_override_nec_display_fields_from_public_canon() -> None:
|
| 45 |
+
path = _find_public_nec_canon_path()
|
| 46 |
+
if not path:
|
| 47 |
+
return
|
| 48 |
+
try:
|
| 49 |
+
public = _load_public_nec_canon(path)
|
| 50 |
+
except Exception:
|
| 51 |
+
return
|
| 52 |
+
for nec_id, entry in NECESSITY_CANON.items():
|
| 53 |
+
pub = public.get(nec_id)
|
| 54 |
+
if not pub:
|
| 55 |
+
continue
|
| 56 |
+
pub_name = pub.get("name")
|
| 57 |
+
if pub_name:
|
| 58 |
+
entry["name"] = pub_name
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
_maybe_override_nec_display_fields_from_public_canon()
|