@danhachuel/thunderbolt 0.4.19 → 0.4.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app/main.py
CHANGED
|
@@ -45,6 +45,7 @@ from app.modules.niche_finder.data_loader import DatasetError, download_kaggle_d
|
|
|
45
45
|
from app.modules.niche_finder.summarizer import summarize_items
|
|
46
46
|
from app.influencers_ui import render_ai_influencer_characters, render_ai_influencer_content, render_ai_influencers_api_status, render_motion_control, render_ugc_products
|
|
47
47
|
from hermes_ui.blueprints import create_blueprint_from_link, list_branding_files, save_generated_blueprint
|
|
48
|
+
from hermes_ui.thumbnail_blueprints import generate_thumbnail_blueprint, list_thumbnail_blueprint_documents, resolve_thumbnail_blueprint, save_thumbnail_blueprint, save_thumbnail_blueprint_pair, thumbnail_blueprint_catalog, thumbnail_blueprint_for_channel
|
|
48
49
|
from hermes_ui.metadata_cleaner import build_description, clean_video_metadata, list_edit_records, metadata_manifest, normalize_tags, save_edit_record, store_external_video
|
|
49
50
|
from hermes_ui.python_editor import AUDIO_EXTENSIONS, VIDEO_EXTENSIONS, PythonEditorError, change_speed, editor_manifest, extract_audio, list_edit_records as list_python_editor_records, list_generated_videos, list_scripts, list_video_files, read_script, remove_audio, replace_audio, resize_video, save_edit_record as save_python_editor_record, save_script, store_uploaded_asset, trim_video
|
|
50
51
|
from hermes_ui.cuts import CutsError, download_direct_video_url, generate_clips, list_generated_videos as list_cut_generated_videos, list_runs as list_cut_runs, list_video_files as list_cut_video_files, manifest_bytes as cut_manifest_bytes, store_uploaded_video, zip_run as zip_cut_run
|
|
@@ -605,6 +606,17 @@ def render_channel_blueprint_panel(channel: dict, *, compact: bool = False) -> N
|
|
|
605
606
|
st.info(f"**Blueprint utilizado pelo canal:** {summary['name']} · `{summary['id']}` · **Voz:** {voice} · **Idioma:** {video_language}")
|
|
606
607
|
|
|
607
608
|
|
|
609
|
+
def render_channel_thumbnail_blueprint_panel(channel: dict, *, compact: bool = False) -> None:
|
|
610
|
+
document = thumbnail_blueprint_for_channel(channel)
|
|
611
|
+
name = str(document.get("name") or "SEM THUMBNAIL BLUEPRINT CONFIGURADO")
|
|
612
|
+
if name == "SEM THUMBNAIL BLUEPRINT CONFIGURADO":
|
|
613
|
+
st.warning("**SEM THUMBNAIL BLUEPRINT CONFIGURADO** · associe um Thumbnail Blueprint na aba Thumbnail Blueprints.")
|
|
614
|
+
elif compact:
|
|
615
|
+
st.caption(f"**Thumbnail Blueprint:** {name}")
|
|
616
|
+
else:
|
|
617
|
+
st.info(f"**Thumbnail Blueprint utilizado pelo canal:** {name} · apenas leitura")
|
|
618
|
+
|
|
619
|
+
|
|
608
620
|
def creative_payload_from_result(channel: dict, topic: str, creative: dict, topic_source: str = "manual") -> dict[str, Any]:
|
|
609
621
|
variant = creative.get("thumbnail_variant") or {}
|
|
610
622
|
return {
|
|
@@ -620,6 +632,7 @@ def creative_payload_from_result(channel: dict, topic: str, creative: dict, topi
|
|
|
620
632
|
"thumbnail_status": str(creative.get("thumbnail_status") or "prompt_ready"),
|
|
621
633
|
"blueprint_id": str(channel.get("default_blueprint_id") or channel.get("blueprint_id") or ""),
|
|
622
634
|
"blueprint_name": str(channel_blueprint_summary(channel).get("name") or "SEM BLUEPRINT CONFIGURADO"),
|
|
635
|
+
"thumbnail_blueprint_id": str(channel.get("default_thumbnail_blueprint_id") or channel.get("thumbnail_blueprint_id") or ""),
|
|
623
636
|
"voice": str(channel.get("default_voice") or channel.get("voice") or ""),
|
|
624
637
|
"ai_generation": {"creative": creative},
|
|
625
638
|
}
|
|
@@ -839,11 +852,15 @@ def generate_thumbnail_for_ui(
|
|
|
839
852
|
topic = str(topic or "").strip()
|
|
840
853
|
if not topic:
|
|
841
854
|
raise CreativeGenerationError("É necessário um tópico antes de gerar a thumbnail.")
|
|
855
|
+
script_blueprint = blueprint_for_channel(channel)
|
|
856
|
+
visual_blueprint = thumbnail_blueprint_for_channel(channel)
|
|
857
|
+
if visual_blueprint.get("content"):
|
|
858
|
+
script_blueprint = {**script_blueprint, "thumbnail_blueprint_rules": visual_blueprint.get("content", "")}
|
|
842
859
|
variant = generate_thumbnail_prompt(
|
|
843
860
|
settings,
|
|
844
861
|
channel,
|
|
845
862
|
topic,
|
|
846
|
-
blueprint=
|
|
863
|
+
blueprint=script_blueprint,
|
|
847
864
|
language=str(channel.get("language") or "Português"),
|
|
848
865
|
)
|
|
849
866
|
return {
|
|
@@ -1405,7 +1422,7 @@ def render_dashboard():
|
|
|
1405
1422
|
def render_blueprints():
|
|
1406
1423
|
st.title("Blueprints Youtube")
|
|
1407
1424
|
st.caption(f"Biblioteca local lida directamente de `{BLUEPRINTS}`")
|
|
1408
|
-
blueprint_tab
|
|
1425
|
+
blueprint_tab = st.container()
|
|
1409
1426
|
with blueprint_tab:
|
|
1410
1427
|
st.subheader("Criar blueprint a partir de link")
|
|
1411
1428
|
with st.form("create_blueprint_from_link"):
|
|
@@ -1474,42 +1491,115 @@ def render_blueprints():
|
|
|
1474
1491
|
except Exception as exc:
|
|
1475
1492
|
with st.expander(f"Inválido — {path.stem}"):
|
|
1476
1493
|
st.error(str(exc))
|
|
1477
|
-
with branding_tab:
|
|
1478
|
-
st.subheader("Brandings completos")
|
|
1479
|
-
st.caption(f"Brandings gerados ou importados da pasta `{BLUEPRINTS / 'brandings'}`")
|
|
1480
|
-
branding_upload = st.file_uploader("Subir Branding JSON", type=["json"], key="branding_upload")
|
|
1481
|
-
if branding_upload and st.button("Guardar Branding", type="secondary"):
|
|
1482
|
-
try:
|
|
1483
|
-
data = json.loads(branding_upload.getvalue().decode("utf-8"))
|
|
1484
|
-
if not isinstance(data, dict):
|
|
1485
|
-
raise ValueError("O JSON raiz deve ser um objecto.")
|
|
1486
|
-
target = BLUEPRINTS / "brandings" / (Path(branding_upload.name).stem.replace(" ", "-") + ".json")
|
|
1487
|
-
target.parent.mkdir(parents=True, exist_ok=True)
|
|
1488
|
-
atomic_write(target, data)
|
|
1489
|
-
record_notification("branding_completed", f"Branding guardado: {target.stem}", "O Branding importado foi guardado no storage local.", metadata={"name": target.stem}, dedupe_key=f"branding:{target}:{target.stat().st_mtime_ns}")
|
|
1490
|
-
st.success(f"Branding guardado em {target}")
|
|
1491
|
-
st.rerun()
|
|
1492
|
-
except (UnicodeDecodeError, json.JSONDecodeError, ValueError) as exc:
|
|
1493
|
-
st.error(f"Branding JSON inválido: {exc}")
|
|
1494
|
-
branding_files = list_branding_files()
|
|
1495
|
-
st.write(f"{len(branding_files)} branding(s) encontrado(s)")
|
|
1496
|
-
branding_search = st.text_input("Pesquisar brandings", key="branding_search")
|
|
1497
|
-
if not branding_files:
|
|
1498
|
-
st.info("Ainda não existem brandings na pasta local.")
|
|
1499
|
-
for path in branding_files:
|
|
1500
|
-
if branding_search and branding_search.lower() not in path.name.lower():
|
|
1501
|
-
continue
|
|
1502
|
-
try:
|
|
1503
|
-
data = load_blueprint_file(path)
|
|
1504
|
-
title = data.get("name") or data.get("identity", {}).get("channel_name") or path.stem
|
|
1505
|
-
with st.expander(f"{title} — {path.name}"):
|
|
1506
|
-
st.caption(f"Blueprint associado: {data.get('blueprint_id') or 'não associado'}")
|
|
1507
|
-
st.json(data)
|
|
1508
|
-
except Exception as exc:
|
|
1509
|
-
with st.expander(f"Inválido — {path.stem}"):
|
|
1510
|
-
st.error(str(exc))
|
|
1511
1494
|
|
|
1512
1495
|
|
|
1496
|
+
def render_youtube_brandings():
|
|
1497
|
+
st.title("Brandings Youtube")
|
|
1498
|
+
st.caption(f"Brandings gerados ou importados da pasta `{BLUEPRINTS / 'brandings'}`")
|
|
1499
|
+
branding_upload = st.file_uploader("Subir Branding JSON", type=["json"], key="branding_upload")
|
|
1500
|
+
if branding_upload and st.button("Guardar Branding", type="secondary"):
|
|
1501
|
+
try:
|
|
1502
|
+
data = json.loads(branding_upload.getvalue().decode("utf-8"))
|
|
1503
|
+
if not isinstance(data, dict):
|
|
1504
|
+
raise ValueError("O JSON raiz deve ser um objecto.")
|
|
1505
|
+
target = BLUEPRINTS / "brandings" / (Path(branding_upload.name).stem.replace(" ", "-") + ".json")
|
|
1506
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
1507
|
+
atomic_write(target, data)
|
|
1508
|
+
record_notification("branding_completed", f"Branding guardado: {target.stem}", "O Branding importado foi guardado no storage local.", metadata={"name": target.stem}, dedupe_key=f"branding:{target}:{target.stat().st_mtime_ns}")
|
|
1509
|
+
st.success(f"Branding guardado em {target}")
|
|
1510
|
+
st.rerun()
|
|
1511
|
+
except (UnicodeDecodeError, json.JSONDecodeError, ValueError) as exc:
|
|
1512
|
+
st.error(f"Branding JSON inválido: {exc}")
|
|
1513
|
+
branding_files = list_branding_files()
|
|
1514
|
+
st.write(f"{len(branding_files)} branding(s) encontrado(s)")
|
|
1515
|
+
branding_search = st.text_input("Pesquisar brandings", key="branding_search")
|
|
1516
|
+
if not branding_files:
|
|
1517
|
+
st.info("Ainda não existem brandings na pasta local.")
|
|
1518
|
+
for path in branding_files:
|
|
1519
|
+
if branding_search and branding_search.lower() not in path.name.lower():
|
|
1520
|
+
continue
|
|
1521
|
+
try:
|
|
1522
|
+
data = load_blueprint_file(path)
|
|
1523
|
+
title = data.get("name") or data.get("identity", {}).get("channel_name") or path.stem
|
|
1524
|
+
with st.expander(f"{title} — {path.name}"):
|
|
1525
|
+
st.caption(f"Blueprint associado: {data.get('blueprint_id') or 'não associado'}")
|
|
1526
|
+
st.json(data)
|
|
1527
|
+
except Exception as exc:
|
|
1528
|
+
with st.expander(f"Inválido — {path.stem}"):
|
|
1529
|
+
st.error(str(exc))
|
|
1530
|
+
|
|
1531
|
+
|
|
1532
|
+
def render_thumbnail_blueprints():
|
|
1533
|
+
st.title("Thumbnail Blueprints")
|
|
1534
|
+
st.caption(f"Documentos de estilo visual por nicho · armazenamento em `{BLUEPRINTS / 'thumbnails'}`")
|
|
1535
|
+
st.info("Crie uma regra visual reutilizável a partir das thumbnails públicas de um canal concorrente. O documento gerado é separado do Blueprint de roteiro e será aplicado automaticamente ao canal associado.")
|
|
1536
|
+
with st.form("create_thumbnail_blueprint_from_link"):
|
|
1537
|
+
source_url = st.text_input("Link do canal ou vídeo YouTube", placeholder="https://www.youtube.com/@canal ou https://youtu.be/video")
|
|
1538
|
+
niche = st.text_input("Nicho (usado no nome do ficheiro)", placeholder="Ex.: Militar")
|
|
1539
|
+
channel_name = st.text_input("Nome do canal concorrente (opcional)")
|
|
1540
|
+
sample_limit = st.slider("Vídeos públicos para analisar", 3, 10, 10)
|
|
1541
|
+
submitted = st.form_submit_button("Analisar e criar Thumbnail Blueprint", type="primary")
|
|
1542
|
+
if submitted:
|
|
1543
|
+
if not source_url.strip() or not niche.strip():
|
|
1544
|
+
st.error("Informe o link do YouTube e o nicho antes de criar.")
|
|
1545
|
+
else:
|
|
1546
|
+
try:
|
|
1547
|
+
public = fetch_channel_videos_public(source_url, limit=sample_limit)
|
|
1548
|
+
if not public.ok and not public.data.get("videos"):
|
|
1549
|
+
raise ValueError(public.message)
|
|
1550
|
+
document = generate_thumbnail_blueprint(read_json("settings.json", {}), source_url=source_url.strip(), niche=niche.strip(), channel_name=channel_name.strip(), videos=public.data.get("videos", []))
|
|
1551
|
+
path = save_thumbnail_blueprint(document)
|
|
1552
|
+
st.success(f"Thumbnail Blueprint criado: {path.name} · {len(document.get('sample_videos', []))} referência(s) analisada(s).")
|
|
1553
|
+
st.rerun()
|
|
1554
|
+
except (ValueError, OSError) as exc:
|
|
1555
|
+
st.error(str(exc))
|
|
1556
|
+
st.divider()
|
|
1557
|
+
st.subheader("Thumbnail Blueprints existentes")
|
|
1558
|
+
search = st.text_input("Pesquisar Thumbnail Blueprints", key="thumbnail_blueprint_search")
|
|
1559
|
+
documents = list_thumbnail_blueprint_documents()
|
|
1560
|
+
if not documents:
|
|
1561
|
+
st.info("Ainda não existem Thumbnail Blueprints. Use um link público do YouTube para criar o primeiro.")
|
|
1562
|
+
for path in documents:
|
|
1563
|
+
if search and search.casefold() not in path.name.casefold():
|
|
1564
|
+
continue
|
|
1565
|
+
with st.container(border=True):
|
|
1566
|
+
st.markdown(f"### {path.stem}")
|
|
1567
|
+
st.caption(f"Ficheiro: `{path.name}`")
|
|
1568
|
+
pair_options = blueprint_catalog()
|
|
1569
|
+
pair_ids = [item[0] for item in pair_options]
|
|
1570
|
+
pair_labels = {item[0]: item[1] for item in pair_options}
|
|
1571
|
+
pair = st.selectbox("Blueprint de roteiro associado", pair_ids, format_func=lambda item: pair_labels.get(item, item or "Sem Blueprint padrão"), key=f"thumbnail_card_pair_{path.stem}")
|
|
1572
|
+
if st.button("Guardar associação deste card", key=f"thumbnail_card_pair_save_{path.stem}"):
|
|
1573
|
+
save_thumbnail_blueprint_pair(path.stem, pair)
|
|
1574
|
+
st.success("Associação guardada; canais com esse Blueprint usarão esta thumbnail blueprint automaticamente.")
|
|
1575
|
+
st.code(path.read_text(encoding="utf-8"), language="markdown")
|
|
1576
|
+
st.divider()
|
|
1577
|
+
st.subheader("Associar ao canal e ao Blueprint de roteiro")
|
|
1578
|
+
channels = read_json("channels.json", [])
|
|
1579
|
+
thumbnail_options = thumbnail_blueprint_catalog()
|
|
1580
|
+
thumbnail_ids = [item[0] for item in thumbnail_options]
|
|
1581
|
+
thumbnail_labels = {item[0]: item[1] for item in thumbnail_options}
|
|
1582
|
+
blueprint_options = blueprint_catalog()
|
|
1583
|
+
blueprint_ids = [item[0] for item in blueprint_options]
|
|
1584
|
+
blueprint_labels = {item[0]: item[1] for item in blueprint_options}
|
|
1585
|
+
for channel in channels:
|
|
1586
|
+
channel_id = str(channel.get("id") or "")
|
|
1587
|
+
if not channel_id:
|
|
1588
|
+
continue
|
|
1589
|
+
with st.container(border=True):
|
|
1590
|
+
st.write(f"**{channel.get('name', 'Canal')}**")
|
|
1591
|
+
cols = st.columns(3)
|
|
1592
|
+
current_thumb = str(channel.get("default_thumbnail_blueprint_id") or channel.get("thumbnail_blueprint_id") or "")
|
|
1593
|
+
current_script = str(channel.get("default_blueprint_id") or channel.get("blueprint_id") or "")
|
|
1594
|
+
with cols[0]:
|
|
1595
|
+
thumb = st.selectbox("Thumbnail Blueprint", thumbnail_ids, index=thumbnail_ids.index(current_thumb) if current_thumb in thumbnail_ids else 0, format_func=lambda item: thumbnail_labels.get(item, item), key=f"thumbnail_blueprint_channel_{channel_id}")
|
|
1596
|
+
with cols[1]:
|
|
1597
|
+
script = st.selectbox("Blueprint de roteiro associado", blueprint_ids, index=blueprint_ids.index(current_script) if current_script in blueprint_ids else 0, format_func=lambda item: blueprint_labels.get(item, item or "Sem Blueprint padrão"), key=f"thumbnail_script_blueprint_channel_{channel_id}")
|
|
1598
|
+
with cols[2]:
|
|
1599
|
+
if st.button("Guardar par", key=f"thumbnail_blueprint_save_{channel_id}", use_container_width=True):
|
|
1600
|
+
update_channel(channel_id, {"thumbnail_blueprint_id": thumb, "default_thumbnail_blueprint_id": thumb, "blueprint_id": script, "default_blueprint_id": script})
|
|
1601
|
+
st.success("Par Blueprint de roteiro + Thumbnail Blueprint guardado.")
|
|
1602
|
+
st.rerun()
|
|
1513
1603
|
def _tiktok_accounts_from_settings(settings: dict[str, Any]) -> list[dict[str, Any]]:
|
|
1514
1604
|
raw_accounts = settings.get("tiktok_accounts")
|
|
1515
1605
|
if not isinstance(raw_accounts, list) or not raw_accounts:
|
|
@@ -2034,6 +2124,7 @@ def render_channels():
|
|
|
2034
2124
|
render_channel_edit_form(channel, youtube_account_ids, youtube_account_labels, youtube_accounts_by_id)
|
|
2035
2125
|
else:
|
|
2036
2126
|
summary = channel_blueprint_summary(channel)
|
|
2127
|
+
render_channel_thumbnail_blueprint_panel(channel, compact=True)
|
|
2037
2128
|
channel_language = language_label(channel.get("language") or "pt")
|
|
2038
2129
|
block_cols = st.columns(4, gap="small")
|
|
2039
2130
|
with block_cols[0]:
|
|
@@ -2370,6 +2461,7 @@ def render_new_video(page_title: str = "Criação de Vídeos", prefix: str = "ne
|
|
|
2370
2461
|
selected = [selected_one["id"]]
|
|
2371
2462
|
# Intentionally sits between Canal and the generation settings, as requested.
|
|
2372
2463
|
render_channel_blueprint_panel(selected_one)
|
|
2464
|
+
render_channel_thumbnail_blueprint_panel(selected_one)
|
|
2373
2465
|
generation_settings = render_video_generation_settings(
|
|
2374
2466
|
prefix,
|
|
2375
2467
|
current_language=str(st.session_state.get("video_language") or ""),
|
|
@@ -4179,7 +4271,11 @@ def render_automation():
|
|
|
4179
4271
|
with header_cols[3]:
|
|
4180
4272
|
schedule_time = st.text_input("Horário (HH:MM)", value=channel.get("automation_time", "00:00"), key=f"automation_time_{channel_id}")
|
|
4181
4273
|
blueprint_ids, blueprint_labels, current_blueprint, voice_options, current_voice = channel_default_options(channel)
|
|
4182
|
-
|
|
4274
|
+
thumbnail_items = thumbnail_blueprint_catalog()
|
|
4275
|
+
thumbnail_ids = [item[0] for item in thumbnail_items]
|
|
4276
|
+
thumbnail_labels = {item[0]: item[1] for item in thumbnail_items}
|
|
4277
|
+
current_thumbnail = str(channel.get("default_thumbnail_blueprint_id") or channel.get("thumbnail_blueprint_id") or "")
|
|
4278
|
+
default_cols = st.columns([1.0, 1.0, 1.35, 1.55, 1.55, 1.0], gap="small")
|
|
4183
4279
|
with default_cols[0]:
|
|
4184
4280
|
st.markdown("**Idioma Padrão**")
|
|
4185
4281
|
st.caption(language_label(channel.get("language") or "pt"))
|
|
@@ -4203,6 +4299,14 @@ def render_automation():
|
|
|
4203
4299
|
key=f"automation_voice_{channel_id}",
|
|
4204
4300
|
)
|
|
4205
4301
|
with default_cols[4]:
|
|
4302
|
+
automation_thumbnail = st.selectbox(
|
|
4303
|
+
"Thumbnail Blueprint",
|
|
4304
|
+
thumbnail_ids,
|
|
4305
|
+
index=thumbnail_ids.index(current_thumbnail) if current_thumbnail in thumbnail_ids else 0,
|
|
4306
|
+
format_func=lambda item: thumbnail_labels.get(item, item or "Sem Thumbnail Blueprint"),
|
|
4307
|
+
key=f"automation_thumbnail_blueprint_{channel_id}",
|
|
4308
|
+
)
|
|
4309
|
+
with default_cols[5]:
|
|
4206
4310
|
if st.button("Guardar", key=f"automation_save_{channel_id}", use_container_width=True):
|
|
4207
4311
|
if not valid_hhmm(schedule_time):
|
|
4208
4312
|
st.error("Use o formato HH:MM, por exemplo 08:30.")
|
|
@@ -4212,6 +4316,7 @@ def render_automation():
|
|
|
4212
4316
|
"automation_time": schedule_time.strip(),
|
|
4213
4317
|
})
|
|
4214
4318
|
set_channel_defaults(channel_id, automation_blueprint, automation_voice)
|
|
4319
|
+
update_channel(channel_id, {"thumbnail_blueprint_id": automation_thumbnail, "default_thumbnail_blueprint_id": automation_thumbnail})
|
|
4215
4320
|
st.success("Agendamento guardado.")
|
|
4216
4321
|
st.rerun()
|
|
4217
4322
|
|
|
@@ -7067,6 +7172,8 @@ def main():
|
|
|
7067
7172
|
channel_profile_items = [
|
|
7068
7173
|
("Canais YouTube", ":material/ondemand_video:", "Canais YouTube"),
|
|
7069
7174
|
("Blueprints Youtube", ":material/library_books:", "Blueprints Youtube"),
|
|
7175
|
+
("Thumbnail Blueprints", ":material/image:", "Thumbnail Blueprints"),
|
|
7176
|
+
("Brandings Youtube", ":material/brush:", "Brandings Youtube"),
|
|
7070
7177
|
("Contas TikTok", ":material/account_circle:", "Contas TikTok"),
|
|
7071
7178
|
("Prompt Masters", ":material/auto_awesome:", "Prompt Masters"),
|
|
7072
7179
|
("Facebook Pages", ":material/public:", "Facebook Pages"),
|
|
@@ -7148,7 +7255,7 @@ def main():
|
|
|
7148
7255
|
"Niche Finder": "/niche-finder", "Niche Finder Kaggle": "/niche-finder/kaggle", "Niche Finder Apify": "/niche-finder/apify",
|
|
7149
7256
|
"Pipeline Vídeos": "/pipeline-videos", "Criação de Vídeos": "/pipeline-videos/criacao", "Backlog Vídeos": "/pipeline-videos/backlog", "Roteiros": "/pipeline-videos/roteiros", "Thumbnails": "/pipeline-videos/thumbnails", "Upload": "/pipeline-videos/upload",
|
|
7150
7257
|
"Pipeline Música": "/pipeline-musica", "Criação de Músicas": "/pipeline-musica/criacao", "Music Backlog": "/pipeline-musica/backlog", "Vozes Personalizadas": "/pipeline-musica/vozes-personalizadas", "Upload Música": "/pipeline-musica/upload",
|
|
7151
|
-
"Canais/Perfis (Vídeos)": "/canais-perfis-videos", "Canais YouTube": "/canais-perfis-videos/canais-youtube", "Blueprints Youtube": "/canais-perfis-videos/blueprints-youtube", "Contas TikTok": "/canais-perfis-videos/contas-tiktok", "Prompt Masters": "/canais-perfis-videos/prompt-masters", "Facebook Pages": "/canais-perfis-videos/facebook-pages",
|
|
7258
|
+
"Canais/Perfis (Vídeos)": "/canais-perfis-videos", "Canais YouTube": "/canais-perfis-videos/canais-youtube", "Blueprints Youtube": "/canais-perfis-videos/blueprints-youtube", "Thumbnail Blueprints": "/canais-perfis-videos/thumbnail-blueprints", "Brandings Youtube": "/canais-perfis-videos/brandings-youtube", "Contas TikTok": "/canais-perfis-videos/contas-tiktok", "Prompt Masters": "/canais-perfis-videos/prompt-masters", "Facebook Pages": "/canais-perfis-videos/facebook-pages",
|
|
7152
7259
|
"AI Influencers": "/ai-influencers", "Personagens": "/ai-influencers/personagens", "Geração de Conteúdo IA": "/ai-influencers/geracao-conteudo", "Motion Control": "/ai-influencers/motion-control", "UGC Products": "/ai-influencers/ugc-products", "Redes Sociais": "/ai-influencers/redes-sociais",
|
|
7153
7260
|
"Edição": "/edicao", "Limpador de Metadados": "/edicao/limpador-metadados", "Cortes": "/edicao/cortes", "Editor Python": "/edicao/editor-python", "Download Mídia": "/edicao/download-midia",
|
|
7154
7261
|
"Growth": "/growth", "Analista Growth Youtube": "/growth/youtube", "Analista Growth Tiktok": "/growth/tiktok", "Analista Growth Instagram": "/growth/instagram", "Analista Facebook Pages": "/growth/facebook-pages", "Analista Bilibili": "/growth/bilibili",
|
|
@@ -7226,6 +7333,8 @@ def main():
|
|
|
7226
7333
|
"Thumbnails": render_thumbnails,
|
|
7227
7334
|
"Upload": render_upload,
|
|
7228
7335
|
"Blueprints Youtube": render_blueprints,
|
|
7336
|
+
"Thumbnail Blueprints": render_thumbnail_blueprints,
|
|
7337
|
+
"Brandings Youtube": render_youtube_brandings,
|
|
7229
7338
|
"Prompt Masters": render_tiktok_prompt_masters,
|
|
7230
7339
|
"Canais YouTube": render_channels,
|
|
7231
7340
|
"Contas TikTok": render_tiktok_accounts,
|
|
@@ -182,6 +182,7 @@ def _creative_payload(channel: dict[str, Any]) -> tuple[str, dict[str, Any]]:
|
|
|
182
182
|
"thumbnail_status": "pending_prompt",
|
|
183
183
|
"blueprint_id": str(channel.get("default_blueprint_id") or channel.get("blueprint_id") or ""),
|
|
184
184
|
"blueprint_name": str(blueprint.get("name") or "SEM BLUEPRINT CONFIGURADO"),
|
|
185
|
+
"thumbnail_blueprint_id": str(channel.get("default_thumbnail_blueprint_id") or channel.get("thumbnail_blueprint_id") or ""),
|
|
185
186
|
"voice": str(channel.get("default_voice") or channel.get("voice") or ""),
|
|
186
187
|
"material_source": material_source,
|
|
187
188
|
"generation_settings": {"video_keywords": editorial.get("keywords", []), "material_source": material_source},
|
|
@@ -228,6 +229,7 @@ def _pending_payload(channel: dict[str, Any]) -> tuple[str, dict[str, Any]]:
|
|
|
228
229
|
"language": language,
|
|
229
230
|
"blueprint_id": str(channel.get("default_blueprint_id") or channel.get("blueprint_id") or ""),
|
|
230
231
|
"blueprint_name": str(blueprint.get("name") or "SEM BLUEPRINT CONFIGURADO"),
|
|
232
|
+
"thumbnail_blueprint_id": str(channel.get("default_thumbnail_blueprint_id") or channel.get("thumbnail_blueprint_id") or ""),
|
|
231
233
|
"voice": str(channel.get("default_voice") or channel.get("voice") or ""),
|
|
232
234
|
"material_source": material_source,
|
|
233
235
|
"generation_settings": {"material_source": material_source},
|
|
@@ -136,6 +136,7 @@ def channel_context(channel: dict[str, Any], blueprint: dict[str, Any] | None =
|
|
|
136
136
|
"blueprint_id": str(blueprint.get("id") or channel.get("default_blueprint_id") or channel.get("blueprint_id") or ""),
|
|
137
137
|
"blueprint_name": str(blueprint.get("name") or "SEM BLUEPRINT CONFIGURADO"),
|
|
138
138
|
"blueprint_niche": str(blueprint.get("target_niche") or blueprint.get("niche") or metadata.get("target_niche") or metadata.get("niche") or ""),
|
|
139
|
+
"thumbnail_blueprint_rules": str(blueprint.get("thumbnail_blueprint_rules") or "").strip(),
|
|
139
140
|
"default_voice": str(channel.get("default_voice") or channel.get("voice") or ""),
|
|
140
141
|
}
|
|
141
142
|
|
package/hermes_ui/domain.py
CHANGED
|
@@ -45,6 +45,8 @@ def create_channel(name: str, url: str = "", metadata: dict[str, Any] | None = N
|
|
|
45
45
|
"language": "Português",
|
|
46
46
|
"blueprint_id": "",
|
|
47
47
|
"default_blueprint_id": "",
|
|
48
|
+
"thumbnail_blueprint_id": "",
|
|
49
|
+
"default_thumbnail_blueprint_id": "",
|
|
48
50
|
"style_wide": "pexels",
|
|
49
51
|
"voice": "",
|
|
50
52
|
"default_voice": "",
|
|
@@ -178,6 +180,7 @@ def create_tasks_for_batch(batch: dict[str, Any]) -> list[dict[str, Any]]:
|
|
|
178
180
|
"generation_settings": payload.get("generation_settings", options.get("generation_settings", {})),
|
|
179
181
|
"blueprint_id": payload.get("blueprint_id") or channel.get("default_blueprint_id") or channel.get("blueprint_id", ""),
|
|
180
182
|
"blueprint_name": payload.get("blueprint_name", ""),
|
|
183
|
+
"thumbnail_blueprint_id": payload.get("thumbnail_blueprint_id") or channel.get("default_thumbnail_blueprint_id") or channel.get("thumbnail_blueprint_id", ""),
|
|
181
184
|
"voice": payload.get("voice") or channel.get("default_voice") or channel.get("voice", ""),
|
|
182
185
|
"automation_on": bool(channel.get("automation_on", False)),
|
|
183
186
|
"automation_time": channel.get("automation_time", "00:00"),
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
import uuid
|
|
5
|
+
from datetime import datetime, timezone
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any, Mapping
|
|
8
|
+
|
|
9
|
+
from .provider_routing import route_llm_json
|
|
10
|
+
from .storage import BLUEPRINTS, atomic_write, list_blueprint_files, load_blueprint_file
|
|
11
|
+
|
|
12
|
+
PROMPT_MASTER = '''You are a forensic YouTube thumbnail analyst. Build a reusable Thumbnail Blueprint from the reference channel videos below.
|
|
13
|
+
The output must be a practical, locked visual system, not a script blueprint. Infer recurring composition, framing, lighting, color, typography, overlay text, symbols, emotional triggers, mobile readability, aspect ratio, quality and negative constraints. Use the exact Markdown structure of the requested reference: STYLE LOCK, FRAMING & POSE, BACKGROUND & LIGHTING, GEOPOLITICAL SYMBOLS when relevant, VISUAL ATTENTION ELEMENT, TEXT STYLE, TEXT PSYCHOLOGY, COMPOSITION RULES, FORMAT & QUALITY, FINAL OBJECTIVE, FINAL INPUT FORMAT and FINAL SYSTEM INSTRUCTION. Write the document in English. Do not invent channel analytics. The document must instruct future thumbnail generation and include a concise, ready-to-use image prompt template.'''
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _slug(value: Any) -> str:
|
|
17
|
+
text = re.sub(r"[^A-Za-z0-9]+", "_", str(value or "").strip()).strip("_")
|
|
18
|
+
return text or "General"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _record_name(niche: str) -> str:
|
|
22
|
+
return f"{_slug(niche)}_Thumbnail_Blueprint"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def thumbnail_blueprint_catalog() -> list[tuple[str, str]]:
|
|
26
|
+
folder = BLUEPRINTS / "thumbnails"
|
|
27
|
+
folder.mkdir(parents=True, exist_ok=True)
|
|
28
|
+
result: list[tuple[str, str]] = [("", "Sem Thumbnail Blueprint padrão")]
|
|
29
|
+
for path in sorted(folder.glob("*.md"), key=lambda p: p.stat().st_mtime, reverse=True):
|
|
30
|
+
result.append((path.stem, path.stem))
|
|
31
|
+
return result
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def resolve_thumbnail_blueprint(identifier: Any) -> dict[str, Any]:
|
|
35
|
+
wanted = str(identifier or "").strip()
|
|
36
|
+
if not wanted:
|
|
37
|
+
return {}
|
|
38
|
+
folder = BLUEPRINTS / "thumbnails"
|
|
39
|
+
for path in folder.glob("*.md"):
|
|
40
|
+
if path.stem == wanted or path.name == wanted:
|
|
41
|
+
return {"id": path.stem, "name": path.stem, "path": str(path), "content": path.read_text(encoding="utf-8")}
|
|
42
|
+
return {"id": wanted, "name": wanted}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def thumbnail_blueprint_for_channel(channel: Mapping[str, Any]) -> dict[str, Any]:
|
|
46
|
+
direct = channel.get("default_thumbnail_blueprint_id") or channel.get("thumbnail_blueprint_id")
|
|
47
|
+
if direct:
|
|
48
|
+
return resolve_thumbnail_blueprint(direct)
|
|
49
|
+
script_id = str(channel.get("default_blueprint_id") or channel.get("blueprint_id") or "").strip()
|
|
50
|
+
pairs = _pair_state()
|
|
51
|
+
return resolve_thumbnail_blueprint(pairs.get(script_id, ""))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _pair_state() -> dict[str, str]:
|
|
55
|
+
path = BLUEPRINTS / "thumbnail_blueprint_pairs.json"
|
|
56
|
+
try:
|
|
57
|
+
value = __import__("json").loads(path.read_text(encoding="utf-8"))
|
|
58
|
+
return {str(k): str(v) for k, v in value.items()} if isinstance(value, dict) else {}
|
|
59
|
+
except (OSError, ValueError, TypeError):
|
|
60
|
+
return {}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def save_thumbnail_blueprint_pair(thumbnail_id: str, blueprint_id: str) -> None:
|
|
64
|
+
pairs = _pair_state()
|
|
65
|
+
if blueprint_id:
|
|
66
|
+
pairs[str(blueprint_id)] = str(thumbnail_id)
|
|
67
|
+
else:
|
|
68
|
+
for key, value in list(pairs.items()):
|
|
69
|
+
if value == thumbnail_id:
|
|
70
|
+
pairs.pop(key, None)
|
|
71
|
+
atomic_write(BLUEPRINTS / "thumbnail_blueprint_pairs.json", pairs)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def generate_thumbnail_blueprint(
|
|
75
|
+
settings: Mapping[str, Any],
|
|
76
|
+
*,
|
|
77
|
+
source_url: str,
|
|
78
|
+
niche: str,
|
|
79
|
+
channel_name: str = "",
|
|
80
|
+
videos: list[Mapping[str, Any]] | None = None,
|
|
81
|
+
) -> dict[str, Any]:
|
|
82
|
+
clean_niche = str(niche or "General").strip() or "General"
|
|
83
|
+
samples = list(videos or [])[:10]
|
|
84
|
+
sample_text = "\n".join(
|
|
85
|
+
f"- Title: {item.get('title', '')}\n URL: {item.get('url', '')}\n Thumbnail URL: {item.get('thumbnail_url', '')}"
|
|
86
|
+
for item in samples
|
|
87
|
+
) or "- No public sample videos were available; produce a clearly marked baseline system from the niche."
|
|
88
|
+
user_prompt = f"Niche: {clean_niche}\nChannel: {channel_name}\nSource: {source_url}\nReference videos:\n{sample_text}\nReturn JSON with one key content containing only the complete Markdown document."
|
|
89
|
+
try:
|
|
90
|
+
routed = route_llm_json(settings, PROMPT_MASTER, user_prompt)
|
|
91
|
+
content = str(routed.payload.get("content") or "").strip()
|
|
92
|
+
except Exception as exc:
|
|
93
|
+
raise ValueError(f"Não foi possível gerar o Thumbnail Blueprint no provider configurado: {exc}") from exc
|
|
94
|
+
if not content:
|
|
95
|
+
raise ValueError("O provider não devolveu um documento Thumbnail Blueprint válido.")
|
|
96
|
+
if not content.startswith("#"):
|
|
97
|
+
content = f"# {_record_name(clean_niche)}\n\n" + content
|
|
98
|
+
return {
|
|
99
|
+
"id": _record_name(clean_niche),
|
|
100
|
+
"name": _record_name(clean_niche),
|
|
101
|
+
"niche": clean_niche,
|
|
102
|
+
"channel_name": channel_name,
|
|
103
|
+
"source_url": source_url,
|
|
104
|
+
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
105
|
+
"version": 1,
|
|
106
|
+
"sample_videos": samples,
|
|
107
|
+
"content": content.rstrip() + "\n",
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def save_thumbnail_blueprint(document: Mapping[str, Any]) -> Path:
|
|
112
|
+
name = _record_name(str(document.get("niche") or document.get("name") or "General").replace("_Thumbnail_Blueprint", ""))
|
|
113
|
+
folder = BLUEPRINTS / "thumbnails"
|
|
114
|
+
folder.mkdir(parents=True, exist_ok=True)
|
|
115
|
+
target = folder / f"{name}.md"
|
|
116
|
+
content = str(document.get("content") or "").strip()
|
|
117
|
+
if not content:
|
|
118
|
+
raise ValueError("O documento Thumbnail Blueprint não pode ficar vazio.")
|
|
119
|
+
front = ["---", f"type: thumbnail_blueprint", f"id: {name}", f"name: {name}", f"niche: {document.get('niche', '')}", f"source_url: {document.get('source_url', '')}", f"created_at: {document.get('created_at', '')}", "---", ""]
|
|
120
|
+
target.write_text("\n".join(front) + content + "\n", encoding="utf-8")
|
|
121
|
+
return target
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def list_thumbnail_blueprint_documents() -> list[Path]:
|
|
125
|
+
folder = BLUEPRINTS / "thumbnails"
|
|
126
|
+
folder.mkdir(parents=True, exist_ok=True)
|
|
127
|
+
return sorted(folder.glob("*.md"), key=lambda p: p.stat().st_mtime, reverse=True)
|
package/package.json
CHANGED