Downloads · 30 days
0
riad777/kdp-pdf-generator
kdp-pdf-generator is a machine learning model from riad777. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Drop a cover image → the app uses AI to design a journal interior, stamps your cover on top, upscales to 300 DPI, and gives you a print-ready KDP PDF. One image-generation call per book.
Downloads · 30 days
0
Access
Public
Updated Jul 4, 2026
Repo size
193 KB
Likes
0
Public
Click a slice to open those files.
.pdf193 KB · 64%
From the Hugging Face model README
Drop a cover image → the app uses AI to design a journal interior, stamps your cover on top, upscales to 300 DPI, and gives you a print-ready KDP PDF. One image-generation call per book.
Cover + theme note
│
▼
OpenRouter /v1/images (google/gemini-3.1-flash-lite-image)
│
▼
Pillow — stamp cover on top 1.5 in
│
▼
Pillow — LANCZOS upscale to 300 DPI + sharpen
│
▼
ReportLab — embed as N pages of a 6×9 in PDF
│
▼
outputs/{filename}.pdf
Install dependencies
pip install -r requirements.txt
Add the API key
Create .streamlit/secrets.toml (gitignored):
OPENROUTER_API_KEY = "sk-or-v1-YOUR-FRESH-KEY"
Run
streamlit run app.py
Use
One image-generation call per book via OpenRouter. The user pays OpenRouter directly. The exact price depends on the model; see the OpenRouter models page.
If your API key was ever shared in chat, email, or a screenshot, rotate it in the OpenRouter dashboard before using.
| File | What it does |
|---|---|
app.py | Streamlit UI: upload, settings, generate, download |
engine.py | Pipeline: OpenRouter call, stamp, upscale, PDF |
OPENROUTER_PROMPT.txt | The one-shot prompt sent to the AI. Edit this to tune the design. |
requirements.txt | reportlab, streamlit, Pillow, svglib, requests |
assets/ | Sample cover images (reference only) |
outputs/ | Generated PDFs (gitignored) |
PROMPT.txt | V7 LLM-blueprint prompt (legacy, reference only) |
FLOW_PROMPT.txt | Google Flow visual-mockup prompt (reference only) |
python engine.py --cover assets/golden_retriever_pickleball.png \
--out my_book \
--theme "golden retriever playing pickleball" \
--pages 1
Outputs outputs/my_book.pdf.
OPENROUTER_API_KEY (Secret)Edit OPENROUTER_PROMPT.txt. The engine replaces {THEME_NOTE}
with whatever the user types in the UI. Common tweaks:
The AI image comes back at whatever resolution OpenRouter returns (typically ~1024 px wide). The cover is composited on the top 1.5 in of a 600 DPI (3600×5400 px) working canvas, then routed through a 4-pass sharpen chain:
LANCZOS resize to the target resolutionPIL.ImageFilter.UnsharpMask(radius=2, percent=150, threshold=3)PIL.ImageFilter.SHARPEN (kernel sharpen)PIL.ImageEnhance.Sharpness(img).enhance(2.0)The color palette is then quantized to 32 flat colors (posterize + quantize) for a true Adobe Illustrator look — no anti-aliased halos around flat-color regions. The result is embedded in the PDF as N full-bleed pages.
Setting VECTORIZE=1 in the Space's environment variables enables
a potrace-based vector path that traces the line work to SVG and
re-rasterizes at the target DPI for pixel-perfect lines. Requires
the potrace system binary. Falls back gracefully to the raster
path if potrace is missing.
_upscale_to_print in engine.py with a Real-ESRGAN call (will
require PyTorch — won't fit HF Spaces free tier).VECTORIZE=1 in the Space's environment
variables (requires potrace)..streamlit/secrets.toml or any file containing
an API key. The included .gitignore blocks this.