썸네일 선택 로직 및 필터링 추가
This commit is contained in:
1 parent
788e76ef76
commit
6090d500f9
6 files changed
+565
-6
No files matched your search
@@ -9,11 +9,15 @@ from sqlalchemy import select
|
||||
from app.database.session import BackgroundSessionLocal
|
||||
from app.home.models import Project, MarketingIntel
|
||||
from app.utils.subtitles import SubtitleContentsGenerator
|
||||
from app.utils import thumbnail_fitness
|
||||
from app.utils.thumbnail_vision import pick_thumbnail_by_vision
|
||||
from app.utils.creatomate import (
|
||||
CreatomateService,
|
||||
SCENE_TRACK,
|
||||
SUBTITLE_TRACK,
|
||||
KEYWORD_TRACK,
|
||||
THUMBNAIL_SLOT_MARKER,
|
||||
get_shared_client,
|
||||
)
|
||||
from app.utils.logger import get_logger
|
||||
from app.video.services.video import get_image_tags_by_task_id
|
||||
@@ -97,12 +101,65 @@ async def generate_creative_assets_background(
|
||||
f"duplicate={duplicate} - task_id: {task_id}"
|
||||
)
|
||||
|
||||
# 썸네일 슬롯(-9999)이 있는 템플릿이면 픽셀(헤더) 적합도 사전 계산.
|
||||
# 헤더 바이트만 받아 크기를 파싱하므로 CPU 부담 없음 — 실패/타임아웃 시
|
||||
# 빈 dict로 진행(태그 점수만 사용, 배정 자체는 막지 않음).
|
||||
thumbnail_fitness_map: dict = {}
|
||||
has_thumbnail_slot = any(
|
||||
elem_type == "image" and name.endswith(THUMBNAIL_SLOT_MARKER)
|
||||
for name, elem_type in creatomate_service.parse_template_component_name(
|
||||
template["source"]["elements"]
|
||||
).items()
|
||||
)
|
||||
if has_thumbnail_slot and taged_image_list:
|
||||
client = await get_shared_client()
|
||||
thumbnail_fitness_map = await thumbnail_fitness.score_pool_thumbnail_fitness(
|
||||
taged_image_list, client
|
||||
)
|
||||
rejected = {
|
||||
url: fit["reject"]
|
||||
for url, fit in thumbnail_fitness_map.items()
|
||||
if fit["reject"]
|
||||
}
|
||||
logger.info(
|
||||
f"[generate_creative_assets_background] thumbnail fitness — "
|
||||
f"scored={len(thumbnail_fitness_map)}/{len(taged_image_list)}, "
|
||||
f"rejected={len(rejected)} {rejected if rejected else ''} - task_id: {task_id}"
|
||||
)
|
||||
|
||||
# ── Step 1-b: 썸네일 최종 선택 (비전 LLM, Phase 2) ──────────────
|
||||
# 규칙+픽셀로 압축한 top-3 후보를 비전 LLM이 실제로 보고 1컷 선택.
|
||||
# 실패/후보 부족 시 thumbnail_choice가 비어 규칙 1위로 자동 폴백.
|
||||
thumbnail_choice: dict = {}
|
||||
if has_thumbnail_slot and taged_image_list:
|
||||
candidates_by_slot = creatomate_service.rank_thumbnail_candidates(
|
||||
template=template,
|
||||
taged_image_list=taged_image_list,
|
||||
thumbnail_fitness_map=thumbnail_fitness_map,
|
||||
top_n=3,
|
||||
)
|
||||
for slot, candidates in candidates_by_slot.items():
|
||||
chosen = await pick_thumbnail_by_vision(
|
||||
candidates=candidates,
|
||||
industry=project.industry,
|
||||
business_name=customer_name,
|
||||
)
|
||||
if chosen is not None:
|
||||
thumbnail_choice[slot] = chosen["image_url"]
|
||||
logger.info(
|
||||
f"[generate_creative_assets_background] thumbnail vision pick — "
|
||||
f"{ {s: u.rsplit('/', 1)[-1] for s, u in thumbnail_choice.items()} } "
|
||||
f"- task_id: {task_id}"
|
||||
)
|
||||
|
||||
image_modifications, assigned_image_tags = creatomate_service.template_matching_taged_image(
|
||||
template=template,
|
||||
taged_image_list=taged_image_list,
|
||||
music_url="", # 음악 URL은 영상 생성 시점에 결정 — 사전 단계에서는 빈 값
|
||||
address=store_address,
|
||||
duplicate=duplicate,
|
||||
thumbnail_fitness_map=thumbnail_fitness_map,
|
||||
thumbnail_choice=thumbnail_choice,
|
||||
)
|
||||
# audio-music은 영상 생성 시점에 덮어씌워지므로 image_match에서 제거
|
||||
image_match = {k: v for k, v in image_modifications.items() if k != "audio-music"}
|
||||
|
||||
Reference in new issue
Block a user