Musadiq Gilal
commited on
Commit
·
a063211
1
Parent(s):
48f4600
Add SCIN labels to concern results for testing/debugging
Browse files- lib/concern_inference.py +19 -2
- lib/reporting.py +3 -0
lib/concern_inference.py
CHANGED
|
@@ -5,7 +5,7 @@ from typing import Dict, List, Any
|
|
| 5 |
import joblib
|
| 6 |
import numpy as np
|
| 7 |
|
| 8 |
-
from config.concerns import CONCERN_CONFIG, CONCERN_TAGS
|
| 9 |
from config.hudson_products import load_product_config
|
| 10 |
from lib.derm_local import embed_image_path
|
| 11 |
from lib.recommendations import build_routine
|
|
@@ -40,6 +40,19 @@ def _proba_to_binary(proba_list: List[np.ndarray], threshold: float = 0.5) -> np
|
|
| 40 |
return np.column_stack(cols)
|
| 41 |
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
def analyze_embedding(
|
| 44 |
embedding: np.ndarray,
|
| 45 |
models_dir: str = "models",
|
|
@@ -70,6 +83,9 @@ def analyze_embedding(
|
|
| 70 |
|
| 71 |
preds = _proba_to_binary(proba_list, threshold=threshold)[0]
|
| 72 |
|
|
|
|
|
|
|
|
|
|
| 73 |
result: Dict[str, Any] = {}
|
| 74 |
for idx, tag in enumerate(CONCERN_TAGS):
|
| 75 |
cfg = CONCERN_CONFIG.get(tag, {})
|
|
@@ -80,6 +96,8 @@ def analyze_embedding(
|
|
| 80 |
"description": cfg.get("description", ""),
|
| 81 |
"disclaimer": cfg.get("disclaimer", ""),
|
| 82 |
"recommended_products": cfg.get("recommended_products", []),
|
|
|
|
|
|
|
| 83 |
}
|
| 84 |
return result
|
| 85 |
|
|
@@ -132,4 +150,3 @@ def analyze_image_report(
|
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
-
|
|
|
|
| 5 |
import joblib
|
| 6 |
import numpy as np
|
| 7 |
|
| 8 |
+
from config.concerns import CONCERN_CONFIG, CONCERN_TAGS, CONCERN_MAP
|
| 9 |
from config.hudson_products import load_product_config
|
| 10 |
from lib.derm_local import embed_image_path
|
| 11 |
from lib.recommendations import build_routine
|
|
|
|
| 40 |
return np.column_stack(cols)
|
| 41 |
|
| 42 |
|
| 43 |
+
def _build_scin_labels_lookup() -> Dict[str, List[str]]:
|
| 44 |
+
"""
|
| 45 |
+
Build reverse mapping from concern tag to list of SCIN labels that map to it.
|
| 46 |
+
This is informational only - shows which SCIN labels correspond to each concern.
|
| 47 |
+
"""
|
| 48 |
+
reverse_map: Dict[str, List[str]] = {tag: [] for tag in CONCERN_TAGS}
|
| 49 |
+
for scin_label, concern_tags in CONCERN_MAP.items():
|
| 50 |
+
for concern_tag in concern_tags:
|
| 51 |
+
if concern_tag in reverse_map:
|
| 52 |
+
reverse_map[concern_tag].append(scin_label)
|
| 53 |
+
return reverse_map
|
| 54 |
+
|
| 55 |
+
|
| 56 |
def analyze_embedding(
|
| 57 |
embedding: np.ndarray,
|
| 58 |
models_dir: str = "models",
|
|
|
|
| 83 |
|
| 84 |
preds = _proba_to_binary(proba_list, threshold=threshold)[0]
|
| 85 |
|
| 86 |
+
# Build reverse lookup: concern tag -> list of SCIN labels
|
| 87 |
+
scin_labels_lookup = _build_scin_labels_lookup()
|
| 88 |
+
|
| 89 |
result: Dict[str, Any] = {}
|
| 90 |
for idx, tag in enumerate(CONCERN_TAGS):
|
| 91 |
cfg = CONCERN_CONFIG.get(tag, {})
|
|
|
|
| 96 |
"description": cfg.get("description", ""),
|
| 97 |
"disclaimer": cfg.get("disclaimer", ""),
|
| 98 |
"recommended_products": cfg.get("recommended_products", []),
|
| 99 |
+
# Add SCIN labels that map to this concern tag (informational)
|
| 100 |
+
"scin_labels": scin_labels_lookup.get(tag, []),
|
| 101 |
}
|
| 102 |
return result
|
| 103 |
|
|
|
|
| 150 |
|
| 151 |
|
| 152 |
|
|
|
lib/reporting.py
CHANGED
|
@@ -187,12 +187,15 @@ def build_report(
|
|
| 187 |
continue
|
| 188 |
cfg = CONCERN_CONFIG.get(tag, {})
|
| 189 |
body = _format_concern_body(tag, prob)
|
|
|
|
|
|
|
| 190 |
concern_sections.append(
|
| 191 |
{
|
| 192 |
"tag": tag,
|
| 193 |
"title": cfg.get("title", tag.replace("_", " ")),
|
| 194 |
"body": body,
|
| 195 |
"prob": prob,
|
|
|
|
| 196 |
}
|
| 197 |
)
|
| 198 |
|
|
|
|
| 187 |
continue
|
| 188 |
cfg = CONCERN_CONFIG.get(tag, {})
|
| 189 |
body = _format_concern_body(tag, prob)
|
| 190 |
+
# Include SCIN labels if available in concern_results
|
| 191 |
+
scin_labels = concern_results.get(tag, {}).get("scin_labels", [])
|
| 192 |
concern_sections.append(
|
| 193 |
{
|
| 194 |
"tag": tag,
|
| 195 |
"title": cfg.get("title", tag.replace("_", " ")),
|
| 196 |
"body": body,
|
| 197 |
"prob": prob,
|
| 198 |
+
"scin_labels": scin_labels, # SCIN labels that map to this concern
|
| 199 |
}
|
| 200 |
)
|
| 201 |
|