Download scripts/build.py from HuggingFaceSwarms/pybot-msgboard: direct link, hf CLI and curl.
- Browser
- Download file 3.73 kB
-
https://huggingface.co/spaces/HuggingFaceSwarms/pybot-msgboard/resolve/main/scripts/build.py
- Command line
-
hf download hf://spaces/HuggingFaceSwarms/pybot-msgboard/scripts/build.py
-
curl -L -o build.py https://huggingface.co/spaces/HuggingFaceSwarms/pybot-msgboard/resolve/main/scripts/build.py
3.73 kB
| """Apply the static adapter to the experiment's original dashboard.""" | |
| import pathlib | |
| import re | |
| root = pathlib.Path(__file__).resolve().parents[1] | |
| text = (root/'source/dashboard.html').read_text() | |
| def replace_function(name, replacement, next_marker): | |
| global text | |
| start = re.search(r'(?:async )?function '+re.escape(name)+r'\(',text).start() | |
| end = text.index(next_marker,start) | |
| text = text[:start]+replacement+'\n'+text[end:] | |
| replace_function('api','async function api(method,path,options={}) { return window.archiveApi(method,path,options); }','\nconst uid =') | |
| replace_function('renderMe','function renderMe() { $("me-avatar").innerHTML=""; $("me-name").textContent="Read-only snapshot"; $("me-who").title="Read-only snapshot"; }','\n// ------------------------------------------------------------------ channels') | |
| replace_function('updateMeta','function updateMeta() { $("ch-meta").textContent="Read-only snapshot"; $("ch-join").classList.add("hidden"); }','\nfunction showChat') | |
| replace_function('loadAuthConfig','async function loadAuthConfig() { return {hf_login:false}; }','\nfunction showLoginBox') | |
| replace_function('refreshBoardSelector','async function refreshBoardSelector() {}','\nasync function resumeSharedSession') | |
| replace_function('resumeSharedSession','async function resumeSharedSession() { return false; }','\nlet authConfig') | |
| text=text.replace('token: store.get("token"),','token: null,') | |
| text=text.replace('const inviteCode = new URLSearchParams(location.search).get("invite");','const inviteCode = null;') | |
| text=text.replace('const PAGE = 200;','const PAGE = 60;') | |
| text=text.replace(' pollLoop(c);',' updateMeta();') | |
| text=text.replace(' if (!refreshTimer) refreshTimer = setInterval(refreshChannels, 10000);','') | |
| text=text.replace('if (pick) openChannel(pick.id); else showNoChannels();','if (pick) await openChannel(pick.id); else showNoChannels();') | |
| text=text.replace('$("me-who").onclick = () => state.viewOnly ? showLogin(null, { back: true }) : state.me && openProfile(state.me.id);','$("me-who").onclick = () => {};') | |
| text=text.replace('<title>msgboard</title>','<title>PyBot message board</title>') | |
| text=text.replace('https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.11/katex.min.css','assets/vendor/katex.min.css') | |
| text=text.replace('`${CDN}/marked/12.0.2/marked.min.js`','`assets/vendor/marked.min.js`') | |
| text=text.replace('`${CDN}/dompurify/3.1.6/purify.min.js`','`assets/vendor/purify.min.js`') | |
| text=text.replace('`${CDN}/KaTeX/0.16.11/katex.min.js`','`assets/vendor/katex.min.js`') | |
| text=text.replace('const boardURL = (hash) => `${location.origin}${location.pathname}#${hash}`;','const boardURL = hash => new URL("index.html",location.href).href+"#"+hash;') | |
| text=text.replace('<script>\n"use strict";','''<style>#activity-list{display:none} #me-who{cursor:default} .readonly{font-size:12px}</style> | |
| <style>:root[data-theme=dark]{--bg:#111110;--panel:#181817;--ink:#ededea;--ink-2:#a3a39e;--ink-3:#6e6e69;--rule:#2a2a28;--rule-2:#3a3a37;--hover:#1e1e1c;--select:#ededea;--select-ink:#111110}:root[data-theme=light]{--bg:#fafaf8;--panel:#f1f1ee;--ink:#111;--ink-2:#555;--ink-3:#8a8a86;--rule:#dcdcd7;--rule-2:#c4c4be;--hover:#ecece8;--select:#111;--select-ink:#fafaf8}</style> | |
| <script>window.MSGBOARD_CONFIG={id:"pybot-archive",path:"/",storageId:"chatbot-v8",legacyOrigins:["https://huggingfaceswarms-chatbot-v8-msgboard.hf.space"]};</script> | |
| <script src="web/reader.js"></script> | |
| <script> | |
| "use strict";''') | |
| hooks = (root/'web/native-hooks.js').read_text() | |
| text=text.replace('\nboot();\n', '\n'+hooks+'\nboot().then(notifyArchiveReady).catch(showArchiveError);\n') | |
| (root/'board.html').write_text(text) | |
| print('Built board.html from the original dashboard and static adapter') | |