palec87 commited on
Commit ·
15b4be8
1
Parent(s): dd65780
options reorg
Browse files- app.py +1 -13
- comic_gen/backends.py +26 -28
- comic_gen/comics.py +4 -10
- comic_gen/image_backend.py +3 -2
- comic_gen/text_backend.py +0 -1
- test/test_image_backend.py +3 -3
app.py
CHANGED
|
@@ -135,7 +135,6 @@ def _overlay_bubbles_html(
|
|
| 135 |
bbox = bubble.get("bbox_px", [0, 0, 120, 60])
|
| 136 |
x, y, box_w, box_h = bbox
|
| 137 |
line = dialogue[index] if index < len(dialogue) else {}
|
| 138 |
-
# char_id = html.escape(line.get("character_id", "narrator"))
|
| 139 |
text = html.escape(line.get("text", ""))
|
| 140 |
left = max(0.0, min(100.0, (x / width) * 100))
|
| 141 |
top = max(0.0, min(100.0, (y / height) * 100))
|
|
@@ -145,7 +144,6 @@ def _overlay_bubbles_html(
|
|
| 145 |
"<div class='overlay-bubble' "
|
| 146 |
f"style='left:{left:.2f}%;top:{top:.2f}%;"
|
| 147 |
f"width:{bubble_w:.2f}%;height:{bubble_h:.2f}%;'>"
|
| 148 |
-
# f"<div class='overlay-speaker'>{char_id}</div>"
|
| 149 |
f"<div class='overlay-line'>{text}</div>"
|
| 150 |
"</div>"
|
| 151 |
)
|
|
@@ -243,7 +241,6 @@ def generate_strip(
|
|
| 243 |
style_id: str,
|
| 244 |
use_live_feed: bool,
|
| 245 |
panel_count: int,
|
| 246 |
-
enable_model_generation: bool,
|
| 247 |
use_serverless_api: bool,
|
| 248 |
negative_prompt: str,
|
| 249 |
seed: int,
|
|
@@ -258,7 +255,6 @@ def generate_strip(
|
|
| 258 |
payload = backends.fetch_article(
|
| 259 |
language,
|
| 260 |
use_live_feed=use_live_feed,
|
| 261 |
-
model_generation=enable_model_generation,
|
| 262 |
)
|
| 263 |
document = session.build_base_session(language, style_id, payload)
|
| 264 |
document.setdefault("ui", {})["debug_mode"] = debug_mode
|
|
@@ -272,7 +268,6 @@ def generate_strip(
|
|
| 272 |
comics.generate_story_pipeline(
|
| 273 |
document,
|
| 274 |
panel_count=panel_count,
|
| 275 |
-
enable_model_generation=enable_model_generation,
|
| 276 |
text_model_repo_id=DEFAULT_TEXT_MODEL_ID,
|
| 277 |
image_options={
|
| 278 |
"model_repo_id": image_model_id,
|
|
@@ -317,7 +312,6 @@ def generate_strip_ui(
|
|
| 317 |
style_id: str,
|
| 318 |
use_live_feed: bool,
|
| 319 |
panel_count: int,
|
| 320 |
-
enable_model_generation: bool,
|
| 321 |
use_serverless_api: bool,
|
| 322 |
negative_prompt: str,
|
| 323 |
seed: int,
|
|
@@ -344,7 +338,6 @@ def generate_strip_ui(
|
|
| 344 |
style_id,
|
| 345 |
use_live_feed,
|
| 346 |
panel_count,
|
| 347 |
-
enable_model_generation,
|
| 348 |
use_serverless_api,
|
| 349 |
negative_prompt,
|
| 350 |
seed,
|
|
@@ -446,11 +439,7 @@ with gr.Blocks() as demo:
|
|
| 446 |
value=False,
|
| 447 |
)
|
| 448 |
|
| 449 |
-
with gr.Accordion("
|
| 450 |
-
enable_model_generation_input = gr.Checkbox(
|
| 451 |
-
label="Enable model generation (text + images)",
|
| 452 |
-
value=False,
|
| 453 |
-
)
|
| 454 |
use_serverless_api_input = gr.Checkbox(
|
| 455 |
label="Use HF serverless API for text + image generation",
|
| 456 |
value=False,
|
|
@@ -538,7 +527,6 @@ with gr.Blocks() as demo:
|
|
| 538 |
style_input,
|
| 539 |
live_feed_input,
|
| 540 |
panel_count,
|
| 541 |
-
enable_model_generation_input,
|
| 542 |
use_serverless_api_input,
|
| 543 |
negative_prompt_input,
|
| 544 |
seed_input,
|
|
|
|
| 135 |
bbox = bubble.get("bbox_px", [0, 0, 120, 60])
|
| 136 |
x, y, box_w, box_h = bbox
|
| 137 |
line = dialogue[index] if index < len(dialogue) else {}
|
|
|
|
| 138 |
text = html.escape(line.get("text", ""))
|
| 139 |
left = max(0.0, min(100.0, (x / width) * 100))
|
| 140 |
top = max(0.0, min(100.0, (y / height) * 100))
|
|
|
|
| 144 |
"<div class='overlay-bubble' "
|
| 145 |
f"style='left:{left:.2f}%;top:{top:.2f}%;"
|
| 146 |
f"width:{bubble_w:.2f}%;height:{bubble_h:.2f}%;'>"
|
|
|
|
| 147 |
f"<div class='overlay-line'>{text}</div>"
|
| 148 |
"</div>"
|
| 149 |
)
|
|
|
|
| 241 |
style_id: str,
|
| 242 |
use_live_feed: bool,
|
| 243 |
panel_count: int,
|
|
|
|
| 244 |
use_serverless_api: bool,
|
| 245 |
negative_prompt: str,
|
| 246 |
seed: int,
|
|
|
|
| 255 |
payload = backends.fetch_article(
|
| 256 |
language,
|
| 257 |
use_live_feed=use_live_feed,
|
|
|
|
| 258 |
)
|
| 259 |
document = session.build_base_session(language, style_id, payload)
|
| 260 |
document.setdefault("ui", {})["debug_mode"] = debug_mode
|
|
|
|
| 268 |
comics.generate_story_pipeline(
|
| 269 |
document,
|
| 270 |
panel_count=panel_count,
|
|
|
|
| 271 |
text_model_repo_id=DEFAULT_TEXT_MODEL_ID,
|
| 272 |
image_options={
|
| 273 |
"model_repo_id": image_model_id,
|
|
|
|
| 312 |
style_id: str,
|
| 313 |
use_live_feed: bool,
|
| 314 |
panel_count: int,
|
|
|
|
| 315 |
use_serverless_api: bool,
|
| 316 |
negative_prompt: str,
|
| 317 |
seed: int,
|
|
|
|
| 338 |
style_id,
|
| 339 |
use_live_feed,
|
| 340 |
panel_count,
|
|
|
|
| 341 |
use_serverless_api,
|
| 342 |
negative_prompt,
|
| 343 |
seed,
|
|
|
|
| 439 |
value=False,
|
| 440 |
)
|
| 441 |
|
| 442 |
+
with gr.Accordion("Advanced Options", open=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 443 |
use_serverless_api_input = gr.Checkbox(
|
| 444 |
label="Use HF serverless API for text + image generation",
|
| 445 |
value=False,
|
|
|
|
| 527 |
style_input,
|
| 528 |
live_feed_input,
|
| 529 |
panel_count,
|
|
|
|
| 530 |
use_serverless_api_input,
|
| 531 |
negative_prompt_input,
|
| 532 |
seed_input,
|
comic_gen/backends.py
CHANGED
|
@@ -99,7 +99,6 @@ def fallback_image_src(panel: dict[str, Any]) -> str:
|
|
| 99 |
def fetch_article(
|
| 100 |
language: str,
|
| 101 |
use_live_feed: bool = False,
|
| 102 |
-
model_generation: bool = False,
|
| 103 |
) -> dict[str, str]:
|
| 104 |
normalized = language.lower()
|
| 105 |
if use_live_feed:
|
|
@@ -121,33 +120,32 @@ def fetch_article(
|
|
| 121 |
else:
|
| 122 |
payload = load_json_article(language)
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
"publisher"
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
"published_at"
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
)
|
| 151 |
return payload
|
| 152 |
|
| 153 |
return load_json_article(language)
|
|
|
|
| 99 |
def fetch_article(
|
| 100 |
language: str,
|
| 101 |
use_live_feed: bool = False,
|
|
|
|
| 102 |
) -> dict[str, str]:
|
| 103 |
normalized = language.lower()
|
| 104 |
if use_live_feed:
|
|
|
|
| 120 |
else:
|
| 121 |
payload = load_json_article(language)
|
| 122 |
|
| 123 |
+
try:
|
| 124 |
+
parsed = {
|
| 125 |
+
"publisher": payload.get("source").get(
|
| 126 |
+
"publisher"
|
| 127 |
+
),
|
| 128 |
+
"source_link": payload.get("source").get("link"),
|
| 129 |
+
"published_at": payload.get("source").get(
|
| 130 |
+
"published_at"
|
| 131 |
+
),
|
| 132 |
+
"title": payload.get("article").get("title"),
|
| 133 |
+
"fulltext": payload.get("article").get("fulltext"),
|
| 134 |
+
}
|
| 135 |
+
if parsed and parsed.get("source_link") and parsed.get(
|
| 136 |
+
"fulltext"
|
| 137 |
+
):
|
| 138 |
+
return parsed
|
| 139 |
+
except (OSError, json.JSONDecodeError):
|
| 140 |
+
logger.warning(
|
| 141 |
+
f"Error reading example file for '{language}',"
|
| 142 |
+
f" falling back to deterministic article."
|
| 143 |
+
)
|
| 144 |
+
except Exception as e:
|
| 145 |
+
logger.warning(
|
| 146 |
+
f"Unexpected error loading example file for '{language}':"
|
| 147 |
+
f" {e}. Falling back to deterministic article."
|
| 148 |
+
)
|
|
|
|
| 149 |
return payload
|
| 150 |
|
| 151 |
return load_json_article(language)
|
comic_gen/comics.py
CHANGED
|
@@ -25,7 +25,7 @@ def _default_image_options() -> dict[str, Any]:
|
|
| 25 |
return {
|
| 26 |
"enable_live_images": False,
|
| 27 |
"use_serverless_image_api": False,
|
| 28 |
-
"model_repo_id": "
|
| 29 |
"negative_prompt": "",
|
| 30 |
"seed": 0,
|
| 31 |
"randomize_seed": True,
|
|
@@ -52,8 +52,8 @@ def _normalize_model_repo_id(value: Any) -> str:
|
|
| 52 |
value = value[0]
|
| 53 |
else:
|
| 54 |
value = value[0] if value else ""
|
| 55 |
-
model_repo_id = str(value or "
|
| 56 |
-
return model_repo_id or "
|
| 57 |
|
| 58 |
|
| 59 |
def _normalized_image_options(
|
|
@@ -79,7 +79,7 @@ def _normalized_image_options(
|
|
| 79 |
)
|
| 80 |
options["randomize_seed"] = bool(options.get("randomize_seed", True))
|
| 81 |
options["model_repo_id"] = _normalize_model_repo_id(
|
| 82 |
-
options.get("model_repo_id", "
|
| 83 |
)
|
| 84 |
options["negative_prompt"] = str(options.get("negative_prompt", ""))
|
| 85 |
return options
|
|
@@ -88,15 +88,9 @@ def _normalized_image_options(
|
|
| 88 |
def generate_story_pipeline(
|
| 89 |
document: dict[str, Any],
|
| 90 |
panel_count: int,
|
| 91 |
-
enable_model_generation: bool,
|
| 92 |
text_model_repo_id: str,
|
| 93 |
image_options: dict[str, Any] | None = None,
|
| 94 |
) -> None:
|
| 95 |
-
if not enable_model_generation:
|
| 96 |
-
logger.info("Running deterministic pipeline")
|
| 97 |
-
deterministic_pipeline(document)
|
| 98 |
-
return
|
| 99 |
-
|
| 100 |
options = _normalized_image_options(image_options)
|
| 101 |
options["enable_live_images"] = True
|
| 102 |
logger.info("Running unified model pipeline (text + image)")
|
|
|
|
| 25 |
return {
|
| 26 |
"enable_live_images": False,
|
| 27 |
"use_serverless_image_api": False,
|
| 28 |
+
"model_repo_id": "black-forest-labs/FLUX.1-schnell",
|
| 29 |
"negative_prompt": "",
|
| 30 |
"seed": 0,
|
| 31 |
"randomize_seed": True,
|
|
|
|
| 52 |
value = value[0]
|
| 53 |
else:
|
| 54 |
value = value[0] if value else ""
|
| 55 |
+
model_repo_id = str(value or "black-forest-labs/FLUX.1-schnell").strip()
|
| 56 |
+
return model_repo_id or "black-forest-labs/FLUX.1-schnell"
|
| 57 |
|
| 58 |
|
| 59 |
def _normalized_image_options(
|
|
|
|
| 79 |
)
|
| 80 |
options["randomize_seed"] = bool(options.get("randomize_seed", True))
|
| 81 |
options["model_repo_id"] = _normalize_model_repo_id(
|
| 82 |
+
options.get("model_repo_id", "black-forest-labs/FLUX.1-schnell")
|
| 83 |
)
|
| 84 |
options["negative_prompt"] = str(options.get("negative_prompt", ""))
|
| 85 |
return options
|
|
|
|
| 88 |
def generate_story_pipeline(
|
| 89 |
document: dict[str, Any],
|
| 90 |
panel_count: int,
|
|
|
|
| 91 |
text_model_repo_id: str,
|
| 92 |
image_options: dict[str, Any] | None = None,
|
| 93 |
) -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
options = _normalized_image_options(image_options)
|
| 95 |
options["enable_live_images"] = True
|
| 96 |
logger.info("Running unified model pipeline (text + image)")
|
comic_gen/image_backend.py
CHANGED
|
@@ -101,8 +101,8 @@ def _normalize_model_repo_id(value: Any) -> str:
|
|
| 101 |
"""Return a model repo id string that Diffusers can validate."""
|
| 102 |
if isinstance(value, (list, tuple)):
|
| 103 |
value = value[0] if value else ""
|
| 104 |
-
model_repo_id = str(value or "
|
| 105 |
-
return model_repo_id or "
|
| 106 |
|
| 107 |
|
| 108 |
def _is_serverless_image_enabled(options: dict[str, Any]) -> bool:
|
|
@@ -265,6 +265,7 @@ def _generate_panel_image(
|
|
| 265 |
height=height,
|
| 266 |
guidance_scale=guidance_scale,
|
| 267 |
num_inference_steps=num_inference_steps,
|
|
|
|
| 268 |
).images[0]
|
| 269 |
|
| 270 |
out_path = _build_output_path(session_id, panel_id)
|
|
|
|
| 101 |
"""Return a model repo id string that Diffusers can validate."""
|
| 102 |
if isinstance(value, (list, tuple)):
|
| 103 |
value = value[0] if value else ""
|
| 104 |
+
model_repo_id = str(value or "black-forest-labs/FLUX.1-schnell").strip()
|
| 105 |
+
return model_repo_id or "black-forest-labs/FLUX.1-schnell"
|
| 106 |
|
| 107 |
|
| 108 |
def _is_serverless_image_enabled(options: dict[str, Any]) -> bool:
|
|
|
|
| 265 |
height=height,
|
| 266 |
guidance_scale=guidance_scale,
|
| 267 |
num_inference_steps=num_inference_steps,
|
| 268 |
+
max_sequence_length=256,
|
| 269 |
).images[0]
|
| 270 |
|
| 271 |
out_path = _build_output_path(session_id, panel_id)
|
comic_gen/text_backend.py
CHANGED
|
@@ -14,7 +14,6 @@ from .text_utils import (
|
|
| 14 |
ComicResponse,
|
| 15 |
)
|
| 16 |
from .errors import (
|
| 17 |
-
ModelPipelineError,
|
| 18 |
TextGenerationError,
|
| 19 |
UnifiedGenerationError,
|
| 20 |
)
|
|
|
|
| 14 |
ComicResponse,
|
| 15 |
)
|
| 16 |
from .errors import (
|
|
|
|
| 17 |
TextGenerationError,
|
| 18 |
UnifiedGenerationError,
|
| 19 |
)
|
test/test_image_backend.py
CHANGED
|
@@ -62,7 +62,7 @@ def _options(enable_live_images: bool = True) -> dict:
|
|
| 62 |
return {
|
| 63 |
"enable_live_images": enable_live_images,
|
| 64 |
"use_serverless_image_api": True,
|
| 65 |
-
"model_repo_id": "
|
| 66 |
"negative_prompt": "",
|
| 67 |
"seed": 11,
|
| 68 |
"randomize_seed": False,
|
|
@@ -117,7 +117,7 @@ def test_generate_panel_image_uses_serverless_without_local_fallback(
|
|
| 117 |
negative_prompt="",
|
| 118 |
session_id="session-1",
|
| 119 |
panel_id="panel_1",
|
| 120 |
-
model_repo_id=("
|
| 121 |
seed=5,
|
| 122 |
randomize_seed=False,
|
| 123 |
width=256,
|
|
@@ -130,7 +130,7 @@ def test_generate_panel_image_uses_serverless_without_local_fallback(
|
|
| 130 |
assert out_path.endswith("panel_1.png")
|
| 131 |
assert used_seed == 5
|
| 132 |
assert image_source == "serverless"
|
| 133 |
-
assert captured["model_repo_id"] == "
|
| 134 |
|
| 135 |
|
| 136 |
def test_generate_image_panels_passes_stored_image_prompt(monkeypatch):
|
|
|
|
| 62 |
return {
|
| 63 |
"enable_live_images": enable_live_images,
|
| 64 |
"use_serverless_image_api": True,
|
| 65 |
+
"model_repo_id": "black-forest-labs/FLUX.1-schnell",
|
| 66 |
"negative_prompt": "",
|
| 67 |
"seed": 11,
|
| 68 |
"randomize_seed": False,
|
|
|
|
| 117 |
negative_prompt="",
|
| 118 |
session_id="session-1",
|
| 119 |
panel_id="panel_1",
|
| 120 |
+
model_repo_id=("black-forest-labs/FLUX.1-schnell",),
|
| 121 |
seed=5,
|
| 122 |
randomize_seed=False,
|
| 123 |
width=256,
|
|
|
|
| 130 |
assert out_path.endswith("panel_1.png")
|
| 131 |
assert used_seed == 5
|
| 132 |
assert image_source == "serverless"
|
| 133 |
+
assert captured["model_repo_id"] == "black-forest-labs/FLUX.1-schnell"
|
| 134 |
|
| 135 |
|
| 136 |
def test_generate_image_panels_passes_stored_image_prompt(monkeypatch):
|