from pathlib import Path # Remove BOM from 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") hf_path = Path("app/deployment/hf_status.py") text = hf_path.read_text(encoding="utf-8-sig") text = text.replace("\ufeff", "") extra_function = r''' def get_graphrag_demo_html() -> str: return """ GraphRAG Demo - GraphRAG Research Scientist

GraphRAG Demo Console

Test graph build, graph visualization, graph context, graph retrieval fusion, and GraphRAG evaluation.

1. Document Setup

Paste a document_id from your uploaded/indexed document. If using Hugging Face, upload and index from /demo or /docs first.



Ready.

2. Graph Actions

Build graph first, then test context/retrieve/view.

3. Evaluation Actions

Evaluation compares normal retrieval vs graph-guided retrieval vs fused retrieval.

4. Ask with GraphRAG



GraphRAG answer summary will appear here.

5. Output Summary

No output yet

6. Raw JSON Output

{}
""" ''' if "def get_graphrag_demo_html" not in text: text += extra_function print("Added get_graphrag_demo_html to hf_status.py") else: print("get_graphrag_demo_html already exists") hf_path.write_text(text, encoding="utf-8") # Patch main.py main_path = Path("app/main.py") main_text = main_path.read_text(encoding="utf-8-sig") main_text = main_text.replace("\ufeff", "") if "get_graphrag_demo_html" not in main_text: if "from app.deployment.hf_status import" in main_text: main_text = main_text.replace( "from app.deployment.hf_status import", "from app.deployment.hf_status import" ) # Try to extend existing import block. if "get_demo_html" in main_text and "get_graphrag_demo_html" not in main_text: main_text = main_text.replace( "get_demo_html", "get_demo_html, get_graphrag_demo_html", 1 ) else: main_text = "from app.deployment.hf_status import get_graphrag_demo_html\n" + main_text if "# GraphRAG demo UI endpoint" not in main_text: main_text += ''' # GraphRAG demo UI endpoint @app.get("/graphrag-demo", response_class=HTMLResponse) def graphrag_demo_page(): return get_graphrag_demo_html() ''' print("Added /graphrag-demo route to main.py") else: print("/graphrag-demo route already exists") main_path.write_text(main_text, encoding="utf-8") print("Phase 22 GraphRAG demo UI patch complete.")