studio / utils /viral_scorer.py
Ava2lon's picture
Upload 170 files
345855e verified
Raw
History Blame Contribute Delete
1.12 kB
def score_clip(words):
"""
Returns virality score (0–100)
based on speech + structure signals
"""
if not words:
return 0
text = " ".join([w["text"] for w in words]).lower()
score = 0
# -----------------------------
# HOOK SIGNAL (first words)
# -----------------------------
hook_words = ["you", "imagine", "stop", "listen", "this", "never", "why"]
if any(h in text[:50] for h in hook_words):
score += 25
# -----------------------------
# EMOTION SIGNAL
# -----------------------------
exclamations = sum(1 for w in words if "!" in w["text"])
score += min(exclamations * 5, 20)
# -----------------------------
# LENGTH OPTIMIZATION
# -----------------------------
duration = words[-1]["end"] - words[0]["start"]
if 6 <= duration <= 25:
score += 25
elif duration < 6:
score -= 10
else:
score -= 5
# -----------------------------
# WORD DENSITY
# -----------------------------
score += min(len(words) / 2, 20)
# Clamp
return max(0, min(100, score))