#!/usr/bin/env python3.12
"""1130 补图：social_hotspots_0(550px宽) / social_hotspots_2(240x180) 走豆包重生"""
import sys, os
sys.path.insert(0, '/data/news/scripts')
from PIL import Image
import image_relevance_guard as G

JOBS = [
    dict(
        idx=0,
        title='泰山脚下，「新」力量为何大有可为？',
        summ='泰山脚下的新产业力量崛起，为区域经济提供新样本',
        prompts=[
            '配图：泰山山脚现代产业园区与青山相映，日出晨光，无人机航拍视角，山峦层叠，新闻配图风格，写实，横向构图，16:9，高清，无真人，不出现人脸、人影、人体、手部',
            '配图：群山之下的现代城市与产业园，云雾缭绕，晨光，宽幅风景摄影，新闻配图风格，写实，横向构图，16:9，高清，无真人，不出现人脸、人影、人体、手部',
        ],
        dst='/data/news/images/1201/social_hotspots_0.jpg',
        tmp='/tmp/regen1130_s0',
    ),
    dict(
        idx=2,
        title='交通运输部：明年邮轮无目的地海上游有望实现常态化运营',
        summ='交通运输部称明年邮轮无目的地海上游有望实现常态化运营',
        prompts=[
            '配图：大型豪华邮轮在开阔海面航行，蓝色海水与天空，航拍视角，新闻配图风格，写实，横向构图，16:9，高清，无真人，不出现人脸、人影、人体、手部',
            '配图：停靠港口的白色大型邮轮，码头与海面，晴天，新闻摄影风格，写实，横向构图，16:9，高清，无真人，不出现人脸、人影、人体、手部',
        ],
        dst='/data/news/images/1201/social_hotspots_2.jpg',
        tmp='/tmp/regen1130_s2',
    ),
]

for job in JOBS:
    print(f'===== social_hotspots_{job["idx"]}', flush=True)
    ok_final = False
    for ci, pr in enumerate(job['prompts'], 1):
        try:
            tmp = f'{job["tmp"]}_{ci}.jpg'
            open(tmp, 'wb').write(G.gen_image(pr))
            G.strip_watermark(Image.open(tmp).convert('RGB')).save(job['dst'], 'JPEG', quality=92)
            o = Image.open(job['dst'])
            ok, why, desc = G.parse_relevance(G.relevance_ask(job['dst'], job['title'], job['summ']))
            print(f'候选{ci} {o.size} {os.path.getsize(job["dst"])//1024}KB 判定={ok} {why} | {desc[:110]}', flush=True)
            if ok:
                print(f'✅ 候选{ci} 通过 → {job["dst"]}', flush=True)
                ok_final = True
                break
        except Exception as e:
            print(f'候选{ci} 异常: {str(e)[:120]}', flush=True)
    if not ok_final:
        print(f'⚠️ social_hotspots_{job["idx"]} 未达「是」，保留最后候选', flush=True)
    o = Image.open(job['dst'])
    print(f'最终: {o.format} {o.size} {os.path.getsize(job["dst"])//1024}KB', flush=True)
