forked from LiveCarta/ContentGeneration
Refactor src layout and add logging lifecycle + tests
This commit is contained in:
@@ -10,12 +10,12 @@ import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from src.scripts.logging_config import configure_logging
|
||||
from src.scripts.s3_video_storage import S3VideoStorage
|
||||
from src.logging_config import configure_logging, debug_log_lifecycle
|
||||
from src.s3_video_storage import S3VideoStorage
|
||||
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parent
|
||||
SCRIPT_DIR = PROJECT_ROOT / "src" / "scripts"
|
||||
SCRIPT_DIR = PROJECT_ROOT / "src"
|
||||
DEFAULT_BASE_DIR = PROJECT_ROOT
|
||||
DEFAULT_HUNYUAN_DIR = DEFAULT_BASE_DIR / "HunyuanVideo-1.5"
|
||||
DEFAULT_REEL_SCRIPT = DEFAULT_BASE_DIR / "reel_script.json"
|
||||
@@ -43,10 +43,15 @@ def parse_args() -> argparse.Namespace:
|
||||
parser.add_argument("--skip-merge", action="store_true")
|
||||
parser.add_argument("--skip-concat", action="store_true")
|
||||
parser.add_argument("--skip-s3-upload", action="store_true")
|
||||
parser.add_argument("--log-level", default="INFO")
|
||||
parser.add_argument(
|
||||
"--log-level",
|
||||
default=None,
|
||||
help="Logging level (overrides LOG_LEVEL env var)",
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@debug_log_lifecycle
|
||||
def run_step(name: str, cmd: list[str], cwd: Path | None = None) -> None:
|
||||
LOGGER.info("=== %s ===", name)
|
||||
LOGGER.info("$ %s", " ".join(str(part) for part in cmd))
|
||||
@@ -55,6 +60,13 @@ def run_step(name: str, cmd: list[str], cwd: Path | None = None) -> None:
|
||||
subprocess.run(cmd, check=True, cwd=str(cwd) if cwd else None)
|
||||
|
||||
|
||||
def _with_log_level(cmd: list[str], log_level: str | None) -> list[str]:
|
||||
if not log_level:
|
||||
return cmd
|
||||
return [*cmd, "--log-level", log_level]
|
||||
|
||||
|
||||
@debug_log_lifecycle
|
||||
def maybe_upload_to_s3(output_path: Path) -> None:
|
||||
bucket = os.getenv("AWS_S3_BUCKET")
|
||||
if not bucket:
|
||||
@@ -75,6 +87,7 @@ def maybe_upload_to_s3(output_path: Path) -> None:
|
||||
LOGGER.info("Uploaded output to %s", s3_uri)
|
||||
|
||||
|
||||
@debug_log_lifecycle
|
||||
def main() -> int:
|
||||
args = parse_args()
|
||||
configure_logging(args.log_level)
|
||||
@@ -100,10 +113,10 @@ def main() -> int:
|
||||
if not args.skip_generate and not args.reel_script.exists():
|
||||
run_step(
|
||||
"Generate Reel Script",
|
||||
[
|
||||
_with_log_level([
|
||||
sys.executable,
|
||||
str(SCRIPT_DIR / "generate_script.py"),
|
||||
],
|
||||
], args.log_level),
|
||||
cwd=args.base_dir,
|
||||
)
|
||||
if not args.reel_script.exists():
|
||||
@@ -113,7 +126,7 @@ def main() -> int:
|
||||
if not args.skip_generate:
|
||||
run_step(
|
||||
"Generate Videos",
|
||||
[
|
||||
_with_log_level([
|
||||
sys.executable,
|
||||
str(SCRIPT_DIR / "generate_videos.py"),
|
||||
"--hunyuan-dir",
|
||||
@@ -128,13 +141,13 @@ def main() -> int:
|
||||
str(args.audios_dir),
|
||||
"--seed",
|
||||
str(args.seed),
|
||||
],
|
||||
], args.log_level),
|
||||
)
|
||||
|
||||
if not args.skip_merge:
|
||||
run_step(
|
||||
"Merge Audio + Video",
|
||||
[
|
||||
_with_log_level([
|
||||
sys.executable,
|
||||
str(SCRIPT_DIR / "merge_audio_video.py"),
|
||||
"--videos-dir",
|
||||
@@ -143,20 +156,20 @@ def main() -> int:
|
||||
str(args.audios_dir),
|
||||
"--output-dir",
|
||||
str(args.merged_dir),
|
||||
],
|
||||
], args.log_level),
|
||||
)
|
||||
|
||||
if not args.skip_concat:
|
||||
run_step(
|
||||
"Concatenate Merged Videos",
|
||||
[
|
||||
_with_log_level([
|
||||
sys.executable,
|
||||
str(SCRIPT_DIR / "concat_merged.py"),
|
||||
"--merged-dir",
|
||||
str(args.merged_dir),
|
||||
"--output",
|
||||
str(args.output),
|
||||
],
|
||||
], args.log_level),
|
||||
)
|
||||
except subprocess.CalledProcessError as exc:
|
||||
LOGGER.exception("Pipeline failed at command: %s", exc.cmd)
|
||||
|
||||
Reference in New Issue
Block a user