broadfield commited on
Commit
8ec1ecd
Β·
verified Β·
1 Parent(s): 8b1c07f

Deploy HF Module Manager UI

Browse files
Files changed (1) hide show
  1. index.html +111 -19
index.html CHANGED
@@ -1,19 +1,111 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>