Spaces:
Sleeping
Sleeping
File size: 8,242 Bytes
67ce4ed | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | """CLI entry point for the Humeo pipeline."""
import argparse
import logging
import sys
from datetime import datetime
from pathlib import Path
from humeo.config import PipelineConfig
from humeo.pipeline import run_pipeline
def setup_logging(verbose: bool = False):
"""Configure logging with a clean format."""
level = logging.DEBUG if verbose else logging.INFO
logging.basicConfig(
level=level,
format="%(asctime)s | %(levelname)-7s | %(name)s | %(message)s",
datefmt="%H:%M:%S",
handlers=[logging.StreamHandler(sys.stdout)],
)
# Suppress noisy third-party loggers
logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger("httpx").setLevel(logging.WARNING)
def build_parser() -> argparse.ArgumentParser:
"""Build the argument parser."""
parser = argparse.ArgumentParser(
prog="humeo",
description="Humeo - Automated podcast-to-shorts pipeline from YouTube or local MP4",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
humeo --long-to-shorts "https://youtube.com/watch?v=abc123"
humeo --long-to-shorts "C:\\Videos\\episode.mp4"
humeo --long-to-shorts "https://youtube.com/watch?v=abc123" --work-dir .humeo_work
humeo --long-to-shorts "https://youtube.com/watch?v=abc123" --gemini-model gemini-2.0-flash
""",
)
parser.add_argument(
"--long-to-shorts",
metavar="SOURCE",
required=True,
help="YouTube video URL or local MP4 path to process",
)
parser.add_argument(
"--output", "-o",
type=Path,
default=Path("output"),
help="Output directory for final shorts (default: ./output)",
)
parser.add_argument(
"--work-dir",
type=Path,
default=None,
help="Working directory for intermediate files. Default: per-video folder under the "
"cache root (see docs/ENVIRONMENT.md). Use this to force e.g. ./.humeo_work.",
)
parser.add_argument(
"--no-video-cache",
action="store_true",
help="Do not use per-video cache dirs; use ./.humeo_work unless --work-dir is set.",
)
parser.add_argument(
"--cache-root",
type=Path,
default=None,
help="Override cache root for manifests and per-video ingest (env: HUMEO_CACHE_ROOT).",
)
parser.add_argument(
"--gemini-model",
default=None,
help="Gemini model id for clip selection (default: GEMINI_MODEL env; see humeo.config).",
)
parser.add_argument(
"--force-clip-selection",
action="store_true",
help="Re-run clip-selection LLM even when clips.meta.json matches the transcript.",
)
parser.add_argument(
"--gemini-vision-model",
default=None,
help="Gemini model for per-keyframe layout + bbox (default: GEMINI_VISION_MODEL env or --gemini-model).",
)
parser.add_argument(
"--force-layout-vision",
action="store_true",
help="Re-run Gemini vision for layouts even when layout_vision.meta.json matches.",
)
parser.add_argument(
"--prune-level",
choices=["off", "conservative", "balanced", "aggressive"],
default="balanced",
help=(
"Stage 2.5 inner-clip content pruning aggressiveness. "
"'off' skips pruning entirely; 'conservative' trims <=10%%, "
"'balanced' <=20%%, 'aggressive' <=35%% of each clip "
"(always clamped to the MIN_CLIP_DURATION_SEC floor). Default: balanced."
),
)
parser.add_argument(
"--force-content-pruning",
action="store_true",
help="Re-run content-pruning LLM even when prune.meta.json matches.",
)
parser.add_argument(
"--no-hook-detection",
action="store_true",
help=(
"Skip Stage 2.25 hook detection. The selector's hook window "
"(possibly the 0.0-3.0s placeholder) will be carried through. "
"Stage 2.5 content pruning still treats that exact placeholder "
"as 'no hook' so pruning is not disabled."
),
)
parser.add_argument(
"--force-hook-detection",
action="store_true",
help="Re-run hook-detection LLM even when hooks.meta.json matches.",
)
parser.add_argument(
"--clean-run",
action="store_true",
help=(
"Run with a fresh work dir and no cache reuse. Implies --no-video-cache, "
"--force-clip-selection, --force-layout-vision, and overwrite existing outputs."
),
)
parser.add_argument(
"--interactive", "-i",
action="store_true",
help="Pause after clip selection and after render for human approval.",
)
parser.add_argument(
"--subtitle-font-size",
type=int,
default=48,
help=(
"Caption font size in output pixels. libass is pinned to "
"original_size=1080x1920, so this is a true pixel value. "
"(default: 48)"
),
)
parser.add_argument(
"--subtitle-margin-v",
type=int,
default=160,
help="Caption bottom margin in output pixels (default: 160)",
)
parser.add_argument(
"--subtitle-max-words",
type=int,
default=4,
help="Max words per subtitle cue (default: 4)",
)
parser.add_argument(
"--subtitle-max-cue-sec",
type=float,
default=2.2,
help="Max subtitle cue duration in seconds (default: 2.2)",
)
parser.add_argument(
"--verbose", "-v",
action="store_true",
help="Enable debug logging",
)
return parser
def main():
"""CLI entry point."""
parser = build_parser()
args = parser.parse_args()
setup_logging(args.verbose)
use_video_cache = not args.no_video_cache
force_clip_selection = args.force_clip_selection
force_layout_vision = args.force_layout_vision
force_content_pruning = args.force_content_pruning
force_hook_detection = args.force_hook_detection
detect_hooks = not args.no_hook_detection
overwrite_outputs = False
work_dir = args.work_dir
if args.clean_run:
use_video_cache = False
force_clip_selection = True
force_layout_vision = True
force_content_pruning = True
force_hook_detection = True
overwrite_outputs = True
if work_dir is None:
stamp = datetime.now().strftime("%Y%m%d_%H%M%S")
work_dir = Path(f".humeo_work_clean_{stamp}")
config = PipelineConfig(
youtube_url=args.long_to_shorts,
output_dir=args.output,
work_dir=work_dir,
use_video_cache=use_video_cache,
cache_root=args.cache_root,
gemini_model=args.gemini_model,
gemini_vision_model=args.gemini_vision_model,
force_clip_selection=force_clip_selection,
force_layout_vision=force_layout_vision,
clean_run=args.clean_run,
overwrite_outputs=overwrite_outputs,
interactive=args.interactive,
prune_level=args.prune_level,
force_content_pruning=force_content_pruning,
detect_hooks=detect_hooks,
force_hook_detection=force_hook_detection,
subtitle_font_size=args.subtitle_font_size,
subtitle_margin_v=args.subtitle_margin_v,
subtitle_max_words_per_cue=args.subtitle_max_words,
subtitle_max_cue_sec=args.subtitle_max_cue_sec,
)
try:
outputs = run_pipeline(config)
print(f"\nDone. {len(outputs)} shorts generated in: {config.output_dir}")
for p in outputs:
print(f" -> {p}")
except KeyboardInterrupt:
print("\nPipeline interrupted.")
sys.exit(1)
except Exception as e:
logging.getLogger(__name__).error("Pipeline failed: %s", e, exc_info=True)
sys.exit(1)
if __name__ == "__main__":
main()
|