lyric 생성 시점에 subtitle 생성하도록 DB 및 코드 변경

This commit is contained in:
jaehwang committed 2026-03-24 06:43:32 +00:00
1 parent 7da6ab6ec0
commit 395b4dbbfb
6 files changed
+114 -22

No files matched your search

+32 -16
View File
@@ -14,6 +14,8 @@ Video API Router
"""
import json
import asyncio
from typing import Literal
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, Query
@@ -145,6 +147,34 @@ async def generate_video(
image_urls: list[str] = []
try:
subtitle_done = False
count = 0
async with AsyncSessionLocal() as session:
project_result = await session.execute(
select(Project)
.where(Project.task_id == task_id)
.order_by(Project.created_at.desc())
.limit(1)
)
project = project_result.scalar_one_or_none()
while not subtitle_done:
async with AsyncSessionLocal() as session:
logger.info(f"[generate_video] Checking subtitle- task_id: {task_id}, count : {count}")
marketing_result = await session.execute(
select(MarketingIntel).where(MarketingIntel.id == project.marketing_intelligence)
)
marketing_intelligence = marketing_result.scalar_one_or_none()
subtitle_done = bool(marketing_intelligence.subtitle)
if subtitle_done:
logger.info(f"[generate_video] Check subtitle done task_id: {task_id}")
break
await asyncio.sleep(5)
if count > 12 :
raise Exception("subtitle 결과 생성 실패")
count += 1
# 세션을 명시적으로 열고 DB 작업 후 바로 닫음
async with AsyncSessionLocal() as session:
# ===== 순차 쿼리 실행: Project, Lyric, Song, Image =====
@@ -198,10 +228,8 @@ async def generate_video(
detail=f"task_id '{task_id}'에 해당하는 Project를 찾을 수 없습니다.",
)
project_id = project.id
marketing_intelligence = project.marketing_intelligence
store_address = project.detail_region_info
customer_name = project.store_name
marketing_intelligence = project.marketing_intelligence
# customer_name = project.store_name
marketing_result = await session.execute(
select(MarketingIntel).where(MarketingIntel.id == project.marketing_intelligence)
@@ -296,8 +324,6 @@ async def generate_video(
# 2단계: 외부 API 호출 (세션 사용 안함 - 커넥션 풀 점유 없음)
# ==========================================================================
stage2_start = time.perf_counter()
subtitle_generator = SubtitleContentsGenerator()
try:
logger.info(
@@ -325,17 +351,7 @@ async def generate_video(
)
logger.debug(f"[generate_video] Modifications created - task_id: {task_id}")
pitchings = creatomate_service.extract_text_format_from_template(template)
generated_subtitles = await subtitle_generator.generate_subtitle_contents(
marketing_intelligence = marketing_intelligence.intel_result,
pitching_label_list = pitchings,
customer_name = customer_name,
detail_region_info = store_address,
)
pitching_output_list = generated_subtitles.pitching_results
subtitle_modifications = {pitching_output.pitching_tag : pitching_output.pitching_data for pitching_output in pitching_output_list}
subtitle_modifications = marketing_intelligence.subtitle
modifications.update(subtitle_modifications)
# 6-3. elements 수정