Update static/ui.html
Browse files- static/ui.html +141 -35
static/ui.html
CHANGED
|
@@ -1,48 +1,154 @@
|
|
| 1 |
<!doctype html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
-
<meta charset="utf-8"
|
| 5 |
-
<
|
| 6 |
-
<
|
| 7 |
-
<style>
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
</head>
|
| 18 |
<body>
|
| 19 |
-
<header><h1
|
| 20 |
<main>
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
<button onclick="doHealth()">GET /health</button>
|
| 23 |
<button onclick="doWarmup()">POST /warmup</button>
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
</
|
| 33 |
-
<
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
</main>
|
| 39 |
<script>
|
| 40 |
-
async function doHealth(){
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
async function
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
</script>
|
| 47 |
</body>
|
| 48 |
</html>
|
|
|
|
| 1 |
<!doctype html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
+
<meta charset="utf-8"/>
|
| 5 |
+
<title>Brain UI – Test Panel</title>
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
| 7 |
+
<style>
|
| 8 |
+
body{font-family:system-ui,Segoe UI,Roboto,Helvetica,Arial,sans-serif;margin:0;background:#0b0f19;color:#e5e7eb}
|
| 9 |
+
header{padding:16px 20px;background:#111827;position:sticky;top:0}
|
| 10 |
+
h1{margin:0;font-size:18px}
|
| 11 |
+
main{padding:20px;display:grid;gap:16px;grid-template-columns:repeat(auto-fit,minmax(320px,1fr))}
|
| 12 |
+
section{background:#111827;border:1px solid #1f2937;border-radius:12px;padding:16px}
|
| 13 |
+
h2{margin:0 0 12px 0;font-size:16px}
|
| 14 |
+
label{display:block;margin:8px 0 4px 0}
|
| 15 |
+
input[type="text"],textarea{width:100%;padding:10px;border-radius:8px;border:1px solid #374151;background:#0b1220;color:#e5e7eb}
|
| 16 |
+
input[type="file"]{margin:8px 0 12px 0}
|
| 17 |
+
button{background:#2563eb;border:none;color:white;padding:10px 14px;border-radius:8px;cursor:pointer}
|
| 18 |
+
button:disabled{opacity:0.6;cursor:not-allowed}
|
| 19 |
+
.row{display:flex;gap:8px;flex-wrap:wrap}
|
| 20 |
+
pre{white-space:pre-wrap;background:#0b1220;border:1px solid #1f2937;color:#cbd5e1;border-radius:8px;padding:10px;max-height:220px;overflow:auto}
|
| 21 |
+
audio{width:100%;margin-top:8px}
|
| 22 |
+
small{opacity:.7}
|
| 23 |
+
</style>
|
| 24 |
</head>
|
| 25 |
<body>
|
| 26 |
+
<header><h1>Brain UI · TTS · STT · Code Help · Memory</h1></header>
|
| 27 |
<main>
|
| 28 |
+
|
| 29 |
+
<section id="warmup">
|
| 30 |
+
<h2>Warmup / Health</h2>
|
| 31 |
+
<div class="row">
|
| 32 |
<button onclick="doHealth()">GET /health</button>
|
| 33 |
<button onclick="doWarmup()">POST /warmup</button>
|
| 34 |
+
</div>
|
| 35 |
+
<pre id="healthOut"></pre>
|
| 36 |
+
</section>
|
| 37 |
+
|
| 38 |
+
<section id="tts">
|
| 39 |
+
<h2>TTS</h2>
|
| 40 |
+
<label>Text</label>
|
| 41 |
+
<textarea id="ttsText" rows="3">Hello from Brain through ActualTTS.</textarea>
|
| 42 |
+
<div class="row"><button id="ttsBtn" onclick="doTTS()">POST /speak</button></div>
|
| 43 |
+
<audio id="ttsAudio" controls></audio>
|
| 44 |
+
<pre id="ttsOut"></pre>
|
| 45 |
+
</section>
|
| 46 |
+
|
| 47 |
+
<section id="stt">
|
| 48 |
+
<h2>STT</h2>
|
| 49 |
+
<label>Audio file (.wav recommended)</label>
|
| 50 |
+
<input type="file" id="sttFile" accept="audio/*"/>
|
| 51 |
+
<div class="row"><button id="sttBtn" onclick="doSTT()">POST /transcribe</button></div>
|
| 52 |
+
<pre id="sttOut"></pre>
|
| 53 |
+
</section>
|
| 54 |
+
|
| 55 |
+
<section id="codehelp">
|
| 56 |
+
<h2>Code Help</h2>
|
| 57 |
+
<label>Viewport text</label>
|
| 58 |
+
<textarea id="vp" rows="4">def foo(): return 1 print(reslt)</textarea>
|
| 59 |
+
<div class="row"><button id="codeBtn" onclick="doCodeHelp()">POST /code_help</button></div>
|
| 60 |
+
<pre id="codeOut"></pre>
|
| 61 |
+
</section>
|
| 62 |
+
|
| 63 |
+
<section id="memory">
|
| 64 |
+
<h2>Memory</h2>
|
| 65 |
+
<label>Item</label>
|
| 66 |
+
<input type="text" id="memItem" placeholder="Something to remember"/>
|
| 67 |
+
<div class="row">
|
| 68 |
+
<button onclick="saveMem('short')">Save to short</button>
|
| 69 |
+
<button onclick="saveMem('sess')">Save to sess</button>
|
| 70 |
+
<button onclick="saveMem('proj')">Save to proj</button>
|
| 71 |
+
<button onclick="clearMem('')">Clear ALL</button>
|
| 72 |
+
</div>
|
| 73 |
+
<div class="row">
|
| 74 |
+
<button onclick="clearMem('short')">Clear short</button>
|
| 75 |
+
<button onclick="clearMem('sess')">Clear sess</button>
|
| 76 |
+
<button onclick="clearMem('proj')">Clear proj</button>
|
| 77 |
+
<button onclick="loadMem()">GET /memory</button>
|
| 78 |
+
</div>
|
| 79 |
+
<pre id="memOut"></pre>
|
| 80 |
+
</section>
|
| 81 |
+
|
| 82 |
</main>
|
| 83 |
<script>
|
| 84 |
+
async function doHealth(){
|
| 85 |
+
const r = await fetch('/health'); const j = await r.json();
|
| 86 |
+
document.getElementById('healthOut').textContent = JSON.stringify(j,null,2);
|
| 87 |
+
}
|
| 88 |
+
async function doWarmup(){
|
| 89 |
+
const r = await fetch('/warmup',{method:'POST'}); const j = await r.json();
|
| 90 |
+
document.getElementById('healthOut').textContent = JSON.stringify(j,null,2);
|
| 91 |
+
}
|
| 92 |
+
async function doTTS(){
|
| 93 |
+
const btn = document.getElementById('ttsBtn'); btn.disabled=true;
|
| 94 |
+
try{
|
| 95 |
+
const text = document.getElementById('ttsText').value;
|
| 96 |
+
const r = await fetch('/speak',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({text})});
|
| 97 |
+
const j = await r.json();
|
| 98 |
+
document.getElementById('ttsOut').textContent = JSON.stringify(j,null,2);
|
| 99 |
+
if(j.ok && j.audio_url){
|
| 100 |
+
const a = document.getElementById('ttsAudio'); a.src = j.audio_url; a.play().catch(()=>{});
|
| 101 |
+
}
|
| 102 |
+
}finally{btn.disabled=false}
|
| 103 |
+
}
|
| 104 |
+
async function doSTT(){
|
| 105 |
+
const btn = document.getElementById('sttBtn'); btn.disabled=true;
|
| 106 |
+
try{
|
| 107 |
+
const f = document.getElementById('sttFile').files[0];
|
| 108 |
+
if(!f){ alert('Pick an audio file'); return; }
|
| 109 |
+
const fd = new FormData(); fd.append('file', f, f.name);
|
| 110 |
+
const r = await fetch('/transcribe',{method:'POST', body: fd});
|
| 111 |
+
const j = await r.json();
|
| 112 |
+
document.getElementById('sttOut').textContent = JSON.stringify(j,null,2);
|
| 113 |
+
}finally{btn.disabled=false}
|
| 114 |
+
}
|
| 115 |
+
async function doCodeHelp(){
|
| 116 |
+
const btn = document.getElementById('codeBtn'); btn.disabled=true;
|
| 117 |
+
try{
|
| 118 |
+
const viewportText = document.getElementById('vp').value;
|
| 119 |
+
const payload = {
|
| 120 |
+
utterance: "please fix the error and make it run",
|
| 121 |
+
telemetry: {
|
| 122 |
+
file: "main.py",
|
| 123 |
+
lang: "python",
|
| 124 |
+
cursor: {l: 1, c: 1},
|
| 125 |
+
viewport: {start: 1, end: viewportText.split('\n').length, text: viewportText},
|
| 126 |
+
diag: [],
|
| 127 |
+
term: ""
|
| 128 |
+
},
|
| 129 |
+
memory: {short:[], sess:[], proj:[]},
|
| 130 |
+
response_mode: "patch"
|
| 131 |
+
};
|
| 132 |
+
const r = await fetch('/code_help',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(payload)});
|
| 133 |
+
const j = await r.json();
|
| 134 |
+
document.getElementById('codeOut').textContent = JSON.stringify(j,null,2);
|
| 135 |
+
}finally{btn.disabled=false}
|
| 136 |
+
}
|
| 137 |
+
async function loadMem(){
|
| 138 |
+
const r = await fetch('/memory'); const j = await r.json();
|
| 139 |
+
document.getElementById('memOut').textContent = JSON.stringify(j,null,2);
|
| 140 |
+
}
|
| 141 |
+
async function saveMem(bucket){
|
| 142 |
+
const item = document.getElementById('memItem').value;
|
| 143 |
+
const r = await fetch('/memory/save',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({bucket, item})});
|
| 144 |
+
const j = await r.json();
|
| 145 |
+
document.getElementById('memOut').textContent = JSON.stringify(j,null,2);
|
| 146 |
+
}
|
| 147 |
+
async function clearMem(bucket){
|
| 148 |
+
const r = await fetch('/memory/clear',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({bucket})});
|
| 149 |
+
const j = await r.json();
|
| 150 |
+
document.getElementById('memOut').textContent = JSON.stringify(j,null,2);
|
| 151 |
+
}
|
| 152 |
</script>
|
| 153 |
</body>
|
| 154 |
</html>
|