-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
253 lines (220 loc) · 11.1 KB
/
Copy pathmain.py
File metadata and controls
253 lines (220 loc) · 11.1 KB
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
#!/usr/bin/env python3
"""DarcAds command-line interface.
Examples
--------
Generate one ad with whatever engines are available:
python3 main.py --url https://store.com/products/thing
Generate three A/B variants at 30 seconds, with music and a brand kit:
python3 main.py --url https://store.com/products/thing \\
--variants 3 --seconds 30 --music assets/music/upbeat.mp3 \\
--brand-name "Acme" --accent "#FF4D6D" --cta "Get 20% off"
"""
import argparse
import sys
from src.avatars import list_actors
from src.config import (
AVATAR_MODEL_CHOICES,
PLATFORM_PRESETS,
QUALITY_PRESETS,
VIDEO_MODEL_CHOICES,
available_providers,
ensure_env_loaded,
)
from src.llm_director import HOOK_FRAMEWORKS
from src.models import BrandKit
from src.pipeline import run_darcads_pipeline, run_movie_pipeline
from src.utils import FFmpegError, ffmpeg_available, log, warn
from src.voice import ENGINE_ORDER, VOICE_CHOICES
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog="darcads",
description="DarcAds / Darc Studio - AI Video, Movie & Ad Generation Suite",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=__doc__,
)
core = parser.add_argument_group("core")
core.add_argument("--mode", type=str, default="ad", choices=["ad", "movie", "viral_scene"],
help="Creation mode: ad (from product URL), movie (cinematic scenes), or viral_scene")
core.add_argument("--url", type=str, default=None, help="Product page URL to advertise (ad mode)")
core.add_argument("--premise", type=str, default=None, help="Story premise or movie scene concept (movie mode)")
core.add_argument("--style", type=str, default="hyper_realistic",
choices=["hyper_realistic", "cinematic_hollywood", "dark_fantasy", "cyberpunk", "anime_cinematic", "retro_35mm_film", "3d_pixar", "analog_noir", "documentary"],
help="Cinematic visual style")
core.add_argument("--output", type=str, default="output/final_video.mp4", help="Output MP4 path")
core.add_argument("--variants", type=int, default=1, help="Number of creative variants to produce")
core.add_argument("--seconds", type=float, default=20.0, help="Target runtime in seconds")
core.add_argument("--framework", type=str, default="pas", choices=sorted(HOOK_FRAMEWORKS.keys()),
help="Hook / narrative framework")
core.add_argument("--doctor", action="store_true", help="Report which engines are configured, then exit")
script = parser.add_argument_group("script engine")
script.add_argument("--provider", type=str, default="auto",
choices=["auto", "anthropic", "openai", "openai_compatible", "offline"])
script.add_argument("--model", type=str, default=None, help="LLM model name override")
script.add_argument("--base-url", type=str, default=None, help="Custom LLM base URL (Ollama, LM Studio)")
audio = parser.add_argument_group("audio")
audio.add_argument("--voice", type=str, default="female_energetic", choices=VOICE_CHOICES)
audio.add_argument("--tts", type=str, default="auto", choices=["auto"] + ENGINE_ORDER)
audio.add_argument("--music", type=str, default=None, help="Background music track")
audio.add_argument("--music-volume", type=float, default=0.18, help="Music level, 0 to 1")
audio.add_argument("--no-duck", action="store_true", help="Disable side-chain ducking of the music")
visual = parser.add_argument_group("visuals")
visual.add_argument("--video-model", type=str, default="wan-2.1", choices=VIDEO_MODEL_CHOICES)
visual.add_argument("--platform", type=str, default="tiktok", choices=sorted(PLATFORM_PRESETS.keys()))
visual.add_argument("--quality", type=str, default="standard", choices=sorted(QUALITY_PRESETS.keys()))
visual.add_argument("--captions", type=str, default="karaoke",
choices=["karaoke", "word_pop", "block", "none"])
visual.add_argument("--transition", type=str, default="fade",
choices=["none", "fade", "slideleft", "slideright", "wipeleft", "circleopen", "dissolve", "smoothleft"])
visual.add_argument("--transition-seconds", type=float, default=0.35,
help="Crossfade length; scenes shorter than ~1.6x this fall back to hard cuts")
visual.add_argument("--no-generation", action="store_true",
help="Never call paid video generation; use product photos and designed frames")
visual.add_argument("--no-whisper", action="store_true",
help="Skip Whisper alignment and estimate caption timings instead")
avatar = parser.add_argument_group("UGC avatar")
avatar.add_argument("--avatar", action="store_true", help="Use a lip-synced presenter for every scene")
avatar.add_argument("--actor", type=str, default=None, help="Actor name, file path or URL")
avatar.add_argument("--avatar-model", type=str, default="auto",
choices=["auto"] + AVATAR_MODEL_CHOICES)
avatar.add_argument("--list-actors", action="store_true", help="List available actors, then exit")
brand = parser.add_argument_group("brand kit")
brand.add_argument("--brand-name", type=str, default=None)
brand.add_argument("--logo", type=str, default=None, help="Path to a transparent PNG logo")
brand.add_argument("--accent", type=str, default="#00E5A0", help="Accent colour for captions and CTA")
brand.add_argument("--text-color", type=str, default="#FFFFFF", help="Base caption colour")
brand.add_argument("--cta", type=str, default="Shop now", help="End card call to action")
brand.add_argument("--cta-seconds", type=float, default=1.6, help="End card length; 0 disables it")
brand.add_argument("--font", type=str, default=None, help="Font family name or .ttf path")
return parser
def print_doctor() -> None:
"""Prints a readable report of what is and is not configured."""
ensure_env_loaded()
log("DarcAds environment check\n")
ffmpeg_ok = ffmpeg_available()
print(f" {'ok ' if ffmpeg_ok else 'MISSING'} ffmpeg + ffprobe")
if not ffmpeg_ok:
print(" DarcAds cannot render without ffmpeg. See the README for install steps.")
providers = available_providers()
labels = {
"anthropic": "Anthropic (script engine)",
"openai": "OpenAI (script engine + TTS)",
"ollama": "Ollama / local LLM",
"elevenlabs": "ElevenLabs (premium voice)",
"kokoro": "Kokoro-82M (local voice)",
"edge_tts": "edge-tts (free voice)",
"fal": "fal.ai (video + avatars)",
"replicate": "Replicate (video)",
"comfyui": "ComfyUI (local video)",
"whisper": "faster-whisper (caption sync)",
}
print()
for key, label in labels.items():
print(f" {'ok ' if providers.get(key) else '- '} {label}")
actors = list_actors()
print(f"\n {len(actors)} UGC actor asset(s) available"
+ (f": {', '.join(sorted(actors))}" if actors else " (add files to assets/actors/)"))
print("\n DarcAds runs fully offline with no keys - quality simply improves as you add them.")
def main() -> None:
parser = build_parser()
args = parser.parse_args()
if args.doctor:
print_doctor()
return
if args.list_actors:
actors = list_actors()
if actors:
for name, path in actors.items():
print(f"{name:<24} {path}")
else:
print("No actors found. Add images or clips to assets/actors/.")
return
if not ffmpeg_available():
warn("ffmpeg or ffprobe was not found on PATH. Install it before rendering.", stage="darcads")
sys.exit(1)
# Route based on creation mode
if args.premise or args.mode in ("movie", "viral_scene"):
premise_text = args.premise or "A mysterious signal from deep space is decoded"
try:
result = run_movie_pipeline(
premise=premise_text,
output_path=args.output,
framework=args.framework if args.framework in HOOK_FRAMEWORKS else "viral_plot_twist",
style=args.style,
video_model=args.video_model,
platform=args.platform,
voice=args.voice,
tts_engine=args.tts,
target_seconds=args.seconds,
music_path=args.music,
music_volume=args.music_volume,
captions=args.captions,
allow_generation=not args.no_generation,
use_whisper=not args.no_whisper,
)
print(f"\n[Darc Studio] Render complete: {result.final_video_path} ({result.duration:.1f}s)")
return
except FFmpegError as exc:
print(f"\n[Darc Studio] Render failed:\n{exc}", file=sys.stderr)
sys.exit(1)
except KeyboardInterrupt:
print("\n[Darc Studio] Interrupted.", file=sys.stderr)
sys.exit(130)
except Exception as exc:
print(f"\n[Darc Studio] Pipeline failed: {exc}", file=sys.stderr)
sys.exit(1)
if not args.url:
parser.error("--url is required for ad mode (or use --premise for movie mode / --doctor)")
brand = BrandKit(
name=args.brand_name,
logo_path=args.logo,
primary_color=args.text_color,
accent_color=args.accent,
cta_text=args.cta,
cta_seconds=args.cta_seconds,
font_family=args.font,
)
try:
results = run_darcads_pipeline(
product_url=args.url,
output_path=args.output,
model=args.model,
provider=args.provider,
base_url=args.base_url,
video_model=args.video_model,
voice=args.voice,
tts_engine=args.tts,
platform=args.platform,
quality=args.quality,
framework=args.framework,
target_seconds=args.seconds,
variants=max(1, args.variants),
brand=brand,
music_path=args.music,
music_volume=args.music_volume,
duck_music=not args.no_duck,
captions=args.captions,
transition=args.transition,
transition_seconds=args.transition_seconds,
use_avatar=args.avatar,
actor=args.actor,
avatar_model=args.avatar_model,
allow_generation=not args.no_generation,
use_whisper=not args.no_whisper,
)
except FFmpegError as exc:
print(f"\n[DarcAds] Render failed:\n{exc}", file=sys.stderr)
sys.exit(1)
except KeyboardInterrupt:
print("\n[DarcAds] Interrupted.", file=sys.stderr)
sys.exit(130)
except Exception as exc: # noqa: BLE001 - top-level CLI guard
print(f"\n[DarcAds] Pipeline failed: {exc}", file=sys.stderr)
sys.exit(1)
# Non-zero exit is reserved for failures; craft warnings are informational.
for result in results:
if result.warnings:
print(f"\nScript notes for '{result.variant_name}':", file=sys.stderr)
for issue in result.warnings:
print(f" - {issue}", file=sys.stderr)
if __name__ == "__main__":
main()