Spaces:
Running
Running
Create autonomous_engine.py
Browse files- utils/autonomous_engine.py +97 -0
utils/autonomous_engine.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
V8 Autonomous Viral Engine
|
| 3 |
+
--------------------------
|
| 4 |
+
Fully automated pipeline for viral video generation.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
from utils.transcription import transcribe_video
|
| 9 |
+
from utils.highlights import detect_highlights
|
| 10 |
+
from utils.clipper import create_clips
|
| 11 |
+
from utils.srt import generate_srt
|
| 12 |
+
from utils.render import render_subtitles
|
| 13 |
+
from utils.variations import generate_hooks
|
| 14 |
+
from utils.pacing import pacing_engine
|
| 15 |
+
from utils.viral_scorer import score_clip
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# =====================================================
|
| 19 |
+
# CORE AUTONOMOUS PIPELINE
|
| 20 |
+
# =====================================================
|
| 21 |
+
|
| 22 |
+
def run_autonomous_engine(video_path):
|
| 23 |
+
"""
|
| 24 |
+
One-call system → full viral pipeline
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
print("[V8 ENGINE] Starting autonomous pipeline...")
|
| 28 |
+
|
| 29 |
+
# 1. TRANSCRIBE
|
| 30 |
+
words = transcribe_video(video_path)
|
| 31 |
+
|
| 32 |
+
# 2. DETECT HIGHLIGHTS
|
| 33 |
+
highlights = detect_highlights(words)
|
| 34 |
+
|
| 35 |
+
if not highlights:
|
| 36 |
+
return {
|
| 37 |
+
"status": "failed",
|
| 38 |
+
"reason": "No highlights detected"
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
# 3. AUTO CLIP GENERATION
|
| 42 |
+
clips = create_clips(video_path, highlights)
|
| 43 |
+
|
| 44 |
+
if not clips:
|
| 45 |
+
return {
|
| 46 |
+
"status": "failed",
|
| 47 |
+
"reason": "Clip generation failed"
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
outputs = []
|
| 51 |
+
|
| 52 |
+
# 4. PROCESS EACH CLIP AUTONOMOUSLY
|
| 53 |
+
for i, clip in enumerate(clips):
|
| 54 |
+
|
| 55 |
+
try:
|
| 56 |
+
clip_words = transcribe_video(clip)
|
| 57 |
+
|
| 58 |
+
# 5. CAPTIONS
|
| 59 |
+
srt = generate_srt(clip_words)
|
| 60 |
+
|
| 61 |
+
# 6. PACING OPTIMIZATION (NEW V8)
|
| 62 |
+
paced_clip = pacing_engine(clip, clip_words)
|
| 63 |
+
|
| 64 |
+
# 7. HOOK VARIATIONS
|
| 65 |
+
hooks = generate_hooks(clip_words)
|
| 66 |
+
|
| 67 |
+
# 8. RENDER OUTPUT
|
| 68 |
+
output_path = clip.replace(".mp4", f"_v8_{i}.mp4")
|
| 69 |
+
|
| 70 |
+
final_video = render_subtitles(
|
| 71 |
+
paced_clip,
|
| 72 |
+
srt,
|
| 73 |
+
output_path
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
# 9. VIRAL SCORING
|
| 77 |
+
score = score_clip(clip_words)
|
| 78 |
+
|
| 79 |
+
outputs.append({
|
| 80 |
+
"clip": final_video,
|
| 81 |
+
"score": score,
|
| 82 |
+
"hooks": hooks[:3],
|
| 83 |
+
"index": i
|
| 84 |
+
})
|
| 85 |
+
|
| 86 |
+
except Exception as e:
|
| 87 |
+
print(f"[V8 ENGINE] Clip {i} failed:", str(e))
|
| 88 |
+
continue
|
| 89 |
+
|
| 90 |
+
# 10. SORT BY VIRAL SCORE
|
| 91 |
+
outputs = sorted(outputs, key=lambda x: x["score"], reverse=True)
|
| 92 |
+
|
| 93 |
+
return {
|
| 94 |
+
"status": "completed",
|
| 95 |
+
"best_clip": outputs[0] if outputs else None,
|
| 96 |
+
"all_variants": outputs
|
| 97 |
+
}
|