From bd1050a23f0ee0cd697ae6b4b819f1097ac2f1f8 Mon Sep 17 00:00:00 2001 From: CI Bot Date: Sun, 4 Oct 2026 17:34:11 +0000 Subject: [PATCH] style: auto-format with black + isort + ruff + prettier [skip ci-format-check] --- apps/worker/worker_app/tasks/viral_video.py | 72 +++++++++++++++++---- 1 file changed, 60 insertions(+), 12 deletions(-) diff --git a/apps/worker/worker_app/tasks/viral_video.py b/apps/worker/worker_app/tasks/viral_video.py index 295731f84..9e6c6f919 100644 --- a/apps/worker/worker_app/tasks/viral_video.py +++ b/apps/worker/worker_app/tasks/viral_video.py @@ -458,22 +458,60 @@ def _analyze_single_image( _pf = (_ppn.get("attrs") or {}).get("features", "") or "" _ptxt = _pn + " " + _pf # 服装关键词识别(常见上装/下装/裙装/套装) - _cloth_kws = ["衬衫","T恤","毛衣","针织衫","卫衣","外套","西装","夹克","风衣", - "大衣","羽绒服","马甲","背心","连衣裙","半身裙","短裙","长裙", - "牛仔裤","休闲裤","西裤","运动裤","短裤","旗袍","汉服","制服", - "polo衫","POLO衫","针织","毛衫","开衫","帽衫","皮夹克","皮衣"] + _cloth_kws = [ + "衬衫", + "T恤", + "毛衣", + "针织衫", + "卫衣", + "外套", + "西装", + "夹克", + "风衣", + "大衣", + "羽绒服", + "马甲", + "背心", + "连衣裙", + "半身裙", + "短裙", + "长裙", + "牛仔裤", + "休闲裤", + "西裤", + "运动裤", + "短裤", + "旗袍", + "汉服", + "制服", + "polo衫", + "POLO衫", + "针织", + "毛衫", + "开衫", + "帽衫", + "皮夹克", + "皮衣", + ] for _ckw in _cloth_kws: if _ckw in _ptxt: _ci = _ptxt.find(_ckw) # 向前找颜色/材质/款式形容词(白/黑/米/红/蓝/灰/棉/麻/长/短/厚/薄/长袖/短袖/翻领/圆领/V领/印花/条纹等) - _start = max(0, _ci-8) + _start = max(0, _ci - 8) # 向后包含款式词(长袖/短袖/外套/套装/上衣等后续修饰) - _end = min(len(_ptxt), _ci+len(_ckw)+4) + _end = min(len(_ptxt), _ci + len(_ckw) + 4) _outfit_extract = _ptxt[_start:_end].strip(" ,,。.、") # 仅清理明确的品牌/产品类前缀(不清理颜色/款式/尺寸形容词) - _outfit_extract = re.sub(r"^(\S{0,4}牌|\S{0,3}品牌|\S{0,3}款|产品|商品|的)", "", _outfit_extract).strip() + _outfit_extract = re.sub( + r"^(\S{0,4}牌|\S{0,3}品牌|\S{0,3}款|产品|商品|的)", "", _outfit_extract + ).strip() # 尾部清理:去掉残留的品牌字/型号字(如"标""ml""g""装"等单字杂字) - _outfit_extract = re.sub(r"(标[0-9a-zA-Z]*|\d+\s*(?:ml|g|L|斤|件|个|瓶|盒|包|袋|装)|\s+\d+\s*)$", "", _outfit_extract, flags=re.IGNORECASE).strip() + _outfit_extract = re.sub( + r"(标[0-9a-zA-Z]*|\d+\s*(?:ml|g|L|斤|件|个|瓶|盒|包|袋|装)|\s+\d+\s*)$", + "", + _outfit_extract, + flags=re.IGNORECASE, + ).strip() if len(_outfit_extract) >= 2: _outfit = _outfit_extract break @@ -483,14 +521,24 @@ def _analyze_single_image( if _hair in ("自然发型", "无法判断"): _hair_color = "" _color_nodes = [n for n in nodes if n["tag"] == "color"] - _hair_kws_map = {"黑":"黑色","棕":"棕色","金":"金色","栗":"栗色","红":"红色", - "白":"白色","灰":"灰色","蓝":"蓝色","黄":"黄色","紫":"紫色"} + _hair_kws_map = { + "黑": "黑色", + "棕": "棕色", + "金": "金色", + "栗": "栗色", + "红": "红色", + "白": "白色", + "灰": "灰色", + "蓝": "蓝色", + "黄": "黄色", + "紫": "紫色", + } for _cn in _color_nodes: - _cname = (_cn.get("attrs") or {}).get("name","") or "" + _cname = (_cn.get("attrs") or {}).get("name", "") or "" # 小占比颜色更可能是发色(非主色的小面积色),且名称含头发/黑/棕/金等 _ccov = 0.0 try: - _ccov = float((_cn.get("attrs") or {}).get("coverage","0") or 0) + _ccov = float((_cn.get("attrs") or {}).get("coverage", "0") or 0) except Exception: pass for _hk, _hv in _hair_kws_map.items():