- OpenAI Realtime session (server VAD, half-duplex audio via pacat/PipeWire) - Tools: wikipedia_sazetak (en.wikipedia -> Bosnian summary, max 2 A4 pages via WeasyPrint) and bojanka (image generation -> pure line art on A4) - CUPS printing, systemd user service, install script, offline test script Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LzKpYaEsuWDevuNnvSjcFW
31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
"""Ručni test: Wikipedia -> (opciono) sažetak -> PDF. Bez ključa radi samo sa sirovim tekstom članka."""
|
|
import asyncio
|
|
import html
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
from idriz import render, textgen, wiki # noqa: E402
|
|
from idriz.config import load # noqa: E402
|
|
|
|
|
|
async def main(topic: str, age: str) -> None:
|
|
cfg = load()
|
|
art = wiki.find_article(topic)
|
|
if not art:
|
|
print("nema članka"); return
|
|
print("članak:", art.title, art.url, len(art.text), "znakova")
|
|
out = Path("out"); out.mkdir(exist_ok=True)
|
|
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)
|
|
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)
|
|
print("PDF:", pdf)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main(sys.argv[1] if len(sys.argv) > 1 else "Volcano", sys.argv[2] if len(sys.argv) > 2 else "10"))
|