Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
54 lines
2.1 KiB
Python
54 lines
2.1 KiB
Python
"""Title metadata suggestions (MV16): a title, a synopsis and tags from the transcript, through Relay.
|
|
|
|
Suggestions only: the creator applies them in the studio (the normal title
|
|
edit). Lengths match the catalog limits and nothing names a tool or model.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import re
|
|
from collections.abc import Sequence
|
|
from typing import Any
|
|
|
|
from .subtitles import LLM, Cue, _default_llm
|
|
|
|
MAX_TRANSCRIPT_CHARS = 6000
|
|
|
|
|
|
def _json_object(raw: str) -> dict:
|
|
text = raw.strip()
|
|
fence = re.search(r"```(?:json)?\s*(.*?)```", text, re.DOTALL)
|
|
if fence:
|
|
text = fence.group(1).strip()
|
|
start, end = text.find("{"), text.rfind("}")
|
|
if start < 0 or end <= start:
|
|
raise ValueError("no JSON object in the answer")
|
|
value = json.loads(text[start:end + 1])
|
|
if not isinstance(value, dict):
|
|
raise ValueError("not a JSON object")
|
|
return value
|
|
|
|
|
|
def suggest(cues: Sequence[Cue], *, current_title: str = "", llm: LLM | None = None) -> dict[str, Any]:
|
|
from app.domains.presets_hub.catalog import vendor_hits
|
|
|
|
transcript = " ".join(c.text for c in cues)[:MAX_TRANSCRIPT_CHARS]
|
|
if not transcript:
|
|
raise ValueError("there is no speech to describe")
|
|
prompt = ("Write catalog details for this video from its transcript. Answer with only JSON: "
|
|
'{"title": "<at most 80 characters>", "synopsis": "<2-3 plain sentences>", '
|
|
'"tags": ["<up to 8 short topic tags>"]}. Do not invent facts that are not in the transcript. '
|
|
f"Current title: {current_title!r}.\nTranscript: {transcript}")
|
|
data = _json_object((llm or _default_llm)(prompt))
|
|
title = " ".join(str(data.get("title") or "").split())[:80]
|
|
synopsis = " ".join(str(data.get("synopsis") or "").split())[:600]
|
|
tags = [" ".join(str(t).split())[:30].lower() for t in (data.get("tags") or []) if str(t).strip()][:8]
|
|
clean_tags = [t for t in dict.fromkeys(tags) if not vendor_hits(t)]
|
|
if not title or vendor_hits(f"{title} {synopsis}"):
|
|
raise ValueError("the suggestion was not usable")
|
|
return {"title": title, "synopsis": synopsis, "tags": clean_tags}
|
|
|
|
|
|
__all__ = ["suggest"]
|