gate2까지 플로우 정리

This commit is contained in:
jaehwang committed 2026-09-07 15:25:03 +09:00
1 parent 53f308eac2
commit 5e4ff5f962
15 files changed
+755 -4

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
"""⑧ bgm 수동 확인용. **Suno는 실제 과금이 나간다.**
사용: uv run python -m tests.playreel.test_bgm <goods_id>
롱컷은 나레이션을 VLM이 쓰지 않아 BGM 스타일도 안 나오므로 기본 스타일을 쓴다.
결과는 nol_<goods_id>/bgm.mp3 와 bgm.json.
"""
import asyncio
import json
import sys
from pathlib import Path
from models.tts import NarrationTimeline
from services.bgm import DEFAULT_BGM_STYLE, generate_bgm
TEST_RESULT_DIR = Path(__file__).parent.parent / "test_result" / "playreel"
async def main() -> None:
goods_id = sys.argv[1]
product_dir = TEST_RESULT_DIR / f"nol_{goods_id}"
timeline_path = product_dir / "timeline.json"
if not timeline_path.exists():
raise SystemExit(f"{timeline_path} 없음 — test_tts 를 먼저 돌릴 것")
timeline = NarrationTimeline.model_validate_json(
timeline_path.read_text(encoding="utf-8"))
print(f"나레이션 {timeline.total}s → BGM 요청 (기본 스타일)")
print(f" style : {DEFAULT_BGM_STYLE.style}")
print("Suno 생성 시작 — 최대 5분 폴링, 과금됩니다.")
audio = await generate_bgm(DEFAULT_BGM_STYLE, timeline.total, title=f"nol_{goods_id}")
mp3_path = product_dir / "bgm.mp3"
meta_path = product_dir / "bgm.json"
mp3_path.write_bytes(audio.mp3)
meta_path.write_text(json.dumps(
{"task_id": audio.task_id, "seconds": audio.seconds, "duration": audio.duration,
"style": DEFAULT_BGM_STYLE.style, "prompt": DEFAULT_BGM_STYLE.prompt},
ensure_ascii=False, indent=2), encoding="utf-8")
print(f"\n목표 {audio.seconds}s → 실제 {audio.duration}s (taskId={audio.task_id})")
print(f"{mp3_path}\n{meta_path}")
if __name__ == "__main__":
asyncio.run(main())
@@ -0,0 +1,43 @@
"""⑩ hybrid 수동 확인용 — 생성 클립 위에 원본 고정층을 덮는다.
사용: uv run python -m tests.playreel.test_hybrid_poster <goods_id> <config.json>
config는 작품별 좌표 파일이다(fixed_rects·sil_poly·glyphs·punches). 아직 사람이 쓴다.
결과는 nol_<goods_id>/hybrid.mp4 와 hybrid_proof.jpg.
"""
import sys
from pathlib import Path
from models.hybrid import LayerConfig
from services.hybrid_poster import render_hybrid
TEST_RESULT_DIR = Path(__file__).parent.parent / "test_result" / "playreel"
def main() -> None:
goods_id, config_path = sys.argv[1], Path(sys.argv[2])
product_dir = TEST_RESULT_DIR / f"nol_{goods_id}"
poster_path = product_dir / "upscaled.png"
clip_path = product_dir / "clip.mp4"
for required in (poster_path, clip_path, config_path):
if not required.exists():
raise SystemExit(f"{required} 없음")
config = LayerConfig.model_validate_json(config_path.read_text(encoding="utf-8"))
print(f"config {config_path.name} · mask={config.mask.mode}"
f" · 고정사각 {len(config.fixed_rects)} · 글리프 {len(config.glyphs)}"
f" · 펀치 {len(config.punches)} · 정합 {config.hybrid.register}")
result = render_hybrid(poster_path, clip_path.read_bytes(), config, preview=True)
video_path = product_dir / "hybrid.mp4"
video_path.write_bytes(result.video)
print(f"{result.frames}프레임 · {result.duration}초 · {len(result.video) / 1e6:.1f}MB")
if result.proof:
proof_path = product_dir / "hybrid_proof.jpg"
result.proof.save(proof_path, quality=85)
print(f"{proof_path}")
print(f"{video_path}")
if __name__ == "__main__":
main()
+44
View File
@@ -0,0 +1,44 @@
"""⑨ i2v 수동 확인용 — 되돌릴 수 없는 지점이다.
사용: uv run python -m tests.playreel.test_i2v <goods_id>
업스케일 포스터와 ⑤에서 확정한 프롬프트를 쓴다.
detect를 안 거쳐 regions가 없으므로 제목 훼손 게이트는 돌지 않는다.
결과는 nol_<goods_id>/clip.mp4 와 i2v.json.
"""
import asyncio
import json
import sys
from pathlib import Path
from services.i2v import animate
TEST_RESULT_DIR = Path(__file__).parent.parent / "test_result" / "playreel"
async def main() -> None:
goods_id = sys.argv[1]
product_dir = TEST_RESULT_DIR / f"nol_{goods_id}"
poster_path = product_dir / "upscaled.png"
prompt_path = product_dir / "i2v_prompt.txt"
for required in (poster_path, prompt_path):
if not required.exists():
raise SystemExit(f"{required} 없음 — 앞 단계를 먼저 돌릴 것")
result = await animate(prompt_path.read_text(encoding="utf-8").strip(), poster_path)
clip_path = product_dir / "clip.mp4"
summary_path = product_dir / "i2v.json"
clip_path.write_bytes(result.clip)
summary_path.write_text(json.dumps(
{"model": result.model, "credits": result.credits,
"title_gate": result.title_gate.model_dump()},
ensure_ascii=False, indent=2), encoding="utf-8")
print(f"{result.model} · {result.credits}크레딧 · {len(result.clip) / 1e6:.1f}MB")
if result.title_gate.skip:
print(f"제목 게이트: {result.title_gate.skip}")
print(f"\n{clip_path}\n{summary_path}")
if __name__ == "__main__":
asyncio.run(main())
+55
View File
@@ -0,0 +1,55 @@
"""⑤ motion 수동 확인용 — 게이트 ②에서 사람이 고른 요소로 프롬프트를 확정한다.
사용: uv run python -m tests.playreel.test_motion <goods_id> [모션키,쉼표구분]
모션키를 생략하면 analysis.json 에서 켜진(on) 요소를 그대로 쓴다.
결과는 nol_<goods_id>/i2v_prompt.txt 와 motion.json.
"""
import asyncio
import json
import sys
from pathlib import Path
from services.motion import plan_motion
TEST_RESULT_DIR = Path(__file__).parent.parent / "test_result" / "playreel"
def chosen_motions(product_dir: Path) -> list[str]:
analysis_path = product_dir / "analysis.json"
if not analysis_path.exists():
raise SystemExit(f"{analysis_path} 없음 — test_analyze_poster 를 먼저 돌릴 것")
analysis = json.loads(analysis_path.read_text(encoding="utf-8"))
return [choice["key"] for choice in analysis["movable"] if choice["on"]]
async def main() -> None:
goods_id = sys.argv[1]
product_dir = TEST_RESULT_DIR / f"nol_{goods_id}"
poster_path = product_dir / "upscaled.png"
if not poster_path.exists():
raise SystemExit(f"{poster_path} 없음 — test_upscale_poster 를 먼저 돌릴 것")
if len(sys.argv) > 2:
keys = [key.strip() for key in sys.argv[2].split(",") if key.strip()]
else:
keys = chosen_motions(product_dir)
print(f"고른 요소 {keys or '(없음)'}")
plan = await plan_motion(poster_path, force_motions=keys)
prompt_path = product_dir / "i2v_prompt.txt"
summary_path = product_dir / "motion.json"
prompt_path.write_text(plan.prompt, encoding="utf-8")
summary_path.write_text(plan.model_dump_json(indent=2, exclude={"prompt"}),
encoding="utf-8")
print(f"QR {'있음' if plan.has_qr else '없음'} · 채택 {len(plan.kept)}종")
for item in plan.kept:
print(f" ✓ {item.motion:9} {item.what}")
if not plan.kept:
print("\n※ 요소가 0종이다 — i2v가 정지 이미지를 애니메이션하지 못한다")
print(f"\n{prompt_path}\n{summary_path}")
if __name__ == "__main__":
asyncio.run(main())
@@ -0,0 +1,42 @@
"""⑥ narration 수동 확인용 — meta와 캐스트로 7문장을 채운다.
사용: uv run python -m tests.playreel.test_narration_slots <goods_id>
결과는 nol_<goods_id>/narration.json.
"""
import sys
from pathlib import Path
from models.cast import CastExtraction
from models.nol import NolMeta
from services.narration_slots import build_narration
TEST_RESULT_DIR = Path(__file__).parent.parent / "test_result" / "playreel"
def main() -> None:
goods_id = sys.argv[1]
product_dir = TEST_RESULT_DIR / f"nol_{goods_id}"
meta_path = product_dir / "meta.json"
if not meta_path.exists():
raise SystemExit(f"{meta_path} 없음 — test_fetch_nol 을 먼저 돌릴 것")
meta = NolMeta.model_validate_json(meta_path.read_text(encoding="utf-8"))
cast_path = product_dir / "cast.json"
cast = (CastExtraction.model_validate_json(cast_path.read_text(encoding="utf-8"))
if cast_path.exists() else None)
narration = build_narration(meta, cast)
narration_path = product_dir / "narration.json"
narration_path.write_text(narration.model_dump_json(indent=2), encoding="utf-8")
total_chars = sum(len(line.text) for line in narration.lines)
for line in narration.lines:
print(f" {line.slot:12} {line.text}")
print(f"\n7문장 {total_chars}자")
if cast is None or cast.source != "vlm":
print("※ 캐스트가 없어 4번 문장이 안내 문구로 대체됐다")
print(f"\n{narration_path}")
if __name__ == "__main__":
main()
+46
View File
@@ -0,0 +1,46 @@
"""⑦ tts 수동 확인용 — Typecast로 7문장을 읽는다.
사용: uv run python -m tests.playreel.test_tts <goods_id>
.env 의 TYPECAST_API_KEY 와 TYPECAST_VOICE_ID 가 필요하다.
결과는 nol_<goods_id>/narration.mp3 와 timeline.json.
"""
import asyncio
import sys
from pathlib import Path
from models.narration_slots import SlotNarration
from models.tts import TypecastVoice
from services.tts import synthesize
from settings import settings
TEST_RESULT_DIR = Path(__file__).parent.parent / "test_result" / "playreel"
LONGCUT_SECONDS = 30
async def main() -> None:
goods_id = sys.argv[1]
product_dir = TEST_RESULT_DIR / f"nol_{goods_id}"
narration_path = product_dir / "narration.json"
if not narration_path.exists():
raise SystemExit(f"{narration_path} 없음 — test_narration_slots 를 먼저 돌릴 것")
if not settings.typecast_api_key:
raise SystemExit("TYPECAST_API_KEY 없음 — 롱컷은 Typecast 고정이다")
narration = SlotNarration.model_validate_json(narration_path.read_text(encoding="utf-8"))
audio = await synthesize(narration.texts, typecast=TypecastVoice())
mp3_path = product_dir / "narration.mp3"
timeline_path = product_dir / "timeline.json"
mp3_path.write_bytes(audio.mp3)
timeline_path.write_text(audio.timeline.model_dump_json(indent=2), encoding="utf-8")
for cue in audio.timeline.cues:
print(f" [{cue.index}] {cue.start:5.2f}s +{cue.duration:4.2f}s {cue.text}")
print(f"\n총 {audio.timeline.total}s")
if audio.timeline.total > LONGCUT_SECONDS:
print(f"※ {LONGCUT_SECONDS}초를 넘는다 — 문장을 줄이거나 속도를 올려야 한다")
print(f"\n{mp3_path}\n{timeline_path}")
if __name__ == "__main__":
asyncio.run(main())
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Playreel 롱컷 — 게이트 ② 승인 뒤, 게이트 ③(narration_confirm) 직전까지.
# 사용: tests/run_playreel_after_gate2.sh <goods_id> [모션키,쉼표구분]
set -euo pipefail
cd "$(dirname "$0")/.."
goods_id="${1:?사용: $0 <goods_id> [모션키,쉼표구분]}"
run() { echo; echo "── $1 ──"; shift; uv run python -m "$@"; }
run "⑤ motion" tests.playreel.test_motion "$goods_id" ${2+"$2"}
run "⑥ narration" tests.playreel.test_narration_slots "$goods_id"
cat <<EOF
══ 게이트 ③ narration_confirm — 사람이 정해야 이어진다 ══
확인할 것
narration.json 7문장. 캐스팅 스케줄 문장은 빼면 안 된다
캐스트를 못 읽었으면 4번 문장이 안내 문구로 대체돼 있다
i2v_prompt.txt 확정된 i2v 프롬프트
승인 후 — 게이트 ④까지 간다
tests/run_playreel_after_gate3.sh "$goods_id"
EOF
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Playreel 롱컷 — 게이트 ③ 승인 뒤, 게이트 ④(clip_confirm) 직전까지.
# 사용: tests/run_playreel_after_gate3.sh <goods_id>
set -euo pipefail
cd "$(dirname "$0")/.."
goods_id="${1:?사용: $0 <goods_id>}"
run() { echo; echo "── $1 ──"; shift; uv run python -m "$@"; }
run "⑦ tts" tests.playreel.test_tts "$goods_id"
run "⑧ bgm" tests.playreel.test_bgm "$goods_id"
run "⑨ i2v" tests.playreel.test_i2v "$goods_id"
cat <<EOF
══ 게이트 ④ clip_confirm — 사람이 정해야 이어진다 ══
확인할 것
clip.mp4 제목이 훼손되지 않았는지. regions가 없어 자동 게이트가 안 돌므로 눈으로 봐야 한다
i2v.json 쓴 크레딧과 게이트 상태
다시 만들려면 clip.mp4 를 지우고 ⑨를 다시 돌린다 — 그때만 크레딧이 다시 든다.
⑩ hybrid · ⑪ compose 는 아직 서비스가 없다.
EOF