manikumargouni commited on
Commit
ba9485c
·
verified ·
1 Parent(s): 4f6ede7

Upload config.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. config.py +58 -0
config.py CHANGED
@@ -3,6 +3,7 @@ from __future__ import annotations
3
  import csv
4
  import os
5
  from dataclasses import dataclass
 
6
  from pathlib import Path
7
 
8
  PROJECT_VERSION = "0.6.0-phase4"
@@ -96,6 +97,63 @@ IAB_RETRIEVAL_PREFIX_CONFIDENCE_THRESHOLDS = {
96
  }
97
  IAB_PARENT_FALLBACK_CONFIDENCE_FLOOR = 0.3
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  INTENT_TYPE_LABELS = (
100
  "informational",
101
  "exploratory",
 
3
  import csv
4
  import os
5
  from dataclasses import dataclass
6
+ from functools import lru_cache
7
  from pathlib import Path
8
 
9
  PROJECT_VERSION = "0.6.0-phase4"
 
97
  }
98
  IAB_PARENT_FALLBACK_CONFIDENCE_FLOOR = 0.3
99
 
100
+
101
+ _DEFAULT_MODEL_REPO_ID = "admesh/agentic-intent-classifier"
102
+
103
+
104
+ def _hf_repo_id() -> str:
105
+ return os.environ.get("ADMESH_MODEL_REPO_ID", _DEFAULT_MODEL_REPO_ID).strip() or _DEFAULT_MODEL_REPO_ID
106
+
107
+
108
+ def _hf_revision() -> str | None:
109
+ rev = os.environ.get("ADMESH_MODEL_REVISION", "").strip()
110
+ return rev or None
111
+
112
+
113
+ @lru_cache(maxsize=8)
114
+ def _resolve_repo_subdir(local_dir: Path, repo_subdir: str) -> Path:
115
+ """Resolve artifact/model subdirs for local dev and HF trust_remote_code.
116
+
117
+ Local runs: return on-disk folder inside repo.
118
+ HF dynamic module runs: if missing locally, pull only this subdir from Hub.
119
+ """
120
+ if local_dir.exists():
121
+ return local_dir
122
+
123
+ try:
124
+ from huggingface_hub import snapshot_download
125
+ except Exception:
126
+ return local_dir
127
+
128
+ kwargs: dict = {
129
+ "repo_id": _hf_repo_id(),
130
+ "repo_type": "model",
131
+ "allow_patterns": [f"{repo_subdir}/**"],
132
+ }
133
+ revision = _hf_revision()
134
+ if revision:
135
+ kwargs["revision"] = revision
136
+
137
+ try:
138
+ root = Path(snapshot_download(**kwargs))
139
+ candidate = root / repo_subdir
140
+ if candidate.exists():
141
+ return candidate
142
+ except Exception:
143
+ pass
144
+ return local_dir
145
+
146
+
147
+ # Re-resolve critical artifact/model dirs after helper definitions.
148
+ CALIBRATION_ARTIFACTS_DIR = _resolve_repo_subdir(ARTIFACTS_DIR / "calibration", "artifacts/calibration")
149
+ IAB_ARTIFACTS_DIR = _resolve_repo_subdir(ARTIFACTS_DIR / "iab", "artifacts/iab")
150
+ IAB_TAXONOMY_GRAPH_PATH = IAB_ARTIFACTS_DIR / "taxonomy_graph.json"
151
+ IAB_TAXONOMY_NODES_PATH = IAB_ARTIFACTS_DIR / "taxonomy_nodes.json"
152
+ IAB_TAXONOMY_EMBEDDINGS_PATH = IAB_ARTIFACTS_DIR / "taxonomy_embeddings.pt"
153
+ IAB_DATASET_SUMMARY_PATH = IAB_ARTIFACTS_DIR / "dataset_summary.json"
154
+ MULTITASK_INTENT_MODEL_DIR = _resolve_repo_subdir(BASE_DIR / "multitask_intent_model_output", "multitask_intent_model_output")
155
+ IAB_CLASSIFIER_MODEL_DIR = _resolve_repo_subdir(BASE_DIR / "iab_classifier_model_output", "iab_classifier_model_output")
156
+
157
  INTENT_TYPE_LABELS = (
158
  "informational",
159
  "exploratory",