from pathlib import Path import re # Clean BOM 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.") hf_path = Path("app/deployment/hf_status.py") text = hf_path.read_text(encoding="utf-8-sig") text = text.replace("\ufeff", "") new_ui = r''' def get_home_html() -> str: return """ GraphResearcher
GraphRAG Research Assistant

Chat with your documents using graph-powered RAG.

Upload a research paper, report, PDF, or notes and ask questions naturally. GraphResearcher retrieves evidence, builds an entity-relation graph, generates grounded answers, and shows citations without forcing users to handle technical document IDs.

1. Upload
User uploads a document. The app stores the document ID internally.
2. Build Graph
Entities and relations are extracted for graph-guided retrieval.
3. Chat
User asks follow-up questions like ChatGPT or Gemini.
4. Verify
Answers include citations, source chunks, and fusion metrics.

Document Workspace

Upload, select, chat with, and delete documents from a normal user interface.

GraphRAG Retrieval

Combines hybrid retrieval with graph context, graph-guided chunks, and fusion evaluation.

Professional Demo

Includes app UI, GraphRAG console, API docs, health checks, and deployment status.

""" def get_product_app_html() -> str: return """ GraphResearcher App
No document selected Upload or select a document from the left sidebar.
Ready
Ask naturally. Example: “Summarize this”, “What is the main idea?”, “Explain this simply”.
""" ''' text += new_ui hf_path.write_text(text, encoding="utf-8") print("Updated hf_status.py with home UI and improved product app UI.") # 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", "") # Ensure HTMLResponse import if "HTMLResponse" not in main_text: lines = main_text.splitlines() inserted = False for i, line in enumerate(lines): if line.startswith("from fastapi.responses import"): lines[i] = line + ", HTMLResponse" inserted = True break if not inserted: lines.insert(0, "from fastapi.responses import HTMLResponse") main_text = "\n".join(lines) + "\n" # Ensure get_home_html and get_product_app_html import if "get_home_html" not in main_text: main_text = "from app.deployment.hf_status import get_home_html, get_product_app_html\n" + main_text elif "get_product_app_html" not in main_text: main_text = "from app.deployment.hf_status import get_product_app_html\n" + main_text # Replace existing root route if present root_replacement = '''@app.get("/", response_class=HTMLResponse) def home_page(): return get_home_html() ''' pattern = re.compile( r'@app\.get\(\s*["\\\']/["\\\'][^\n]*\)\s*\n(?:async\s+)?def\s+\w+\([^)]*\):\s*\n(?: .*(?:\n|$))+', re.MULTILINE ) if '@app.get("/")' in main_text or '@app.get("/",' in main_text or "@app.get('/')" in main_text: main_text = pattern.sub(root_replacement + "\n", main_text, count=1) print("Replaced existing / route with home UI.") else: main_text += "\n\n" + root_replacement print("Added / route with home UI.") # Add /app route if missing if '# Improved product workspace app endpoint' not in main_text: main_text += ''' # Improved product workspace app endpoint @app.get("/app", response_class=HTMLResponse) def product_workspace_app_page(): return get_product_app_html() ''' print("Added /app product workspace route.") else: print("/app route already exists.") main_path.write_text(main_text, encoding="utf-8") print("Phase 26 patch complete.")