SAkizuki commited on
Commit
a4bb90e
·
verified ·
1 Parent(s): 6c9a052

Auto-sync from GitHub Actions

Browse files
Files changed (2) hide show
  1. mcp_server.py +6 -2
  2. platform_utils.py +28 -1
mcp_server.py CHANGED
@@ -132,8 +132,8 @@ popularity_weight (default 0.15, rarely needs changing):
132
  - Lower (0.0): surface niche/rare tags
133
 
134
  include_wiki (default False):
135
- - True: tag meaning matters — disambiguation, explaining tags to user, exploring unfamiliar domains
136
- - False: prompt generation (wiki irrelevant to downstream), tags already known
137
 
138
  ### Quick reference
139
 
@@ -147,6 +147,8 @@ include_wiki (default False):
147
  ### Workflow
148
 
149
  After search_tags, pass selected tags to get_related_tags to discover complementary tags via co-occurrence (accessories, character features, scene atmosphere).
 
 
150
 
151
  ## Examples
152
 
@@ -233,6 +235,8 @@ async def get_related_tags(
233
  """
234
  Return co-occurrence-based tag recommendations for a given tag list (NPMI scoring).
235
  Typical workflow: call search_tags first, then pass selected tags here to discover complementary ones.
 
 
236
 
237
  Works well for: clothing accessories, character visual features, theme exploration, multi-tag intersections.
238
  e.g. tags=["fingerless_gloves"] → returns characters often wearing them
 
132
  - Lower (0.0): surface niche/rare tags
133
 
134
  include_wiki (default False):
135
+ - True: The meaning of the tag is important — disambiguation, explaining tags to users, exploring unfamiliar domains, or when you are unsure of the tag's meaning
136
+ - False: Prompt generation (Wiki is irrelevant to the downstream task), tags are known
137
 
138
  ### Quick reference
139
 
 
147
  ### Workflow
148
 
149
  After search_tags, pass selected tags to get_related_tags to discover complementary tags via co-occurrence (accessories, character features, scene atmosphere).
150
+ Supports chained exploration / iterative loops – take the interesting tags from the returned results as input to call get_related_tags again,
151
+ and use the results from get_related to feed back into a new round of search, enabling multi-hop deep traversal along the co-occurrence graph.
152
 
153
  ## Examples
154
 
 
235
  """
236
  Return co-occurrence-based tag recommendations for a given tag list (NPMI scoring).
237
  Typical workflow: call search_tags first, then pass selected tags here to discover complementary ones.
238
+ Supports chained exploration / iterative loops – take the interesting tags from the returned results as input to call get_related_tags again,
239
+ and use the results from get_related to feed back into a new round of search, enabling multi-hop deep traversal along the co-occurrence graph.
240
 
241
  Works well for: clothing accessories, character visual features, theme exploration, multi-tag intersections.
242
  e.g. tags=["fingerless_gloves"] → returns characters often wearing them
platform_utils.py CHANGED
@@ -214,6 +214,24 @@ def upload_bytes(
214
  _MS_WORKDIR = Path('/home/user/app')
215
 
216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
  def download_file(
218
  filename: str,
219
  *,
@@ -230,7 +248,9 @@ def download_file(
230
  下载单个引擎数据文件,返回本地绝对路径字符串。
231
 
232
  HF 平台:
233
- Space repo 下,hf_repo_id 默认读取环境变量 SPACE_ID
 
 
234
 
235
  MS 平台:
236
  文件已随 studio repo 部署到容器本地,直接返回工作目录下的路径,
@@ -240,6 +260,13 @@ def download_file(
240
  直接返回原始路径。
241
  """
242
  if PLATFORM == 'hf':
 
 
 
 
 
 
 
243
  from huggingface_hub import hf_hub_download
244
  repo_id = hf_repo_id or os.environ.get('SPACE_ID')
245
  if not repo_id:
 
214
  _MS_WORKDIR = Path('/home/user/app')
215
 
216
 
217
+ # HF Storage Bucket 挂载检测
218
+
219
+ # HF Storage Buckets 挂载到 Space 时,会映射到容器内的一个本地路径
220
+ # (通常为 /data),文件可直接以本地路径读取,无需 hf_hub_download。
221
+ _HF_BUCKET_MOUNT = Path('/data')
222
+
223
+
224
+ def get_hf_bucket_path(relative: str) -> Optional[Path]:
225
+ """
226
+ 如果 HF Storage Bucket 已挂载且目标文件存在,返回本地绝对路径。
227
+ 否则返回 None(调用方应 fallback 到 hf_hub_download)。
228
+ """
229
+ candidate = _HF_BUCKET_MOUNT / relative
230
+ if candidate.exists():
231
+ return candidate
232
+ return None
233
+
234
+
235
  def download_file(
236
  filename: str,
237
  *,
 
248
  下载单个引擎数据文件,返回本地绝对路径字符串。
249
 
250
  HF 平台:
251
+ 优先 Storage Bucket(/data)读取本地文件(零延迟)
252
+ 若 Bucket 未挂载或文件不存在,回退到从 Space repo 下载
253
+ (hf_repo_id 默认读取环境变量 SPACE_ID)。
254
 
255
  MS 平台:
256
  文件已随 studio repo 部署到容器本地,直接返回工作目录下的路径,
 
260
  直接返回原始路径。
261
  """
262
  if PLATFORM == 'hf':
263
+ # 优先从挂载的 Storage Bucket 读取(本地路径,零延迟)
264
+ bucket_path = get_hf_bucket_path(filename)
265
+ if bucket_path is not None:
266
+ print(f'[PlatformUtils] 从 Storage Bucket 读取: {bucket_path}')
267
+ return str(bucket_path)
268
+
269
+ # Bucket 未挂载或文件不存在,回退到从 Space repo 下载
270
  from huggingface_hub import hf_hub_download
271
  repo_id = hf_repo_id or os.environ.get('SPACE_ID')
272
  if not repo_id: