Andhs commited on
Commit
eca03f4
·
verified ·
1 Parent(s): e3be01a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -481,7 +481,7 @@ def generate_text_sse():
481
  temperature=temperature, cfg_scale=cfg_scale, remasking=remasking,
482
  capture_interval=capture_interval
483
  ):
484
- yield f"data: {json.dumps(state)}"
485
  else:
486
  streamer = TextIteratorStreamer(
487
  tokenizer, skip_prompt=True, skip_special_tokens=True
@@ -504,11 +504,14 @@ def generate_text_sse():
504
 
505
  accumulated = []
506
  for text in streamer:
 
 
507
  accumulated.append(text)
508
- yield f"data: {json.dumps({'type': 'token', 'text': text})}"
 
509
 
510
  full_text = "".join(accumulated)
511
- yield f"data: {json.dumps({'type': 'final', 'text': full_text, 'total_steps': 1})}"
512
 
513
  return Response(
514
  stream(), mimetype='text/event-stream',
 
481
  temperature=temperature, cfg_scale=cfg_scale, remasking=remasking,
482
  capture_interval=capture_interval
483
  ):
484
+ yield f"data: {json.dumps(state)}\n\n"
485
  else:
486
  streamer = TextIteratorStreamer(
487
  tokenizer, skip_prompt=True, skip_special_tokens=True
 
504
 
505
  accumulated = []
506
  for text in streamer:
507
+ if not text: # skip empty chunks
508
+ continue
509
  accumulated.append(text)
510
+ current = "".join(accumulated)
511
+ yield f"data: {json.dumps({'type': 'intermediate', 'text': current})}\n\n"
512
 
513
  full_text = "".join(accumulated)
514
+ yield f"data: {json.dumps({'type': 'final', 'text': full_text, 'total_steps': 1})}\n\n"
515
 
516
  return Response(
517
  stream(), mimetype='text/event-stream',