@danhachuel/thunderbolt 0.4.31 → 0.4.33
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 +3 -0
- package/hermes_ui/thumbnails.py +34 -2
- package/package.json +1 -1
package/app/main.py
CHANGED
|
@@ -4199,10 +4199,13 @@ def render_thumbnails():
|
|
|
4199
4199
|
):
|
|
4200
4200
|
try:
|
|
4201
4201
|
with st.spinner("A refazer apenas o lettering…"):
|
|
4202
|
+
channel, _blueprint = _thumbnail_editor_context(record)
|
|
4202
4203
|
_task, generated_path = regenerate_thumbnail_lettering(
|
|
4203
4204
|
task_id,
|
|
4204
4205
|
settings,
|
|
4205
4206
|
lettering_prompt=record.get("lettering_prompt") or "",
|
|
4207
|
+
language=str(record.get("language") or channel.get("language") or current_ui_language()),
|
|
4208
|
+
channel=channel,
|
|
4206
4209
|
)
|
|
4207
4210
|
record_notification(
|
|
4208
4211
|
"thumbnail_generation_completed",
|
package/hermes_ui/thumbnails.py
CHANGED
|
@@ -7,7 +7,7 @@ import uuid
|
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
from typing import Any
|
|
9
9
|
|
|
10
|
-
from .creative_generation import generate_thumbnail_prompt
|
|
10
|
+
from .creative_generation import _language_instruction, generate_thumbnail_prompt
|
|
11
11
|
from .media_generation import generate_image_from_pool
|
|
12
12
|
from .media_providers import media_cards_for_pool
|
|
13
13
|
from .storage import STORAGE, ensure_storage, now, read_json, update_json
|
|
@@ -96,6 +96,7 @@ def normalize_thumbnail_task(task: dict[str, Any]) -> dict[str, Any]:
|
|
|
96
96
|
"topic": str(task.get("topic") or "").strip(),
|
|
97
97
|
"channel_id": str(task.get("channel_id") or "").strip(),
|
|
98
98
|
"channel_name": str(task.get("channel_name") or "Canal sem nome").strip(),
|
|
99
|
+
"language": str(task.get("language") or "").strip(),
|
|
99
100
|
"blueprint_id": str(task.get("blueprint_id") or "").strip(),
|
|
100
101
|
"blueprint_name": str(task.get("blueprint_name") or "").strip(),
|
|
101
102
|
"thumbnail_blueprint_id": str(task.get("thumbnail_blueprint_id") or "").strip(),
|
|
@@ -348,6 +349,8 @@ def regenerate_thumbnail_lettering(
|
|
|
348
349
|
task_id: str,
|
|
349
350
|
settings: dict[str, Any],
|
|
350
351
|
lettering_prompt: str = "",
|
|
352
|
+
language: str = "",
|
|
353
|
+
channel: dict[str, Any] | None = None,
|
|
351
354
|
) -> tuple[dict[str, Any], Path]:
|
|
352
355
|
"""Edit only the lettering while sending the existing image as a Nano Banana reference."""
|
|
353
356
|
tasks = read_json("tasks.json", [])
|
|
@@ -357,10 +360,34 @@ def regenerate_thumbnail_lettering(
|
|
|
357
360
|
previous_image = record.get("image_path")
|
|
358
361
|
if not previous_image or not previous_image.is_file():
|
|
359
362
|
raise ThumbnailGenerationError("A thumbnail precisa de uma imagem existente para refazer o lettering.")
|
|
363
|
+
requested_language = str(language or record.get("language") or "Português").strip()
|
|
364
|
+
language_instruction = _language_instruction(requested_language)
|
|
360
365
|
base_prompt = record["prompt"] or "Cria uma thumbnail de YouTube cinematográfica e de alto contraste."
|
|
366
|
+
resolved_channel = dict(channel or {})
|
|
367
|
+
if not resolved_channel:
|
|
368
|
+
channels = read_json("channels.json", [])
|
|
369
|
+
channel_id = str(task.get("channel_id") or "").strip()
|
|
370
|
+
resolved_channel = next(
|
|
371
|
+
(item for item in channels if isinstance(item, dict) and str(item.get("id") or "") == channel_id),
|
|
372
|
+
{},
|
|
373
|
+
) if isinstance(channels, list) else {}
|
|
374
|
+
try:
|
|
375
|
+
localized_variant = generate_thumbnail_prompt(
|
|
376
|
+
settings,
|
|
377
|
+
resolved_channel,
|
|
378
|
+
record["title"] or record["topic"],
|
|
379
|
+
current_prompt=base_prompt,
|
|
380
|
+
language=requested_language,
|
|
381
|
+
)
|
|
382
|
+
exact_headline = str(localized_variant.get("overlay_text") or "").strip()
|
|
383
|
+
except Exception:
|
|
384
|
+
exact_headline = str(record.get("thumbnail_text") or (record.get("variant") or {}).get("overlay_text") or "").strip()
|
|
385
|
+
if not exact_headline:
|
|
386
|
+
raise ThumbnailGenerationError("Não foi possível gerar o texto do lettering no idioma do canal.")
|
|
361
387
|
edit_prompt = str(lettering_prompt or "").strip() or (
|
|
362
388
|
f"Refaz apenas o lettering da thumbnail para o vídeo {record['title']!r}. "
|
|
363
|
-
"
|
|
389
|
+
f"Escreve obrigatoriamente em {language_instruction}. "
|
|
390
|
+
f"Usa exactamente este texto, sem alterar palavras, idioma ou acentuação: {exact_headline!r}."
|
|
364
391
|
)
|
|
365
392
|
combined_prompt = (
|
|
366
393
|
"BASE IMAGE LAYER — preserva exactamente a composição, enquadramento, sujeitos, fundo, iluminação, "
|
|
@@ -368,6 +395,9 @@ def regenerate_thumbnail_lettering(
|
|
|
368
395
|
f"{base_prompt}\n\n"
|
|
369
396
|
"LETTERING EDIT LAYER — altera exclusivamente o texto/lettering visível da thumbnail. "
|
|
370
397
|
"Mantém tudo o que pertence à BASE IMAGE LAYER pixelmente tão próximo quanto possível, sem mudar a imagem.\n"
|
|
398
|
+
f"LANGUAGE LOCK — todo o texto visível novo deve estar obrigatoriamente em {language_instruction}. "
|
|
399
|
+
"Não uses inglês nem traduzas para outro idioma.\n"
|
|
400
|
+
f"EXACT HEADLINE — renderiza somente este texto: <<<{exact_headline}>>>\n"
|
|
371
401
|
f"{edit_prompt}\n"
|
|
372
402
|
"Não adicionar logótipos, marcas de água ou outros elementos."
|
|
373
403
|
)
|
|
@@ -378,10 +408,12 @@ def regenerate_thumbnail_lettering(
|
|
|
378
408
|
topic=record["title"] or record["topic"],
|
|
379
409
|
variant_index=record["variant_index"],
|
|
380
410
|
reference_image=previous_image,
|
|
411
|
+
lettering_text=exact_headline,
|
|
381
412
|
lettering_prompt=edit_prompt,
|
|
382
413
|
)
|
|
383
414
|
variant = _variant_for_record(record)
|
|
384
415
|
variant["image_prompt"] = base_prompt
|
|
416
|
+
variant["overlay_text"] = exact_headline
|
|
385
417
|
variant["lettering_prompt"] = edit_prompt
|
|
386
418
|
updated = _update_thumbnail_task(
|
|
387
419
|
task_id,
|
package/package.json
CHANGED