---
type: "Source File"
title: "\"\"\"Fix model detail pages: convert markdown to HTML, remove broken models.\"\"\""
description: "\"\"\"Fix model detail pages: convert markdown to HTML, remove broken models.\"\"\" import json # === Fix 1: Add markdown filter to app.py === app_path = \"/home/ben/infra/copecheck/app.py\" with open(app_path, \"r\") as f."
resource: "https://www.copecheck.com"
tags: ["copecheck", "main", "source-file", "py"]
timestamp: "2026-05-09T19:56:03Z"
site: "main"
source_path: "copecheck/fix_model_markdown.py"
---

# """Fix model detail pages: convert markdown to HTML, remove broken models."""

Source path: `copecheck/fix_model_markdown.py`  
Index snapshot generated: `2026-11-24T13:42:54Z`  
File modified: `2026-05-09T19:56:03Z`

```py
"""Fix model detail pages: convert markdown to HTML, remove broken models."""
import json

# === Fix 1: Add markdown filter to app.py ===
app_path = "/home/ben/infra/copecheck/app.py"
with open(app_path, "r") as f:
    content = f.read()

# Add markdown import and filter after existing imports
if "import markdown" not in content:
    # Find the right place - after the model_cope import
    marker = "import model_cope\nmodel_cope.init_model_cope()"
    if marker in content:
        md_code = '''import markdown as _md

@app.template_filter("md2html")
def md2html(text):
    """Convert markdown to HTML for transcript display."""
    if not text:
        return ""
    # Convert markdown to HTML
    html = _md.markdown(str(text), extensions=["nl2br", "fenced_code", "tables"])
    return html
'''
        content = content.replace(marker, marker + "\n\n" + md_code)
        print("Added markdown filter to app.py")
    else:
        print("ERROR: Could not find marker for markdown filter")
else:
    print("Markdown filter already exists")

with open(app_path, "w") as f:
    f.write(content)

# === Fix 2: Update model_detail.html template ===
tmpl_path = "/home/ben/infra/copecheck/templates/model_detail.html"
with open(tmpl_path, "r") as f:
    tmpl = f.read()

# Replace raw text output with markdown-rendered HTML
old_line = '<div style="color:#ccc;font-size:0.85rem;line-height:1.6;white-space:pre-wrap;word-break:break-word">{{ msg.content }}</div>'
new_line = '<div style="color:#ccc;font-size:0.85rem;line-height:1.6;word-break:break-word" class="transcript-md">{{ msg.content|md2html|safe }}</div>'

if old_line in tmpl:
    tmpl = tmpl.replace(old_line, new_line)
    print("Updated template to use md2html filter")
else:
    print("ERROR: Could not find template line to replace")

# Add minimal CSS for markdown content inside transcript
style_addition = """
<style>
.transcript-md p { margin: 0 0 0.6rem 0; }
.transcript-md ul, .transcript-md ol { margin: 0.3rem 0 0.6rem 1.5rem; padding: 0; }
.transcript-md li { margin-bottom: 0.2rem; }
.transcript-md strong { color: #eee; }
.transcript-md code { background: rgba(255,255,255,0.08); padding: 0.15rem 0.4rem; border-radius: 3px; font-size: 0.82rem; }
.transcript-md pre { background: rgba(255,255,255,0.05); padding: 0.8rem; border-radius: 6px; overflow-x: auto; margin: 0.5rem 0; }
.transcript-md pre code { background: none; padding: 0; }
.transcript-md h1, .transcript-md h2, .transcript-md h3 { color: #ddd; margin: 0.8rem 0 0.4rem; font-size: 0.95rem; }
</style>
"""

if ".transcript-md" not in tmpl:
    tmpl = tmpl.replace("{% endblock %}", style_addition + "{% endblock %}")
    print("Added transcript markdown styles")

with open(tmpl_path, "w") as f:
    f.write(tmpl)

# === Fix 3: Remove broken model ===
import sqlite3
db_path = "/home/ben/infra/copecheck/copecheck.db"
try:
    conn = sqlite3.connect(db_path)
    cur = conn.execute("DELETE FROM model_cope WHERE model_name = 'cognitivecomputations/dolphin-mixtral-8x7b'")
    conn.commit()
    print(f"Deleted {cur.rowcount} broken model(s)")
    conn.close()
except Exception as e:
    print(f"DB error: {e}")
    # Try cope.db
    try:
        conn = sqlite3.connect("/home/ben/infra/copecheck/cope.db")
        cur = conn.execute("DELETE FROM model_cope WHERE model_name = 'cognitivecomputations/dolphin-mixtral-8x7b'")
        conn.commit()
        print(f"Deleted {cur.rowcount} broken model(s) from cope.db")
        conn.close()
    except Exception as e2:
        print(f"cope.db error: {e2}")

print("\nDone!")
```
