from pathlib import Path # ===================================================== # 1. Remove hidden BOM characters from all Python files # ===================================================== for path in Path("app").rglob("*.py"): text = path.read_text(encoding="utf-8-sig") text = text.replace("\ufeff", "") path.write_text(text, encoding="utf-8") print("BOM cleanup completed for app/*.py files.") # ===================================================== # 2. Create graph visualization HTML service # ===================================================== Path("app/graph/graph_visualization.py").write_text(r''' from html import escape def get_graph_visualization_html(document_id: str) -> str: safe_document_id = escape(document_id) return f""" Graph View - {safe_document_id}

🕸️ Document Graph View

Document ID: {safe_document_id}

""" ''', encoding="utf-8") # ===================================================== # 3. Patch main.py route # ===================================================== main_path = Path("app/main.py") text = main_path.read_text(encoding="utf-8-sig") text = text.replace("\ufeff", "") if "from app.graph.graph_visualization import get_graph_visualization_html" not in text: text = "from app.graph.graph_visualization import get_graph_visualization_html\n" + text if "Phase 14.1 - Graph Visualization UI" not in text: old_phases = [ "Phase 14 - Graph Foundation Entity Relation Extraction", "Phase 13 - Deployment Demo Stabilization", "Phase 12 - Hugging Face Hosted LLM Provider Hardening", "Phase 11 - Hugging Face Deployment Readiness", ] for old in old_phases: text = text.replace(old, "Phase 14.1 - Graph Visualization UI") if "# Graph visualization endpoint" not in text: text += ''' # Graph visualization endpoint @app.get("/documents/{document_id}/graph/view", response_class=HTMLResponse) def view_document_graph(document_id: str): return get_graph_visualization_html(document_id) ''' main_path.write_text(text, encoding="utf-8") print("Phase 14.1 graph visualization UI added successfully.")