Michaellllaidi's picture
Deploy from HuggingChat
9b60183 verified
Raw History Blame Contribute Delete
23.1 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="theme-color" content="#0f172a">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<title>Local AI Agent</title>
<style>
:root{
--bg:#0f172a; --panel:#1e293b; --panel2:#273449; --accent:#6366f1;
--accent2:#22d3ee; --text:#e2e8f0; --muted:#94a3b8; --ok:#34d399; --warn:#fbbf24; --err:#f87171;
}
*{box-sizing:border-box; -webkit-tap-highlight-color:transparent;}
html,body{height:100%; margin:0;}
body{
background:var(--bg); color:var(--text);
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
display:flex; flex-direction:column; height:100dvh; overflow:hidden;
}
header{
display:flex; align-items:center; gap:10px; padding:10px 14px;
background:linear-gradient(90deg,var(--accent),var(--accent2));
color:#fff; font-weight:700; letter-spacing:.3px; flex-shrink:0;
}
header .logo{font-size:20px;}
header .spacer{flex:1;}
.pill{
font-size:11px; background:rgba(255,255,255,.2); padding:3px 9px; border-radius:99px;
font-weight:600;
}
.tabs{display:flex; background:var(--panel); border-bottom:1px solid #334155; flex-shrink:0;}
.tab{
flex:1; text-align:center; padding:10px 4px; font-size:13px; font-weight:600;
color:var(--muted); cursor:pointer; border-bottom:2px solid transparent; user-select:none;
}
.tab.active{color:var(--accent2); border-bottom-color:var(--accent2); background:rgba(99,102,241,.08);}
main{flex:1; display:flex; flex-direction:column; min-height:0;}
.view{display:none; flex:1; flex-direction:column; min-height:0;}
.view.active{display:flex;}
/* CHAT */
#chat{overflow-y:auto; padding:14px; display:flex; flex-direction:column; gap:12px; flex:1;}
.msg{max-width:88%; padding:10px 13px; border-radius:14px; font-size:14px; line-height:1.5; white-space:pre-wrap; word-break:break-word;}
.msg.user{align-self:flex-end; background:var(--accent); color:#fff; border-bottom-right-radius:4px;}
.msg.bot{align-self:flex-start; background:var(--panel2); border-bottom-left-radius:4px;}
.msg.bot .who{font-size:11px; color:var(--accent2); font-weight:700; margin-bottom:4px;}
.msg.error{background:#7f1d1d; color:#fecaca;}
.msg code, .msg pre{background:#0b1220; border-radius:6px; padding:2px 5px; font-size:12px;}
.msg pre{padding:8px; overflow-x:auto; margin:6px 0;}
.typing{color:var(--muted); font-size:13px; font-style:italic; align-self:flex-start;}
.inputbar{
display:flex; gap:8px; padding:10px; background:var(--panel); border-top:1px solid #334155; flex-shrink:0;
}
#inp{
flex:1; background:var(--panel2); border:1px solid #334155; color:var(--text);
border-radius:12px; padding:11px 13px; font-size:14px; outline:none; resize:none; max-height:120px;
}
#inp:focus{border-color:var(--accent);}
#send{
width:46px; height:46px; border:none; border-radius:12px; background:var(--accent); color:#fff;
font-size:18px; cursor:pointer; flex-shrink:0;
}
#send:active{transform:scale(.94);}
/* CODER */
.coder{display:flex; flex-direction:column; flex:1; min-height:0;}
.filebar{display:flex; gap:6px; padding:8px 10px; background:var(--panel); border-bottom:1px solid #334155; overflow-x:auto; flex-shrink:0;}
.file{
background:var(--panel2); border:1px solid #334155; color:var(--text); padding:5px 11px;
border-radius:8px; font-size:12px; cursor:pointer; white-space:nowrap;
}
.file.active{background:var(--accent); border-color:var(--accent); color:#fff;}
.file .x{color:var(--muted); margin-left:6px; font-weight:700;}
.file.active .x{color:#c7d2fe;}
.newfile{background:none; border:1px dashed var(--accent); color:var(--accent); padding:5px 11px; border-radius:8px; font-size:12px; cursor:pointer; white-space:nowrap;}
#editorWrap{flex:1; min-height:0; position:relative;}
#editor{
width:100%; height:100%; background:#0b1220; color:#d1e8ff; border:none; outline:none;
padding:14px; font-family:"Fira Code",Consolas,monospace; font-size:13px; line-height:1.55; resize:none; tab-size:2;
}
.runbar{display:flex; gap:8px; padding:8px 10px; background:var(--panel); border-top:1px solid #334155; flex-shrink:0; flex-wrap:wrap;}
.btn{
background:var(--accent); color:#fff; border:none; border-radius:9px; padding:9px 14px;
font-size:13px; font-weight:600; cursor:pointer;
}
.btn.ghost{background:var(--panel2); color:var(--text); border:1px solid #334155;}
.btn.ok{background:#059669;}
.btn:active{transform:scale(.96);}
#out{
background:#0b1220; color:#a5f3fc; padding:12px 14px; font-family:Consolas,monospace; font-size:12px;
white-space:pre-wrap; overflow-y:auto; max-height:38%; border-top:1px solid #334155; flex-shrink:0; min-height:60px;
}
.out-err{color:#fca5a5;}
/* SPACE */
.space{flex:1; overflow-y:auto; padding:16px; display:flex; flex-direction:column; gap:12px;}
.card{background:var(--panel); border:1px solid #334155; border-radius:14px; padding:14px;}
.card h3{margin:0 0 6px; font-size:15px; color:var(--accent2);}
.card p{margin:0 0 10px; font-size:13px; color:var(--muted); line-height:1.5;}
.row{display:flex; gap:8px; flex-wrap:wrap;}
.field{flex:1; min-width:120px; background:var(--panel2); border:1px solid #334155; color:var(--text); border-radius:9px; padding:10px; font-size:13px; outline:none;}
.field:focus{border-color:var(--accent);}
.preview{background:#0b1220; border-radius:10px; padding:12px; font-family:Consolas,monospace; font-size:12px; color:#a5f3fc; white-space:pre-wrap; max-height:220px; overflow:auto;}
.badge{display:inline-block; font-size:11px; background:rgba(34,211,238,.15); color:var(--accent2); padding:2px 8px; border-radius:99px; margin:2px 2px 0 0;}
.toast{
position:fixed; bottom:20px; left:50%; transform:translateX(-50%) translateY(80px);
background:var(--panel2); color:var(--text); padding:10px 18px; border-radius:10px;
border:1px solid var(--accent); font-size:13px; opacity:0; transition:.3s; z-index:50; pointer-events:none;
}
.toast.show{opacity:1; transform:translateX(-50%) translateY(0);}
.toast.ok{border-color:var(--ok);} .toast.err{border-color:var(--err);}
</style>
</head>
<body>
<header>
<span class="logo">🤖</span> Local AI Agent
<span class="spacer"></span>
<span class="pill">100% free · offline</span>
</header>
<div class="tabs">
<div class="tab active" data-view="chat">💬 Chat</div>
<div class="tab" data-view="coder">🧑‍💻 Code</div>
<div class="tab" data-view="space">🚀 Space</div>
</div>
<main>
<!-- CHAT -->
<div class="view active" id="view-chat">
<div id="chat">
<div class="msg bot"><div class="who">AGENT</div>Hey! I'm your local AI agent — free, private, runs right here on your device (works great on Android). I can help you <b>create programs</b>, run them in the sandbox, and <b>build &amp; deploy a Hugging Face Space</b>.
Try typing things like:
• "create a program that prints fibonacci"
• "make a todo list app"
• "build a space with a counter demo"
• "help me plan a project"</div>
</div>
<div class="inputbar">
<textarea id="inp" rows="1" placeholder="Message your agent…"></textarea>
<button id="send">➤</button>
</div>
</div>
<!-- CODER -->
<div class="view" id="view-coder">
<div class="coder">
<div class="filebar" id="filebar"></div>
<div id="editorWrap"><textarea id="editor" spellcheck="false"></textarea></div>
<div class="runbar">
<button class="btn ok" id="runBtn">▶ Run</button>
<button class="btn ghost" id="saveBtn">💾 Save</button>
<button class="btn ghost" id="newBtn">+ New file</button>
</div>
<div id="out">// Output appears here. Click ▶ Run to execute your program.</div>
</div>
</div>
<!-- SPACE -->
<div class="view" id="view-space">
<div class="space">
<div class="card">
<h3>🚀 Build &amp; Deploy a Hugging Face Space</h3>
<p>Generate a ready-to-push Gradio Space from your current code. The agent drafts <code>app.py</code> + <code>requirements.txt</code> for you — then copy the files and push with the <code>hf</code> CLI:</p>
<div class="preview" id="deployCmd">$ hf repos create my-space --type space --sdk gradio --private
$ hf upload my-space app.py requirements.txt</div>
</div>
<div class="card">
<h3>1 · Pick what to deploy</h3>
<div class="row">
<input class="field" id="spaceName" placeholder="space name (e.g. my-agent-demo)">
<button class="btn" id="genSpaceBtn">⚡ Generate Space</button>
</div>
<div style="margin-top:10px">
<span class="badge">Gradio</span><span class="badge">Python</span><span class="badge">Free CPU</span>
</div>
</div>
<div class="card">
<h3>2 · Generated files</h3>
<div class="preview" id="spacePreview">// Click "Generate Space" to draft app.py + requirements.txt</div>
</div>
<div class="card">
<h3>3 · Push to the Hub</h3>
<p>Copy the files above into a folder, then run these commands (install the CLI with <code>pip install -U "huggingface_hub[cli]"</code>):</p>
<div class="preview" id="pushCmd"># 1. create the space
$ hf repos create my-space --type space --sdk gradio --private
# 2. upload the generated files
$ hf upload my-space app.py
$ hf upload my-space requirements.txt
# 3. watch it build
$ hf spaces wait my-space</div>
</div>
</div>
</div>
</div>
<div class="toast" id="toast"></div>
<script>
/* ============ STATE ============ */
const files = {
"main.js": `// Welcome to your local agent workspace!
// Write any JavaScript program and hit ▶ Run.
function fibonacci(n){
const seq = [0, 1];
for(let i=2; i<n; i++) seq.push(seq[i-1] + seq[i-2]);
return seq.slice(0, n);
}
console.log("Hello from your local AI agent 🤖");
console.log("First 10 Fibonacci numbers:");
console.log(fibonacci(10).join(", "));`,
"todo.js": `// A tiny todo list program
const todos = [];
function add(t){ todos.push({text:t, done:false}); }
function toggle(i){ todos[i].done = !todos[i].done; }
function show(){
todos.forEach((t,i)=> console.log((t.done?"[x]":"[ ]")+" "+i+": "+t.text));
}
add("Build a program");
add("Run it in the sandbox");
add("Deploy a Space");
toggle(0);
show();`
};
let currentFile = "main.js";
/* ============ HELPERS ============ */
const $ = id => document.getElementById(id);
const chat = $('chat'), inp = $('inp'), out = $('out'), editor = $('editor');
function toast(msg, type=''){
const t = $('toast');
t.textContent = msg;
t.className = 'toast show ' + type;
clearTimeout(t._h);
t._h = setTimeout(()=> t.className='toast', 2200);
}
function addMsg(text, cls){
const d = document.createElement('div');
d.className = 'msg ' + cls;
if(cls==='bot') d.innerHTML = '<div class="who">AGENT</div>';
d.appendChild(document.createTextNode(text));
chat.appendChild(d);
chat.scrollTop = chat.scrollHeight;
return d;
}
/* ============ TABS ============ */
document.querySelectorAll('.tab').forEach(tab=>{
tab.addEventListener('click', ()=>{
document.querySelectorAll('.tab').forEach(t=>t.classList.remove('active'));
document.querySelectorAll('.view').forEach(v=>v.classList.remove('active'));
tab.classList.add('active');
$('view-'+tab.dataset.view).classList.add('active');
});
});
/* ============ CHAT AGENT ============ */
function agentReply(text){
const t = text.toLowerCase();
const typing = document.createElement('div');
typing.className = 'typing'; typing.textContent = 'agent is thinking…';
chat.appendChild(typing); chat.scrollTop = chat.scrollHeight;
setTimeout(()=>{
typing.remove();
let reply = '';
if(/fibonacci|fib/.test(t)){
reply = "Done! I created a program that prints the Fibonacci sequence.\n\nOpen the Code tab → file main.js to see it, then hit ▶ Run.\n\nWant me to make it interactive (ask the user for a number)?";
}
else if(/todo|to-do/.test(t)){
reply = "I added a todo-list program for you (todo.js in the Code tab). It lets you add items, toggle them done, and print the list. Run it to see the demo.";
}
else if(/space|deploy|build|sps/.test(t)){
reply = "Let's build a Space! 🚀 Go to the Space tab, type a name, and click \"Generate Space\". I'll draft app.py + requirements.txt for you, then give you the exact `hf` CLI commands to push it to the Hub.";
}
else if(/counter/.test(t)){
reply = "Here's a counter demo you can drop into a Gradio Space:\n\n```python\nimport gradio as gr\n\ndef count(n):\n return n + 1\n\ndemo = gr.Interface(\n fn=count,\n inputs=gr.Number(label=\"Current count\"),\n outputs=gr.Number(label=\"Next count\"),\n title=\"Counter Demo\"\n)\n\ndemo.launch()\n```\n\nGo to the Space tab and I'll generate it for you automatically.";
}
else if(/plan|project|idea/.test(t)){
reply = "Great — let's plan it! 🗺️\n\n1. **Goal** — what should it do?\n2. **Files** — which programs do we need?\n3. **Run** — test it in the Code tab sandbox.\n4. **Ship** — turn it into a Space and deploy.\n\nTell me your idea and I'll scaffold the first file for you.";
}
else if(/hi|hello|hey/.test(t)){
reply = "Hey there! 👋 I'm your local agent. I can create programs (Code tab), run them in a sandbox, and build & deploy a Hugging Face Space (Space tab). What shall we build?";
}
else if(/help|what can/.test(t)){
reply = "Here's what I can do:\n\n• 💬 Chat — plan and brainstorm\n• 🧑‍💻 Code — create & run JS programs in a sandbox\n• 🚀 Space — generate a deployable Hugging Face Space\n\nTry: \"create a program that prints fibonacci\"";
}
else if(/create|make|write|program|app|code/.test(t)){
reply = "Sure! Tell me what you want the program to do and I'll write it for you in the Code tab. For example:\n• \"make a todo list\"\n• \"fibonacci program\"\n• \"a counter demo\"\n\nI'll create a new file and you can run it instantly.";
}
else {
reply = "Got it. Here's my suggestion: let's turn that into a concrete program. Open the Code tab and I can scaffold it — or tell me more and I'll draft the first version. You can also ask me to \"build a space\" to ship it. 🤖";
}
addMsg(reply, 'bot');
}, 500);
}
$('send').addEventListener('click', sendMsg);
inp.addEventListener('keydown', e=>{
if(e.key==='Enter' && !e.shiftKey){ e.preventDefault(); sendMsg(); }
});
function sendMsg(){
const v = inp.value.trim();
if(!v) return;
addMsg(v, 'user');
inp.value=''; inp.style.height='auto';
agentReply(v);
}
inp.addEventListener('input', ()=>{ inp.style.height='auto'; inp.style.height=Math.min(inp.scrollHeight,120)+'px'; });
/* ============ CODER ============ */
function renderFiles(){
const bar = $('filebar');
bar.innerHTML='';
Object.keys(files).forEach(name=>{
const el = document.createElement('span');
el.className = 'file' + (name===currentFile?' active':'');
el.innerHTML = name + '<span class="x">✕</span>';
el.addEventListener('click', e=>{
if(e.target.classList.contains('x')){ delete files[name]; if(currentFile===name) currentFile=Object.keys(files)[0]; renderFiles(); loadEditor(); }
else { currentFile=name; renderFiles(); loadEditor(); }
});
bar.appendChild(el);
});
const nf = document.createElement('button');
nf.className='newfile'; nf.textContent='+';
nf.addEventListener('click', ()=>{
const n = prompt('New file name (e.g. app.js):');
if(n && !files[n]){ files[n]='// '+n+'\n'; currentFile=n; renderFiles(); loadEditor(); }
});
bar.appendChild(nf);
}
function loadEditor(){ editor.value = files[currentFile] || ''; }
$('saveBtn').addEventListener('click', ()=>{ files[currentFile]=editor.value; toast('Saved '+currentFile,'ok'); });
$('newBtn').addEventListener('click', ()=>{
const n = prompt('New file name (e.g. app.js):');
if(n && !files[n]){ files[n]='// '+n+'\n'; currentFile=n; renderFiles(); loadEditor(); }
});
/* RUN sandbox */
$('runBtn').addEventListener('click', runCode);
function runCode(){
files[currentFile]=editor.value;
out.className=''; out.textContent='▶ Running '+currentFile+'…';
const logs=[];
const origLog = console.log, origErr = console.error, origWarn = console.warn;
console.log = (...a)=> logs.push(a.map(fmt).join(' '));
console.warn = (...a)=> logs.push('⚠ '+a.map(fmt).join(' '));
console.error = (...a)=> logs.push('❌ '+a.map(fmt).join(' '));
function fmt(x){
if(typeof x==='object' && x!==null) return JSON.stringify(x);
return String(x);
}
try{
new Function(editor.value)();
out.textContent = logs.join('\n') || '// (no console output)';
}catch(e){
out.textContent = (logs.length? logs.join('\n')+'\n' : '') + '❌ Error: ' + e.message;
out.className='out-err';
}finally{
console.log=origLog; console.error=origErr; console.warn=origWarn;
}
}
/* ============ SPACE GENERATOR ============ */
$('genSpaceBtn').addEventListener('click', genSpace);
function genSpace(){
const name = ($('spaceName').value.trim() || 'my-agent-demo').toLowerCase().replace(/[^a-z0-9-]/g,'-');
const appPy = `import gradio as gr
# Generated by your Local AI Agent 🤖
# A friendly demo you can extend with your own logic.
def greet(name, excitement):
return f"Hello {name}!" + "!" * excitement
def counter(n):
return n + 1
with gr.Blocks(title="${name}") as demo:
gr.Markdown("# 🤖 ${name}")
gr.Markdown("Built with the **Local AI Agent** — free, local, and yours.")
with gr.Tab("Greeter"):
name = gr.Textbox(label="Your name", value="World")
excitement = gr.Slider(0, 5, value=1, step=1, label="Excitement")
out = gr.Textbox(label="Greeting")
greet_btn = gr.Button("Greet")
greet_btn.click(greet, [name, excitement], out)
with gr.Tab("Counter"):
num = gr.Number(label="Current", value=0)
nxt = gr.Number(label="Next", interactive=False)
step = gr.Button("Increment")
step.click(counter, num, nxt)
demo.launch()`;
const req = `gradio>=4.0`;
$('spacePreview').textContent = "── app.py ──\n" + appPy + "\n\n── requirements.txt ──\n" + req;
$('deployCmd').textContent =
`$ hf repos create ${name} --type space --sdk gradio --private
$ hf upload ${name} app.py
$ hf upload ${name} requirements.txt
$ hf spaces wait ${name}`;
$('pushCmd').textContent =
`# 1. create the space
$ hf repos create ${name} --type space --sdk gradio --private
# 2. upload the generated files
$ hf upload ${name} app.py
$ hf upload ${name} requirements.txt
# 3. watch it build & go live
$ hf spaces wait ${name}
# open it:
# https://huggingface.co/spaces/YOUR_USERNAME/${name}`;
toast('Space generated! 🚀','ok');
}
/* ============ INIT ============ */
renderFiles();
loadEditor();
</script>
</body>
</html>
<script data-huggingchat-badge="script">
(function () {
try {
if (document.querySelector("[data-huggingchat-badge]:not(script)")) return;
var host = document.createElement("div");
host.setAttribute("data-huggingchat-badge", "");
var styles = [["all","initial"],["position","fixed"],["right","12px"],["bottom","12px"],["z-index","2147483647"],["display","block"],["visibility","visible"],["opacity","1"],["pointer-events","auto"],["width","auto"],["height","auto"],["margin","0"],["padding","0"],["max-width","none"],["max-height","none"],["transform","none"],["filter","none"],["clip-path","none"],["color-scheme","light"]];
for (var i = 0; i < styles.length; i++) {
host.style.setProperty(styles[i][0], styles[i][1], "important");
}
host.attachShadow({ mode: "closed" }).innerHTML = "<style>\n:host { all: initial; }\na {\n display: flex;\n align-items: center;\n gap: 5px;\n box-sizing: border-box;\n height: 26px;\n padding: 0 9px 0 7px;\n border-radius: 999px;\n border: 1px solid rgba(0, 0, 0, 0.07);\n background: rgba(255, 255, 255, 0.92);\n -webkit-backdrop-filter: saturate(180%) blur(8px);\n backdrop-filter: saturate(180%) blur(8px);\n box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 6px 16px rgba(0, 0, 0, 0.06);\n color: #111827;\n font: 500 11px/1 ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif;\n letter-spacing: 0.01em;\n text-decoration: none;\n white-space: nowrap;\n opacity: 0.72;\n transition: opacity 0.15s ease, transform 0.15s ease;\n}\na:hover, a:focus-visible { opacity: 1; transform: translateY(-1px); }\nsvg { width: 14px; height: 14px; flex: none; }\n@media print { a { display: none; } }\n<\/style><a href=\"https://huggingface.co/chat\" target=\"_blank\" rel=\"noopener noreferrer nofollow\"><svg viewBox=\"0 0 32 32\" fill=\"none\" aria-hidden=\"true\"><path d=\"M16.0006 25.9992C13.8266 25.999 11.7118 25.2901 9.97686 23.9799C8.2419 22.6698 6.98127 20.8298 6.38599 18.7388C5.79071 16.6478 5.89323 14.4198 6.678 12.3923C7.46278 10.3648 8.88705 8.64837 10.735 7.50308C12.5829 6.35779 14.7538 5.84606 16.9187 6.04544C19.0837 6.24481 21.1246 7.14442 22.7323 8.60795C24.34 10.0715 25.4268 12.0192 25.8281 14.1559C26.2293 16.2926 25.9232 18.5019 24.9561 20.449C24.7703 20.8042 24.7223 21.2155 24.8211 21.604L25.4211 23.8316C25.4803 24.0518 25.4805 24.2837 25.4216 24.5039C25.3627 24.7242 25.2468 24.925 25.0856 25.0862C24.9244 25.2474 24.7235 25.3633 24.5033 25.4222C24.283 25.4811 24.0512 25.4809 23.831 25.4217L21.6034 24.8217C21.2172 24.7248 20.809 24.7729 20.4558 24.9567C19.0683 25.6467 17.5457 26.0068 16.0006 26.0068V25.9992Z\" fill=\"currentColor\"/><path d=\"M9.62598 16.0013C9.62598 15.3799 10.1294 14.8765 10.7508 14.8765C11.3721 14.8765 11.8756 15.3799 11.8756 16.0013C11.8756 17.0953 12.3102 18.1448 13.0838 18.9184C13.8574 19.692 14.9069 20.1266 16.001 20.1267C17.095 20.1267 18.1445 19.692 18.9181 18.9184C19.6918 18.1448 20.1264 17.0953 20.1264 16.0013C20.1264 15.3799 20.6299 14.8765 21.2512 14.8765C21.8725 14.8765 22.3759 15.3799 22.3759 16.0013C22.3759 17.6921 21.7046 19.3137 20.509 20.5093C19.3134 21.7049 17.6918 22.3762 16.001 22.3762C14.3102 22.3762 12.6885 21.7049 11.4929 20.5093C10.2974 19.3137 9.62598 17.6921 9.62598 16.0013Z\" fill=\"#fff\"/><\/svg><span>Made with HuggingChat<\/span><\/a>";
function attach() {
var parent = document.body || document.documentElement;
if (parent && host.parentNode !== parent) parent.appendChild(host);
}
attach();
// Artifacts that rewrite document.body wholesale would drop the badge.
if (document.body && typeof MutationObserver === "function") {
new MutationObserver(attach).observe(document.body, { childList: true });
} else {
document.addEventListener("DOMContentLoaded", attach);
}
} catch (e) {}
})();
</script>