import html, sqlite3 from db import get_conn def render_rows(rows): """ Render rows as HTML. Example: render_rows(rows_by_tag("diffusion models")) """ blocks = [] for t, a, txt, pub in rows: #Handle None values by converting to empty strings title = html.escape(t) if t is not None else "" authors = html.escape(a) if a is not None else "" summary = html.escape(txt) if txt is not None else "" published = pub[:10] if pub is not None else "" blocks += [ f"

{title}

", f"

Authors: {authors}
{published}

", f"
{summary}
", "
" ] return "\n".join(blocks) or "

No matching papers found.

" def rows_by_tag(keyword: str, limit: int = 25): """ Get rows in databaseby tag. Example: rows_by_tag("diffusion models") """ conn = get_conn() q = f"%{keyword.lower()}%" return conn.execute( "SELECT title, authors, summary, published FROM papers " "WHERE LOWER(tags) LIKE ? ORDER BY published DESC LIMIT ?", (q, limit) ).fetchall()