ajit3259 commited on
Commit
e0ddf2a
Β·
1 Parent(s): 009e190

fix: Qwen2.5-VL chat template, skip embed on empty summary

Browse files
Files changed (2) hide show
  1. app.py +2 -0
  2. lm.py +10 -3
app.py CHANGED
@@ -402,6 +402,8 @@ async def _process(cid: int, type: str, **kwargs):
402
  else:
403
  return
404
  summary = result.get("summary") or ""
 
 
405
  claims = result.get("claims") or []
406
  title = result.get("title") or ""
407
  intent = result.get("intent")
 
402
  else:
403
  return
404
  summary = result.get("summary") or ""
405
+ if not summary:
406
+ raise ValueError("LM returned empty summary")
407
  claims = result.get("claims") or []
408
  title = result.get("title") or ""
409
  intent = result.get("intent")
lm.py CHANGED
@@ -380,12 +380,19 @@ else:
380
  img = _PILImage.open(file_path).convert("RGB")
381
  if max(img.width, img.height) > 768:
382
  img.thumbnail((768, 768), _PILImage.LANCZOS)
383
- # Match inputs to wherever the model actually is (ZeroGPU may or may not have moved it)
 
 
 
 
 
384
  device = next(vl_model.parameters()).device
385
- inputs = processor(text=text_prompt, images=img, return_tensors="pt").to(device)
 
386
  with torch.no_grad():
387
  out = vl_model.generate(**inputs, max_new_tokens=256)
388
- return processor.decode(out[0], skip_special_tokens=True)
 
389
 
390
 
391
  # ══════════════════════════════════════════════════════════════════════════════
 
380
  img = _PILImage.open(file_path).convert("RGB")
381
  if max(img.width, img.height) > 768:
382
  img.thumbnail((768, 768), _PILImage.LANCZOS)
383
+ # Qwen2.5-VL requires chat-template format with explicit image content blocks
384
+ messages = [{"role": "user", "content": [
385
+ {"type": "image", "image": img},
386
+ {"type": "text", "text": text_prompt},
387
+ ]}]
388
+ text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
389
  device = next(vl_model.parameters()).device
390
+ inputs = processor(text=[text], images=[img], return_tensors="pt").to(device)
391
+ input_len = inputs["input_ids"].shape[1]
392
  with torch.no_grad():
393
  out = vl_model.generate(**inputs, max_new_tokens=256)
394
+ # Slice off the prompt tokens, decode only the generated part
395
+ return processor.decode(out[0][input_len:], skip_special_tokens=True)
396
 
397
 
398
  # ══════════════════════════════════════════════════════════════════════════════