Spaces:
Running on Zero
Running on Zero
Keep Pause available between automatic GPU sessions
Browse files- app.py +7 -1
- token_space.js +5 -5
app.py
CHANGED
|
@@ -192,7 +192,9 @@ def _run(flow, temperature, top_p, penalty, seed, count, watch, delay, memory=12
|
|
| 192 |
|
| 193 |
@spaces.GPU(duration=30)
|
| 194 |
def run(flow, temperature, top_p, penalty, seed, count, watch, delay, memory=128,
|
| 195 |
-
auto_continue=True, attention=True, attention_layer=-1, attention_head=-1):
|
|
|
|
|
|
|
| 196 |
for update in _run(flow, temperature, top_p, penalty, seed, count, watch, delay,
|
| 197 |
memory, auto_continue, attention, attention_layer, attention_head):
|
| 198 |
yield (*update, flow)
|
|
@@ -308,6 +310,8 @@ def build_app():
|
|
| 308 |
"Sliders apply live. The top overlay retains the full generated text; scroll it to read earlier passages.")
|
| 309 |
transport = gr.HTML('', elem_id="space-transport", elem_classes=["space-transport"])
|
| 310 |
start = gr.Button("Start generation", elem_id="generation-run", elem_classes=["generation-proxy"])
|
|
|
|
|
|
|
| 311 |
pause = gr.Button("Pause generation", elem_id="generation-pause", elem_classes=["generation-proxy"])
|
| 312 |
outputs = [page, panel, status, transport]
|
| 313 |
inputs = [flow, temperature, top_p, penalty, seed, count, watch, delay, memory, auto_continue,
|
|
@@ -325,6 +329,8 @@ def build_app():
|
|
| 325 |
reset_view, [flow], outputs, api_name="reset_model_state", **common)
|
| 326 |
start.click(run, inputs, [*outputs, flow], api_name="run", **common).failure(
|
| 327 |
refresh_view, [flow], transport, queue=False)
|
|
|
|
|
|
|
| 328 |
new_stream.click(begin, inputs, [*outputs, flow], api_name="begin", **common).failure(
|
| 329 |
refresh_view, [flow], transport, queue=False)
|
| 330 |
halt.click(stop, [flow], transport, queue=False)
|
|
|
|
| 192 |
|
| 193 |
@spaces.GPU(duration=30)
|
| 194 |
def run(flow, temperature, top_p, penalty, seed, count, watch, delay, memory=128,
|
| 195 |
+
auto_continue=True, attention=True, attention_layer=-1, attention_head=-1, automatic=False):
|
| 196 |
+
if automatic and (flow.paused or flow.reset_requested or not flow.continue_automatically):
|
| 197 |
+
return
|
| 198 |
for update in _run(flow, temperature, top_p, penalty, seed, count, watch, delay,
|
| 199 |
memory, auto_continue, attention, attention_layer, attention_head):
|
| 200 |
yield (*update, flow)
|
|
|
|
| 310 |
"Sliders apply live. The top overlay retains the full generated text; scroll it to read earlier passages.")
|
| 311 |
transport = gr.HTML('', elem_id="space-transport", elem_classes=["space-transport"])
|
| 312 |
start = gr.Button("Start generation", elem_id="generation-run", elem_classes=["generation-proxy"])
|
| 313 |
+
automatic_start = gr.Button("Continue GPU session", elem_id="generation-auto", elem_classes=["generation-proxy"])
|
| 314 |
+
automatic_request = gr.State(True)
|
| 315 |
pause = gr.Button("Pause generation", elem_id="generation-pause", elem_classes=["generation-proxy"])
|
| 316 |
outputs = [page, panel, status, transport]
|
| 317 |
inputs = [flow, temperature, top_p, penalty, seed, count, watch, delay, memory, auto_continue,
|
|
|
|
| 329 |
reset_view, [flow], outputs, api_name="reset_model_state", **common)
|
| 330 |
start.click(run, inputs, [*outputs, flow], api_name="run", **common).failure(
|
| 331 |
refresh_view, [flow], transport, queue=False)
|
| 332 |
+
automatic_start.click(run, [*inputs, automatic_request], [*outputs, flow], api_name=False, **common).failure(
|
| 333 |
+
refresh_view, [flow], transport, queue=False)
|
| 334 |
new_stream.click(begin, inputs, [*outputs, flow], api_name="begin", **common).failure(
|
| 335 |
refresh_view, [flow], transport, queue=False)
|
| 336 |
halt.click(stop, [flow], transport, queue=False)
|
token_space.js
CHANGED
|
@@ -8,10 +8,10 @@
|
|
| 8 |
let lastText='';
|
| 9 |
let paused=false, previousMode='live';
|
| 10 |
let textView=null,externalSelected=null,reader=null,readerSignature='',lastHighlighted=null;
|
| 11 |
-
let running=false,ended=false,togglePending=false,toggleButton=null;
|
| 12 |
function generationClick(){
|
| 13 |
if(togglePending||(running&&paused))return;
|
| 14 |
-
const pausing=running&&!paused;
|
| 15 |
const host=document.querySelector(pausing?'#generation-pause':ended?'#generation-new':'#generation-run');
|
| 16 |
const proxy=host?.querySelector?.('button')||host;
|
| 17 |
if(typeof proxy?.click!=='function')return;
|
|
@@ -25,7 +25,7 @@
|
|
| 25 |
toggleButton?.removeEventListener?.('click',generationClick);toggleButton=button;
|
| 26 |
toggleButton.addEventListener('click',generationClick);
|
| 27 |
}
|
| 28 |
-
const label=togglePending?toggleButton.textContent:running?(paused?'Pausing...':'Pause'):paused?'Resume':seen>=0&&!ended?'Resume':'Start';
|
| 29 |
if(toggleButton.textContent!==label)toggleButton.textContent=label;
|
| 30 |
toggleButton.disabled=togglePending||(running&&paused);
|
| 31 |
}
|
|
@@ -170,12 +170,12 @@
|
|
| 170 |
mount();const node=document.querySelector('[data-flow-frame]');if(!node)return;
|
| 171 |
const raw=node.getAttribute('data-flow-frame');if(raw===payload)return;
|
| 172 |
payload=raw;let data;try{data=JSON.parse(raw);}catch{return;}
|
| 173 |
-
running=Boolean(data.running);ended=Boolean(data.ended);togglePending=false;
|
| 174 |
if(data.continue_automatically&&!data.running&&!data.paused&&!data.ended){
|
| 175 |
const expectedStream=data.stream,expectedRevision=data.revision;
|
| 176 |
setTimeout(()=>{
|
| 177 |
if(stream===expectedStream && JSON.parse(payload).revision===expectedRevision && !running && !paused){
|
| 178 |
-
const host=document.querySelector('#generation-
|
| 179 |
const button=host?.tagName?.toLowerCase()==='button'?host:host?.querySelector('button')||host;
|
| 180 |
button?.click();
|
| 181 |
}
|
|
|
|
| 8 |
let lastText='';
|
| 9 |
let paused=false, previousMode='live';
|
| 10 |
let textView=null,externalSelected=null,reader=null,readerSignature='',lastHighlighted=null;
|
| 11 |
+
let running=false,awaitingGPU=false,ended=false,togglePending=false,toggleButton=null;
|
| 12 |
function generationClick(){
|
| 13 |
if(togglePending||(running&&paused))return;
|
| 14 |
+
const pausing=(running||awaitingGPU)&&!paused;
|
| 15 |
const host=document.querySelector(pausing?'#generation-pause':ended?'#generation-new':'#generation-run');
|
| 16 |
const proxy=host?.querySelector?.('button')||host;
|
| 17 |
if(typeof proxy?.click!=='function')return;
|
|
|
|
| 25 |
toggleButton?.removeEventListener?.('click',generationClick);toggleButton=button;
|
| 26 |
toggleButton.addEventListener('click',generationClick);
|
| 27 |
}
|
| 28 |
+
const label=togglePending?toggleButton.textContent:(running||awaitingGPU)?(paused?'Pausing...':'Pause'):paused?'Resume':seen>=0&&!ended?'Resume':'Start';
|
| 29 |
if(toggleButton.textContent!==label)toggleButton.textContent=label;
|
| 30 |
toggleButton.disabled=togglePending||(running&&paused);
|
| 31 |
}
|
|
|
|
| 170 |
mount();const node=document.querySelector('[data-flow-frame]');if(!node)return;
|
| 171 |
const raw=node.getAttribute('data-flow-frame');if(raw===payload)return;
|
| 172 |
payload=raw;let data;try{data=JSON.parse(raw);}catch{return;}
|
| 173 |
+
running=Boolean(data.running);awaitingGPU=Boolean(data.continue_automatically)&&!data.running&&!data.paused&&!data.ended;ended=Boolean(data.ended);togglePending=false;
|
| 174 |
if(data.continue_automatically&&!data.running&&!data.paused&&!data.ended){
|
| 175 |
const expectedStream=data.stream,expectedRevision=data.revision;
|
| 176 |
setTimeout(()=>{
|
| 177 |
if(stream===expectedStream && JSON.parse(payload).revision===expectedRevision && !running && !paused){
|
| 178 |
+
const host=document.querySelector('#generation-auto');
|
| 179 |
const button=host?.tagName?.toLowerCase()==='button'?host:host?.querySelector('button')||host;
|
| 180 |
button?.click();
|
| 181 |
}
|