Spaces:
Running
Running
Deploy HF Module Manager UI
Browse files- index.html +111 -19
index.html
CHANGED
|
@@ -1,19 +1,111 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>ChatSeed HF Module Manager</title>
|
| 7 |
+
<style>
|
| 8 |
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
| 9 |
+
body { font-family: system-ui, -apple-system, sans-serif; background: #0f172a; color: #e2e8f0; min-height: 100vh; }
|
| 10 |
+
.app { max-width: 900px; margin: 0 auto; padding: 24px; }
|
| 11 |
+
header { display: flex; align-items: center; justify-content: space-between; padding: 16px 0; border-bottom: 1px solid #1e293b; margin-bottom: 24px; }
|
| 12 |
+
header h1 { font-size: 1.4rem; display: flex; align-items: center; gap: 8px; }
|
| 13 |
+
header h1 span { background: #059669; color: #fff; font-size: 0.6rem; padding: 2px 8px; border-radius: 999px; font-weight: 500; }
|
| 14 |
+
.status-bar { display: flex; align-items: center; gap: 12px; background: #1e293b; padding: 10px 16px; border-radius: 12px; margin-bottom: 20px; font-size: 0.85rem; }
|
| 15 |
+
.btn { padding: 8px 16px; border: none; border-radius: 8px; cursor: pointer; font-size: 0.8rem; font-weight: 500; transition: all 0.15s; }
|
| 16 |
+
.btn-primary { background: #059669; color: #fff; }
|
| 17 |
+
.btn-primary:hover { background: #047857; }
|
| 18 |
+
.btn-outline { background: transparent; border: 1px solid #334155; color: #cbd5e1; }
|
| 19 |
+
.btn-outline:hover { background: #1e293b; }
|
| 20 |
+
.card { background: #1e293b; border: 1px solid #334155; border-radius: 14px; padding: 20px; margin-bottom: 16px; }
|
| 21 |
+
.card h3 { font-size: 0.9rem; color: #94a3b8; margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
|
| 22 |
+
.tool-btn { display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 14px; background: #0f172a; border: 1px solid #334155; border-radius: 10px; color: #e2e8f0; cursor: pointer; font-size: 0.8rem; transition: all 0.15s; }
|
| 23 |
+
.tool-btn:hover { border-color: #059669; background: #1a2332; }
|
| 24 |
+
.tool-btn .icon { font-size: 1.1rem; width: 24px; text-align: center; }
|
| 25 |
+
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.7); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; }
|
| 26 |
+
.modal { background: #1e293b; border: 1px solid #334155; border-radius: 16px; padding: 24px; width: 520px; max-width: 100%; box-shadow: 0 25px 50px rgba(0,0,0,0.4); }
|
| 27 |
+
.modal h2 { margin-bottom: 16px; font-size: 1.1rem; }
|
| 28 |
+
.modal input, .modal textarea, .modal select { width: 100%; padding: 10px 12px; background: #0f172a; border: 1px solid #475569; border-radius: 8px; color: #f1f5f9; font-size: 0.85rem; margin-bottom: 12px; box-sizing: border-box; }
|
| 29 |
+
.modal textarea { min-height: 80px; font-family: monospace; }
|
| 30 |
+
.output { background: #0f172a; border: 1px solid #334155; border-radius: 10px; padding: 14px; margin-top: 12px; white-space: pre-wrap; font-family: monospace; font-size: 0.78rem; line-height: 1.6; max-height: 400px; overflow-y: auto; }
|
| 31 |
+
.hidden { display: none; }
|
| 32 |
+
.flex { display: flex; gap: 8px; }
|
| 33 |
+
.flex-1 { flex: 1; }
|
| 34 |
+
footer { text-align: center; padding: 24px; color: #475569; font-size: 0.75rem; border-top: 1px solid #1e293b; margin-top: 32px; }
|
| 35 |
+
</style>
|
| 36 |
+
</head>
|
| 37 |
+
<body>
|
| 38 |
+
<div class="app">
|
| 39 |
+
<header>
|
| 40 |
+
<h1>π€ ChatSeed <span>HF Module v10</span></h1>
|
| 41 |
+
<div><span id="statusText" style="font-size:0.8rem;color:#94a3b8;">Online</span></div>
|
| 42 |
+
</header>
|
| 43 |
+
<div class="status-bar">
|
| 44 |
+
<div style="flex:1;display:flex;gap:8px;align-items:center;"><span>π</span><span id="tokenLabel" style="color:#94a3b8;">No token set</span></div>
|
| 45 |
+
<button class="btn btn-outline" onclick="showTokenPopup()">Login</button>
|
| 46 |
+
<button class="btn btn-outline" onclick="logout()">Logout</button>
|
| 47 |
+
</div>
|
| 48 |
+
<div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:20px;">
|
| 49 |
+
<button class="tool-btn" onclick="whoami()"><span class="icon">π</span><span class="name">Whoami</span><span class="arrow">β</span></button>
|
| 50 |
+
<button class="tool-btn" onclick="listSpaces()"><span class="icon">π</span><span class="name">My Spaces</span><span class="arrow">β</span></button>
|
| 51 |
+
<button class="tool-btn" onclick="showCreateSpace()"><span class="icon">β¨</span><span class="name">Create Space</span><span class="arrow">β</span></button>
|
| 52 |
+
<button class="tool-btn" onclick="showSpaceStatus()"><span class="icon">π</span><span class="name">Space Status</span><span class="arrow">β</span></button>
|
| 53 |
+
<button class="tool-btn" onclick="showUploadFile()"><span class="icon">π</span><span class="name">Upload File</span><span class="arrow">β</span></button>
|
| 54 |
+
<button class="tool-btn" onclick="showSearchSpaces()"><span class="icon">π</span><span class="name">Search</span><span class="arrow">β</span></button>
|
| 55 |
+
</div>
|
| 56 |
+
<div class="card"><h3>π Output</h3><div id="output" class="output">π ChatSeed HF Module v10 loaded! Login to start.</div></div>
|
| 57 |
+
<div id="modalArea"></div>
|
| 58 |
+
<footer>ChatSeed HF Hub Manager v10 β <a href="https://huggingface.co/spaces/broadfield/hf-module" target="_blank" style="color:#60a5fa;">broadfield/hf-module</a></footer>
|
| 59 |
+
</div>
|
| 60 |
+
<div id="tokenPopup" class="modal-overlay hidden">
|
| 61 |
+
<div class="modal">
|
| 62 |
+
<h2>π Login</h2>
|
| 63 |
+
<p style="color:#94a3b8;font-size:0.85rem;margin-bottom:16px;">Token stored in localStorage.</p>
|
| 64 |
+
<input type="password" id="tokenInput" placeholder="hf_..." style="font-family:monospace;">
|
| 65 |
+
<label style="display:flex;align-items:center;gap:6px;font-size:0.8rem;color:#94a3b8;margin-bottom:12px;"><input type="checkbox" id="showToken" style="accent-color:#059669;"> Show</label>
|
| 66 |
+
<div class="flex"><button class="btn btn-primary flex-1" onclick="setToken()">π Set</button><button class="btn btn-outline" onclick="closeTokenPopup()">Cancel</button></div>
|
| 67 |
+
</div>
|
| 68 |
+
</div>
|
| 69 |
+
<script>
|
| 70 |
+
(function(){
|
| 71 |
+
'use strict';
|
| 72 |
+
const HF_API_BASE='https://huggingface.co';
|
| 73 |
+
function gt(){try{return localStorage.getItem('chatseed_hf_token')||''}catch(e){return ''}}
|
| 74 |
+
function st(t){try{localStorage.setItem('chatseed_hf_token',t)}catch(e){}}
|
| 75 |
+
function ct(){try{localStorage.removeItem('chatseed_hf_token')}catch(e){}}
|
| 76 |
+
function ah(){const t=gt();if(!t)throw new Error('No HF token');return{Authorization:'Bearer '+t}}
|
| 77 |
+
async function hf(p,o={}){const u=HF_API_BASE+p;const h={...ah(),'Content-Type':'application/json',...o.headers||{}};const r=await fetch(u,{...o,headers:h});if(!r.ok){let m='';try{const e=await r.json();m=e.error||JSON.stringify(e)}catch(e){m=r.statusText}throw new Error('HF '+r.status+': '+m)}if(r.status===204)return null;const c=r.headers.get('content-type')||'';if(c.includes('application/json'))return r.json();return r.text()}
|
| 78 |
+
async function cf(rt,ns,repo,files,s,d){return hf('/api/spaces/'+ns+'/'+repo+'/commit/main',{method:'POST',body:JSON.stringify({summary:s||'Update',description:d||'',files:files.map(f=>({path:f.path,content:f.content}))})})}
|
| 79 |
+
const tools={};
|
| 80 |
+
tools.token_status={handler:async function(){const t=gt();if(!t)return'π No token.';try{const i=await hf('/api/whoami-v2');return'π **Active** ('+t.substring(0,6)+'β¦'+t.substring(t.length-4)+')\nπ€ '+(i.name||i.user)+'\nπ§ '+(i.email||'N/A')}catch(e){return'β οΈ '+e.message}}};
|
| 81 |
+
tools.whoami={handler:async function(){try{const i=await hf('/api/whoami-v2');let r='**π€ User**\nName: '+(i.name||i.user)+'\nEmail: '+(i.email||'N/A');if(i.orgs&&i.orgs.length)r+='\nOrgs: '+i.orgs.map(o=>o.name).join(', ');return r}catch(e){return'β '+e.message}}};
|
| 82 |
+
tools.list_my_spaces={handler:async function(){const u=await hf('/api/whoami-v2');const n=u.name||u.user;const r=await hf('/api/spaces?author='+encodeURIComponent(n)+'&limit=25&sort=lastModified');if(!r||!r.length)return'π No spaces.';let o='π **Spaces ('+n+'):**\n';r.forEach(s=>{o+='\n'+(s.private?'π':'π')+' **'+(s.id||s.namespace+'/'+s.name)+'**'+(s.sdk?' ['+s.sdk+']':'')+(s.runtime?.stage?' β '+s.runtime.stage:'')});return o}};
|
| 83 |
+
tools.create_space={handler:async function(a){const ns=a.org||(await hf('/api/whoami-v2')).name;const p={name:a.name,type:'space',sdk:a.sdk||'gradio',private:a.private||false};if(a.hardware)p.hardware=a.hardware;if(a.sleep_time)p.sleep_time=a.sleep_time;const r=await hf('/api/repos/create',{method:'POST',body:JSON.stringify(p)});return'β
**Created:** '+ns+'/'+a.name+'\nπ https://huggingface.co/spaces/'+ns+'/'+a.name}};
|
| 84 |
+
tools.hf_upload_file={handler:async function(a){const p=a.repo_id.split('/');if(p.length!==2)return'β Invalid';await cf('space',p[0],p[1],[{path:a.path,content:a.content}]);return'β
Uploaded `'+a.path+'` β `'+a.repo_id+'`'}};
|
| 85 |
+
tools.space_status={handler:async function(a){const p=a.repo_id.split('/');if(p.length!==2)return'β Invalid';const r=await hf('/api/spaces/'+p[0]+'/'+p[1]+'/runtime');const ri=await hf('/api/spaces/'+p[0]+'/'+p[1]);const s=r.stage||'UNKNOWN';const em={'NO_APP_FILE':'π','BUILDING':'π¨','RUNNING':'β
','PAUSED':'βΈοΈ','SLEEPING':'π€','ERROR':'β'};return'**π Status:** `'+a.repo_id+'`\n**Stage:** '+(em[s]||'β')+' '+s+'\n**SDK:** '+(ri.sdk||'N/A')+'\n**URL:** https://huggingface.co/spaces/'+a.repo_id+'\n**App:** https://'+p[0]+'-'+p[1]+'.hf.space'}};
|
| 86 |
+
tools.search_spaces={handler:async function(a){const r=await hf('/api/spaces?search='+encodeURIComponent(a.query)+'&limit=5&sort=likes');if(!r||!r.length)return'π None';let o='π **"'+a.query+'"**\n';r.forEach((s,i)=>{o+='\n'+(i+1)+'. **'+(s.id||s.namespace+'/'+s.name)+'**'+(s.sdk?' ['+s.sdk+']':'')+(s.likes?' οΏ½οΏ½οΏ½'+s.likes:'')});return o}};
|
| 87 |
+
|
| 88 |
+
const out=document.getElementById('output');
|
| 89 |
+
function log(m){out.textContent=m}
|
| 90 |
+
window.whoami=async function(){try{log(await tools.whoami.handler())}catch(e){log('β '+e.message)}};
|
| 91 |
+
window.listSpaces=async function(){try{log(await tools.list_my_spaces.handler())}catch(e){log('β '+e.message)}};
|
| 92 |
+
window.showTokenPopup=function(){document.getElementById('tokenPopup').classList.remove('hidden');document.getElementById('tokenInput').focus()};
|
| 93 |
+
window.closeTokenPopup=function(){document.getElementById('tokenPopup').classList.add('hidden')};
|
| 94 |
+
window.setToken=async function(){const v=document.getElementById('tokenInput').value.trim();if(!v)return;st(v);log('β
Token set. Verifying...');try{const i=await hf('/api/whoami-v2');log('β
**Authenticated as** '+(i.name||i.user));closeTokenPopup();updateUI()}catch(e){log('β οΈ Stored but verify failed: '+e.message);closeTokenPopup();updateUI()}};
|
| 95 |
+
window.logout=function(){ct();updateUI();log('πͺ Logged out.')};
|
| 96 |
+
window.showCreateSpace=function(){document.getElementById('modalArea').innerHTML='<div class="modal-overlay" onclick="if(event.target===this)closeModal()"><div class="modal"><h2>β¨ Create Space</h2><input id="spName" placeholder="Space name"><select id="spSdk"><option value="gradio">Gradio</option><option value="streamlit">Streamlit</option><option value="docker">Docker</option><option value="static">Static</option></select><input id="spHw" placeholder="Hardware (optional)"><label style="display:flex;align-items:center;gap:6px;font-size:0.8rem;margin-bottom:12px;"><input type="checkbox" id="spPriv" style="accent-color:#059669;"> Private</label><button class="btn btn-primary" onclick="createSpace()">π Create</button></div></div>'};
|
| 97 |
+
window.createSpace=async function(){const n=document.getElementById('spName').value.trim();if(!n)return;const a={name:n,sdk:document.getElementById('spSdk').value};if(document.getElementById('spPriv').checked)a.private=true;const h=document.getElementById('spHw').value.trim();if(h)a.hardware=h;try{log(await tools.create_space.handler(a));closeModal()}catch(e){log('β '+e.message)}};
|
| 98 |
+
window.showSpaceStatus=function(){document.getElementById('modalArea').innerHTML='<div class="modal-overlay" onclick="if(event.target===this)closeModal()"><div class="modal"><h2>π Status</h2><input id="stRepo" placeholder="namespace/space-name"><button class="btn btn-primary" onclick="getStatus()">π Check</button></div></div>'};
|
| 99 |
+
window.getStatus=async function(){const id=document.getElementById('stRepo').value.trim();if(!id)return;try{log(await tools.space_status.handler({repo_id:id}));closeModal()}catch(e){log('β '+e.message)}};
|
| 100 |
+
window.showUploadFile=function(){document.getElementById('modalArea').innerHTML='<div class="modal-overlay" onclick="if(event.target===this)closeModal()"><div class="modal"><h2>π Upload</h2><input id="upRepo" placeholder="namespace/space-name"><input id="upPath" placeholder="path/to/file"><textarea id="upContent" placeholder="file content..."></textarea><button class="btn btn-primary" onclick="uploadFile()">π€ Upload</button></div></div>'};
|
| 101 |
+
window.uploadFile=async function(){const r=document.getElementById('upRepo').value.trim();const p=document.getElementById('upPath').value.trim();const c=document.getElementById('upContent').value;if(!r||!p)return;try{log(await tools.hf_upload_file.handler({repo_id:r,path:p,content:c}));closeModal()}catch(e){log('β '+e.message)}};
|
| 102 |
+
window.showSearchSpaces=function(){document.getElementById('modalArea').innerHTML='<div class="modal-overlay" onclick="if(event.target===this)closeModal()"><div class="modal"><h2>π Search</h2><input id="sq" placeholder="Search..."><button class="btn btn-primary" onclick="searchSpaces()">π Search</button></div></div>'};
|
| 103 |
+
window.searchSpaces=async function(){const q=document.getElementById('sq').value.trim();if(!q)return;try{log(await tools.search_spaces.handler({query:q}));closeModal()}catch(e){log('β '+e.message)}};
|
| 104 |
+
window.closeModal=function(){document.getElementById('modalArea').innerHTML=''};
|
| 105 |
+
function updateUI(){const t=gt();document.getElementById('tokenLabel').innerHTML=t?'β
<strong>Token set</strong> ('+t.substring(0,6)+'β¦'+t.substring(t.length-4)+')':'β No token set'}
|
| 106 |
+
const t=gt();if(t){(async()=>{try{log(await tools.token_status.handler()+'\n\nπ Click any button!')}catch(e){}})()}updateUI()
|
| 107 |
+
document.getElementById('showToken').addEventListener('change',function(){document.getElementById('tokenInput').type=this.checked?'text':'password'});
|
| 108 |
+
})();
|
| 109 |
+
</script>
|
| 110 |
+
</body>
|
| 111 |
+
</html>
|