Jiaqi-hkust commited on
Commit
cd9ad70
·
verified ·
1 Parent(s): 574dacd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -352,6 +352,14 @@ def _build_device_map(model: Any) -> tuple[dict[str, Any], str]:
352
  return device_map, same_device_modules[0]
353
 
354
 
 
 
 
 
 
 
 
 
355
  def ensure_runtime() -> tuple[Any, Any]:
356
  inferencer = _runtime_cache["inferencer"]
357
  pil_img2rgb = _runtime_cache["pil_img2rgb"]
@@ -515,7 +523,7 @@ def edit_image(
515
  result_text += chunk
516
  else:
517
  last_image = chunk
518
- yield last_image, result_text
519
 
520
 
521
  def update_edit_thinking_visibility(show: bool):
 
352
  return device_map, same_device_modules[0]
353
 
354
 
355
+ def _clean_reasoning_trace(text: str) -> str:
356
+ for token in ("<|im_start|>", "<|im_end|>", "<|endoftext|>"):
357
+ text = text.replace(token, "")
358
+ end_tag = "</think>"
359
+ if end_tag in text:
360
+ text = text.split(end_tag, 1)[0] + end_tag
361
+ return text
362
+
363
  def ensure_runtime() -> tuple[Any, Any]:
364
  inferencer = _runtime_cache["inferencer"]
365
  pil_img2rgb = _runtime_cache["pil_img2rgb"]
 
523
  result_text += chunk
524
  else:
525
  last_image = chunk
526
+ yield last_image, _clean_reasoning_trace(result_text)
527
 
528
 
529
  def update_edit_thinking_visibility(show: bool):