Summary layout for kids: Wikipedia lead image, airy text, facts box, generated illustration fallback
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LzKpYaEsuWDevuNnvSjcFW
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Ručni test: Wikipedia -> (opciono) sažetak -> PDF. Bez ključa radi samo sa sirovim tekstom članka."""
|
||||
"""Ručni test: Wikipedia -> (opciono) sažetak -> PDF. Bez ključa radi sa sirovim tekstom članka i slikom sa Wikipedije."""
|
||||
import asyncio
|
||||
import html
|
||||
import sys
|
||||
@@ -16,13 +16,23 @@ async def main(topic: str, age: str) -> None:
|
||||
print("nema članka"); return
|
||||
print("članak:", art.title, art.url, len(art.text), "znakova")
|
||||
out = Path("out"); out.mkdir(exist_ok=True)
|
||||
url = wiki.page_image_url(art.title)
|
||||
image = None
|
||||
if url:
|
||||
raw = out / ("test-wiki" + Path(url).suffix.lower())
|
||||
if wiki.download(url, raw):
|
||||
image = render.prepare_image(raw, out / "test-img.png")
|
||||
print("slika:", url, "->", image)
|
||||
if cfg.openai_api_key:
|
||||
from openai import AsyncOpenAI
|
||||
title, body = await textgen.summarize(AsyncOpenAI(api_key=cfg.openai_api_key), cfg.text_model, art, topic, age)
|
||||
s = await textgen.summarize(AsyncOpenAI(api_key=cfg.openai_api_key), cfg.text_model, art, topic, age)
|
||||
title, body, facts, caption = s.title, s.html, s.facts, s.caption
|
||||
else:
|
||||
title = art.title
|
||||
body = "".join(f"<p>{html.escape(p)}</p>" for p in art.text.split("\n\n")[:12])
|
||||
pdf = render.render_summary(title, body, art.title, out / "test-sazetak.pdf", cfg.max_pages)
|
||||
paras = [p for p in art.text.split("\n\n") if p and not p.startswith("==")][:5]
|
||||
title, body = art.title, "".join(f"<p>{html.escape(p[:600])}</p>" for p in paras)
|
||||
facts = ["Ovo je probna zanimljivost broj jedan.", "Druga zanimljivost, kratka.", "Treća, još kraća."]
|
||||
caption = "Probni potpis ispod slike."
|
||||
pdf = render.render_summary(title, body, facts, caption, image, art.title, out / "test-sazetak.pdf", cfg.max_pages)
|
||||
print("PDF:", pdf)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user