import os from pathlib import Path def extract_html(): app_path = Path("app.py") content = app_path.read_text(encoding="utf-8") start_marker = ' template = """\n' end_marker = '\n\n"""' start_idx = content.find(start_marker) if start_idx == -1: print("Start marker not found.") return end_idx = content.find(end_marker, start_idx) if end_idx == -1: print("End marker not found.") return # Extract the HTML content html_content = content[start_idx + len(' template = """\n') : end_idx + len('\n\n')] # Write to ui/templates/index.html os.makedirs("ui/templates", exist_ok=True) Path("ui/templates/index.html").write_text(html_content, encoding="utf-8") # Replace in app.py replacement = ''' import os template_path = os.path.join(os.path.dirname(__file__), "ui", "templates", "index.html") with open(template_path, "r", encoding="utf-8") as f: template = f.read()''' new_content = content[:start_idx] + replacement + content[end_idx + len('\n"""'):] app_path.write_text(new_content, encoding="utf-8") print("Successfully extracted HTML to ui/templates/index.html and updated app.py!") if __name__ == "__main__": extract_html()