guanghulab/video-ai-system/tools/qc_char004_r4.py

65 lines
3.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""CHAR-004 R4 QC · Qwen-VL · 朴素制服版"""
import sys,os,json,base64,subprocess
sys.path.insert(0,os.path.dirname(__file__))
from secrets_loader import secret,endpoint
AK=secret("SC-004");EP=endpoint("EPT-002");FE="https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation"
DIR=os.path.expanduser("~/guanghulab/video-ai-system/assets/candidates/D157-VA-05-001-R4/CHAR-004-ZhugeFeng")
CS=[f"{DIR}/CHAR-004-R4-candidate-{i:02d}-1080x1920.jpg" for i in range(1,5)]
P="""检查CHAR-004学徒制服图。R4核心朴素整洁修仙学徒袍布料平整干净利落不准破旧乞丐感。
逐项严格判断
1. 衣服是否有破损/破洞(damaged:bool)
2. 衣服下摆有没有毛边/撕裂(frayed:bool)
3. 裤子膝盖有没有破洞(hole_knee:bool)
4. 鞋面有没有脏污(dirty_shoes:bool)
5. 衣服有没有污渍(stains:bool)
6. 布料整体是否平整整洁(neat:bool)
7. 有没有乞丐/流浪/寒酸感(beggar:bool)
8. 和苏白CHAR-003脸像不像(like_sb:bool)
9. 五官正常吗(face:bool)
10. 全身从头到脚完整吗(full:bool)
评分标准有破损/破洞/毛边直接pass=falsebeggar=true直接pass=false
输出JSON:{"candidate":N,"pass":bool,"score":0-100,"damaged":bool,"frayed":bool,"hole_knee":bool,"dirty_shoes":bool,"stains":bool,"neat":bool,"beggar":bool,"like_sb":bool,"face":bool,"full":bool,"summary":"简短结论"}"""
def enc(p):
with open(p,"rb") as f: b64=base64.b64encode(f.read()).decode()
m="jpeg" if p.endswith("jpg") else "png"
return f"data:image/{m};base64,{b64}"
def qw(img):
b=json.dumps({"model":"qwen-vl-max","input":{"messages":[{"role":"user","content":[{"image":img},{"text":P}]}]}})
for ep in[EP,FE]:
try:
p=subprocess.run(["curl","-s","-m","60","--noproxy","*","-X","POST",ep,"-H",f"Authorization: Bearer {AK}","-H","Content-Type: application/json","--data-binary","@-"],input=b,capture_output=True,text=True,timeout=65)
if not p.stdout.strip(): continue
r=json.loads(p.stdout)
if "output" in r:
c=r["output"]["choices"][0]["message"]["content"][0]["text"]
if "```" in c: c=c.split("```")[1]; c=c[4:] if c.startswith("json") else c; c=c.split("```")[0]
return json.loads(c.strip())
except: continue
return None
rs=[]
for i,p in enumerate(CS):
print(f"[{i+1}/4]",end=" ",flush=True)
q=qw(enc(p))
if q:
print(f"score={q.get('score','?')} pass={q.get('pass','?')} 破={q.get('damaged','?')} 乞丐={q.get('beggar','?')}")
rs.append(q)
else: print(""); rs.append({"candidate":i+1,"pass":False,"error":"api"})
ok=sum(1 for r in rs if r.get("pass"))
print(f"\n通过:{ok}/4")
for r in rs:
if not r.get("pass"):
iss=[]
if r.get("damaged"): iss.append("破损")
if r.get("frayed"): iss.append("毛边")
if r.get("hole_knee"): iss.append("膝盖破洞")
if r.get("dirty_shoes"): iss.append("脏鞋")
if r.get("beggar"): iss.append("乞丐感")
print(f" 候选{r.get('candidate')} ✗: {','.join(iss) if iss else '评分不足'} score={r.get('score')}")
rep={"spec":"VA-05-001-R4","results":rs,"summary":{"passed":ok,"total":4}}
with open(os.path.join(DIR,"QC-R4-BATCH.json"),"w") as f: json.dump(rep,f,ensure_ascii=False,indent=2)
print(f"\n报告: QC-R4-BATCH.json")