Percy3822 commited on
Commit
d1d7385
·
verified ·
1 Parent(s): dd69c3f

Update static/ui.html

Browse files
Files changed (1) hide show
  1. 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
- <meta name="viewport" content="width=device-width,initial-scale=1">
6
- <title>Brain Console</title>
7
- <style>
8
- body{margin:0;background:#0b1020;color:#e9eefc;font-family:sans-serif}
9
- header{padding:16px;background:#121a2e}
10
- h1{margin:0;font-size:18px}
11
- main{display:grid;gap:16px;padding:16px}
12
- .card{background:#121a2e;border:1px solid #1b2544;border-radius:10px;padding:12px}
13
- button{background:#1a2750;color:#fff;border:none;border-radius:6px;padding:8px 12px;cursor:pointer}
14
- textarea{width:100%;height:120px;background:#0d142a;color:#fff;border-radius:6px;padding:8px}
15
- pre{white-space:pre-wrap;background:#0d142a;padding:8px;border-radius:6px}
16
- </style>
 
 
 
 
 
 
 
17
  </head>
18
  <body>
19
- <header><h1>🧠 Brain Console</h1></header>
20
  <main>
21
- <section class="card">
 
 
 
22
  <button onclick="doHealth()">GET /health</button>
23
  <button onclick="doWarmup()">POST /warmup</button>
24
- <button onclick="doCodeHelp()">POST /code_help</button>
25
- <button onclick="doTTS()">POST /tts_speak</button>
26
- <button onclick="doSTT()">POST /stt_transcribe</button>
27
- </section>
28
- <section class="card">
29
- <h3>Request Body</h3>
30
- <textarea id="req"></textarea>
31
- <button onclick="loadSample()">Load Sample JSON</button>
32
- </section>
33
- <section class="card">
34
- <h3>Response</h3>
35
- <pre id="resp"></pre>
36
- <audio id="aud" controls style="display:none"></audio>
37
- </section>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  </main>
39
  <script>
40
- async function doHealth(){const r=await fetch("/health");resp.textContent=JSON.stringify(await r.json(),null,2);}
41
- async function doWarmup(){const r=await fetch("/warmup",{method:"POST"});resp.textContent=JSON.stringify(await r.json(),null,2);}
42
- async function doCodeHelp(){try{const body=JSON.parse(req.value);const r=await fetch("/code_help",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(body)});const j=await r.json();resp.textContent=JSON.stringify(j,null,2);if(j.tts_audio_url){aud.src=j.tts_audio_url;aud.style.display="";}}catch(e){alert("Bad JSON");}}
43
- async function doTTS(){const body={text:"Hello from Brain"};const r=await fetch("/tts_speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(body)});const j=await r.json();resp.textContent=JSON.stringify(j,null,2);if(j.tts_audio_url){aud.src=j.tts_audio_url;aud.style.display="";}}
44
- async function doSTT(){alert("Use curl: curl -X POST -F file=@sample.wav "+window.location.origin+"/stt_transcribe");}
45
- function loadSample(){req.value=JSON.stringify({utterance:"please fix",telemetry:{file:"main.py",lang:"python",cursor:{l:1,c:1},viewport:{start:1,end:3,text:"print(reslt)"},diag:[{l:1,sev:"error",msg:"NameError"}],term:"Traceback"},memory:{short:[],sess:[],proj:[]},response_mode:"patch"},null,2);}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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():&#10; return 1&#10;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>