Update app.py
Browse files55 unmodified lines5657585960616263646555 unmodified lines# there's no position bias and it's faster than even a 2-token LLM call β# just one forward pass per script+candidate pair, batched.# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββdef _select_best_position(script: str, videos: list) -> int:if not videos:return Nonetag_strings = [v.get("tags", "") for v in videos]script_emb = embedder.encode(script, convert_to_tensor=True)tag_embs = embedder.encode(tag_strings, convert_to_tensor=True)55 unmodified lines56575859606162636465666768697071727374757677787980818255 unmodified lines# there's no position bias and it's faster than even a 2-token LLM call β# just one forward pass per script+candidate pair, batched.# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ# Pixabay boilerplate/metadata tags that describe the *asset* rather than# its visual content, and can falsely spike similarity (e.g. "ai generated"# just means the clip was made with generative AI tools β it says nothing# about the subject matter β but it collides hard with any script mentioning# "AI"). Stripped before embedding._NOISE_TAGS = {"ai generated", "live wallpaper", "background", "wallpaper","beautiful wallpaper", "backdrop",}def _clean_tags(tags: str) -> str:parts = [t.strip() for t in tags.split(",")]kept = [t for t in parts if t.lower() not in _NOISE_TAGS]return ", ".join(kept) if kept else tags # never return emptydef _select_best_position(script: str, videos: list) -> int:if not videos:return Nonetag_strings = [_clean_tags(v.get("tags", "")) for v in videos]script_emb = embedder.encode(script, convert_to_tensor=True)tag_embs = embedder.encode(tag_strings, convert_to_tensor=True)
app.py+18-1