test 파일 이동
This commit is contained in:
1 parent
659fd53b97
commit
5c84733a8b
8 files changed
+12
-11
No files matched your search
@@ -0,0 +1,58 @@
|
||||
"""bgm 수동 확인용. **Suno는 실제 과금이 나간다.**
|
||||
|
||||
사용: uv run python -m tests.test_bgm <포스터경로>
|
||||
test_result/<이름>.narration.txt(bgm_style)와 <이름>.tts.txt(total)를 재사용한다.
|
||||
없으면 앞 단계부터 돌린다. 결과는 <이름>.bgm.mp3 와 <이름>.bgm.txt.
|
||||
"""
|
||||
import asyncio
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from models.tts import NarrationTimeline
|
||||
from services.bgm import generate_bgm
|
||||
from services.tts import synthesize
|
||||
from tests.test_tts import load_narration
|
||||
|
||||
TEST_RESULT_DIR = Path(__file__).parent / "test_result"
|
||||
|
||||
|
||||
async def load_timeline(sentences: list[str], voice: str, timeline_path: Path
|
||||
) -> NarrationTimeline:
|
||||
if timeline_path.exists():
|
||||
return NarrationTimeline.model_validate_json(timeline_path.read_text(encoding="utf-8"))
|
||||
audio = await synthesize(sentences, voice)
|
||||
timeline_path.write_text(audio.timeline.model_dump_json(indent=2), encoding="utf-8")
|
||||
return audio.timeline
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
poster_path = Path(sys.argv[1])
|
||||
TEST_RESULT_DIR.mkdir(exist_ok=True)
|
||||
output_base = TEST_RESULT_DIR / poster_path.stem
|
||||
|
||||
answer = await load_narration(poster_path, output_base)
|
||||
timeline = await load_timeline(answer.narration, answer.voice,
|
||||
output_base.with_suffix(".tts.txt"))
|
||||
|
||||
print(f"나레이션 {timeline.total}s → BGM 요청")
|
||||
print(f" style : {answer.bgm_style.style}")
|
||||
print(f" prompt: {answer.bgm_style.prompt}")
|
||||
print("Suno 생성 시작 — 최대 5분 폴링, 과금됩니다.")
|
||||
|
||||
audio = await generate_bgm(answer.bgm_style, timeline.total, title=poster_path.stem)
|
||||
|
||||
mp3_path = output_base.with_suffix(".bgm.mp3")
|
||||
meta_path = output_base.with_suffix(".bgm.txt")
|
||||
mp3_path.write_bytes(audio.mp3)
|
||||
meta_path.write_text(json.dumps(
|
||||
{"task_id": audio.task_id, "seconds": audio.seconds, "duration": audio.duration,
|
||||
"style": answer.bgm_style.style, "prompt": answer.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,33 @@
|
||||
"""detect 수동 확인용.
|
||||
|
||||
사용: uv run python -m tests.test_detect <포스터경로>
|
||||
결과는 test_result/ 아래에 .detect.txt / .grid.jpg / .check.jpg 세 파일로 떨어진다.
|
||||
"""
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from services.detect import detect
|
||||
|
||||
TEST_RESULT_DIR = Path(__file__).parent / "test_result"
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
poster_path = Path(sys.argv[1])
|
||||
TEST_RESULT_DIR.mkdir(exist_ok=True)
|
||||
output_base = TEST_RESULT_DIR / poster_path.stem
|
||||
|
||||
result = await detect(poster_path)
|
||||
|
||||
text_path = output_base.with_suffix(".detect.txt")
|
||||
grid_path = output_base.with_suffix(".grid.jpg")
|
||||
check_path = output_base.with_suffix(".check.jpg")
|
||||
|
||||
text_path.write_text(result.data.model_dump_json(indent=2), encoding="utf-8")
|
||||
result.grid.save(grid_path, quality=90)
|
||||
result.check.save(check_path, quality=90)
|
||||
print(text_path, grid_path, check_path, sep="\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,54 @@
|
||||
"""i2v 수동 확인용.
|
||||
|
||||
사용: uv run python -m tests.test_i2v <포스터경로>
|
||||
test_result/<이름>.i2v.txt(프롬프트)와 <이름>.detect.txt(영역)를 쓴다.
|
||||
결과는 <이름>.clip.mp4 와 <이름>.title_gate.txt.
|
||||
"""
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from models.detect import Regions
|
||||
from services.i2v import DEFAULT_MODEL, animate, cli_args
|
||||
from utils.higgsfield import run_cli
|
||||
|
||||
TEST_RESULT_DIR = Path(__file__).parent / "test_result"
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
poster_path = Path(sys.argv[1])
|
||||
output_base = TEST_RESULT_DIR / poster_path.stem
|
||||
|
||||
prompt_path = output_base.with_suffix(".i2v.txt")
|
||||
detect_path = output_base.with_suffix(".detect.txt")
|
||||
for required in (prompt_path, detect_path):
|
||||
if not required.exists():
|
||||
raise SystemExit(f"{required} 없음 — 앞 단계를 먼저 돌릴 것")
|
||||
|
||||
prompt = prompt_path.read_text(encoding="utf-8").strip()
|
||||
regions = Regions.model_validate_json(detect_path.read_text(encoding="utf-8"))
|
||||
|
||||
raw = await run_cli("generate", "cost", DEFAULT_MODEL,
|
||||
*cli_args(prompt, poster_path, DEFAULT_MODEL), "--json", timeout=300)
|
||||
print(f"=== generate cost 원본 출력 ({len(raw)}자) ===\n{raw}\n=== 끝 ===\n")
|
||||
|
||||
result = await animate(prompt, poster_path, regions)
|
||||
|
||||
clip_path = output_base.with_suffix(".clip.mp4")
|
||||
verdict_path = output_base.with_suffix(".title_gate.txt")
|
||||
clip_path.write_bytes(result.clip)
|
||||
verdict_path.write_text(result.title_gate.model_dump_json(indent=2), encoding="utf-8")
|
||||
|
||||
verdict = result.title_gate
|
||||
print(f"{result.model} · {result.credits} 크레딧 · {len(result.clip) / 1e6:.1f}MB")
|
||||
print(f"제목 게이트 {'통과' if verdict.passed else '실패'} 픽셀 A={verdict.pixel_score}"
|
||||
f"{' (하드컷 초과)' if verdict.pixel_hard else ''}")
|
||||
if verdict.skip:
|
||||
print(f" 판정 생략: {verdict.skip}")
|
||||
for frame in verdict.frames:
|
||||
print(f" {'✓' if frame.legible else '✗'} t={frame.time}s {frame.broken}")
|
||||
print(f"\n{clip_path}\n{verdict_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,44 @@
|
||||
"""motion 수동 확인용.
|
||||
|
||||
사용: uv run python -m tests.test_motion <포스터경로> [모션키,쉼표구분]
|
||||
모션키를 주면 VLM을 건너뛰고 그 목록으로 프롬프트를 만든다(빈 문자열이면 0종).
|
||||
결과는 test_result/<이름>.motion.txt(채택·탈락)와 <이름>.i2v.txt(프롬프트 원문)로 떨어진다.
|
||||
"""
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from services.motion import plan_motion
|
||||
|
||||
TEST_RESULT_DIR = Path(__file__).parent / "test_result"
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
poster_path = Path(sys.argv[1])
|
||||
force_motions = None
|
||||
if len(sys.argv) > 2:
|
||||
force_motions = [key.strip() for key in sys.argv[2].split(",") if key.strip()]
|
||||
|
||||
TEST_RESULT_DIR.mkdir(exist_ok=True)
|
||||
output_base = TEST_RESULT_DIR / poster_path.stem
|
||||
|
||||
plan = await plan_motion(poster_path, force_motions=force_motions)
|
||||
|
||||
summary_path = output_base.with_suffix(".motion.txt")
|
||||
prompt_path = output_base.with_suffix(".i2v.txt")
|
||||
summary_path.write_text(
|
||||
plan.model_dump_json(indent=2, exclude={"prompt"}), encoding="utf-8")
|
||||
prompt_path.write_text(plan.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}")
|
||||
for item in plan.dropped:
|
||||
print(f" ✗ {item.motion:9} {item.what} — {item.why}")
|
||||
if not plan.kept:
|
||||
print("\n※ 움직일 요소가 없다 — i2v를 건너뛰고 정지 포스터로 가는 것이 안전하다.")
|
||||
print(f"\n{summary_path}\n{prompt_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,40 @@
|
||||
"""narration 수동 확인용.
|
||||
|
||||
사용: uv run python -m tests.test_narration <포스터경로>
|
||||
같은 포스터의 test_result/<이름>.detect.txt 가 있으면 재사용하고, 없으면 detect부터 돌린다.
|
||||
결과는 test_result/<이름>.narration.txt 로 떨어진다.
|
||||
"""
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from models.detect import Regions
|
||||
from services.detect import detect
|
||||
from services.narration import generate_narration
|
||||
|
||||
TEST_RESULT_DIR = Path(__file__).parent / "test_result"
|
||||
|
||||
|
||||
async def load_regions(poster_path: Path, detect_path: Path) -> Regions:
|
||||
if detect_path.exists():
|
||||
return Regions.model_validate_json(detect_path.read_text(encoding="utf-8"))
|
||||
result = await detect(poster_path)
|
||||
detect_path.write_text(result.data.model_dump_json(indent=2), encoding="utf-8")
|
||||
return result.data
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
poster_path = Path(sys.argv[1])
|
||||
TEST_RESULT_DIR.mkdir(exist_ok=True)
|
||||
output_base = TEST_RESULT_DIR / poster_path.stem
|
||||
|
||||
regions = await load_regions(poster_path, output_base.with_suffix(".detect.txt"))
|
||||
answer = await generate_narration(poster_path, regions)
|
||||
|
||||
narration_path = output_base.with_suffix(".narration.txt")
|
||||
narration_path.write_text(answer.model_dump_json(indent=2), encoding="utf-8")
|
||||
print(narration_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,50 @@
|
||||
"""render 수동 확인용.
|
||||
|
||||
사용: uv run python -m tests.test_render <포스터경로> [클립경로]
|
||||
클립을 생략하면 test_result/<이름>.clip.mp4 를 쓴다.
|
||||
나레이션(.tts.mp3)·타임라인(.tts.txt)·BGM(.bgm.mp3)은 있으면 얹고 없으면 건너뛴다.
|
||||
결과는 <이름>.final.mp4 와 <이름>.thumb.jpg.
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from models.tts import NarrationTimeline
|
||||
from services.render import render
|
||||
|
||||
TEST_RESULT_DIR = Path(__file__).parent / "test_result"
|
||||
|
||||
|
||||
def read_if_exists(path: Path) -> bytes | None:
|
||||
return path.read_bytes() if path.exists() else None
|
||||
|
||||
|
||||
def main() -> None:
|
||||
poster_path = Path(sys.argv[1])
|
||||
output_base = TEST_RESULT_DIR / poster_path.stem
|
||||
clip_path = Path(sys.argv[2]) if len(sys.argv) > 2 else output_base.with_suffix(".clip.mp4")
|
||||
if not clip_path.exists():
|
||||
raise SystemExit(f"클립 없음: {clip_path}")
|
||||
|
||||
timeline_path = output_base.with_suffix(".tts.txt")
|
||||
timeline = (NarrationTimeline.model_validate_json(timeline_path.read_text(encoding="utf-8"))
|
||||
if timeline_path.exists() else None)
|
||||
narration = read_if_exists(output_base.with_suffix(".tts.mp3"))
|
||||
bgm = read_if_exists(output_base.with_suffix(".bgm.mp3"))
|
||||
print(f"클립 {clip_path.name} / 나레이션 {'있음' if narration else '없음'}"
|
||||
f" / BGM {'있음' if bgm else '없음'}")
|
||||
|
||||
result = render(clip_path.read_bytes(), poster_path,
|
||||
narration=narration, bgm=bgm, timeline=timeline)
|
||||
|
||||
video_path = output_base.with_suffix(".final.mp4")
|
||||
thumb_path = output_base.with_suffix(".thumb.jpg")
|
||||
video_path.write_bytes(result.video)
|
||||
thumb_path.write_bytes(result.thumbnail)
|
||||
|
||||
print(f"{result.width}x{result.height} · {result.frames}프레임 · {result.duration:.2f}초 "
|
||||
f"· {len(result.video) / 1e6:.1f}MB")
|
||||
print(f"\n{video_path}\n{thumb_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,53 @@
|
||||
"""tts 수동 확인용.
|
||||
|
||||
사용: uv run python -m tests.test_tts <포스터경로>
|
||||
test_result/<이름>.narration.txt 가 있으면 재사용하고, 없으면 앞 단계부터 돌린다.
|
||||
결과는 <이름>.tts.mp3(합쳐진 나레이션)와 <이름>.tts.txt(타임라인)로 떨어진다.
|
||||
"""
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from answers.narration_answer import NarrationAnswer
|
||||
from services.narration import generate_narration
|
||||
from services.tts import synthesize
|
||||
from tests.test_narration import load_regions
|
||||
|
||||
TEST_RESULT_DIR = Path(__file__).parent / "test_result"
|
||||
|
||||
|
||||
async def load_narration(poster_path: Path, output_base: Path) -> NarrationAnswer:
|
||||
narration_path = output_base.with_suffix(".narration.txt")
|
||||
if narration_path.exists():
|
||||
return NarrationAnswer.model_validate_json(narration_path.read_text(encoding="utf-8"))
|
||||
regions = await load_regions(poster_path, output_base.with_suffix(".detect.txt"))
|
||||
answer = await generate_narration(poster_path, regions)
|
||||
narration_path.write_text(answer.model_dump_json(indent=2), encoding="utf-8")
|
||||
return answer
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
poster_path = Path(sys.argv[1])
|
||||
TEST_RESULT_DIR.mkdir(exist_ok=True)
|
||||
output_base = TEST_RESULT_DIR / poster_path.stem
|
||||
|
||||
answer = await load_narration(poster_path, output_base)
|
||||
audio = await synthesize(answer.narration, answer.voice)
|
||||
|
||||
mp3_path = output_base.with_suffix(".tts.mp3")
|
||||
timeline_path = output_base.with_suffix(".tts.txt")
|
||||
mp3_path.write_bytes(audio.mp3)
|
||||
timeline_path.write_text(audio.timeline.model_dump_json(indent=2), encoding="utf-8")
|
||||
|
||||
print(f"engine={audio.timeline.engine} voice={audio.timeline.voice}")
|
||||
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.cues[-1].end:.2f}s "
|
||||
f"+ 여백 {audio.timeline.tail}s → 영상 길이 {audio.timeline.total}s")
|
||||
if audio.timeline.total > 8:
|
||||
print("※ 8초를 넘는다 — 영상이 8초 고정이라 나레이션이 잘린다")
|
||||
print(f"\n{mp3_path}\n{timeline_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in new issue
Block a user