from pathlib import Path # 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") hf_path = Path("app/deployment/hf_status.py") text = hf_path.read_text(encoding="utf-8-sig") text = text.replace("\ufeff", "") append_code = r''' # ===================================================== # Phase 33 override: clean retrieval query + stale cache tools # ===================================================== try: _phase33_previous_get_product_app_html = get_product_app_html except NameError: _phase33_previous_get_product_app_html = None def get_product_app_html() -> str: if _phase33_previous_get_product_app_html is None: return "

GraphResearcher App

App UI is unavailable.

" html = _phase33_previous_get_product_app_html() if "Clear Workspace Cache" not in html: buttons = """ """ html = html.replace("", buttons + "\n ", 1) js = r""" """ if "Phase 33 fix: clean retrieval query" not in html: html = html.replace("", js + "\n") html = html.replace( "Upload documents, select one, and chat. You can also compare two documents.", "Upload documents, select one, and chat. If answers say no sources found after rebuild, clear cache and re-upload." ) html = html.replace( "Upload a PDF/document and start chatting. No document ID needed.", "Upload a PDF/document and start chatting. If Hugging Face rebuilt, old cached documents may need re-upload." ) return html ''' if "Phase 33 override: clean retrieval query + stale cache tools" not in text: text += "\n\n" + append_code print("Phase 33 patch added.") else: print("Phase 33 patch already exists.") hf_path.write_text(text, encoding="utf-8") print("Fixed Phase 33 complete.")