41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
"""narration 수동 확인용.
|
|
|
|
사용: uv run python test_narration.py <포스터경로>
|
|
같은 포스터의 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())
|