davanstrien HF Staff Claude commited on
Commit
ddf6b7f
·
1 Parent(s): 6042172

Match official demo message format: text before image

Browse files

Update message format to match LightOn's official demo implementation:
- Add empty text element before image in content array
- Order: text first, then image (matching their Gradio demo)

This ensures we're using the exact same message structure as their
production demo, which should improve reliability and quality.

Reference: Official demo at https://huggingface.co/spaces/lightonai/LightOnOCR

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. lighton-ocr.py +3 -1
lighton-ocr.py CHANGED
@@ -137,11 +137,13 @@ def make_ocr_message(
137
  pil_img.save(buf, format="PNG")
138
  data_uri = f"data:image/png;base64,{base64.b64encode(buf.getvalue()).decode()}"
139
 
140
- # LightOnOCR uses simple message format (no explicit prompt text needed)
 
141
  return [
142
  {
143
  "role": "user",
144
  "content": [
 
145
  {"type": "image_url", "image_url": {"url": data_uri}},
146
  ],
147
  }
 
137
  pil_img.save(buf, format="PNG")
138
  data_uri = f"data:image/png;base64,{base64.b64encode(buf.getvalue()).decode()}"
139
 
140
+ # LightOnOCR uses message format with empty text prompt before image
141
+ # (matching official demo: text first, then image)
142
  return [
143
  {
144
  "role": "user",
145
  "content": [
146
+ {"type": "text", "text": ""},
147
  {"type": "image_url", "image_url": {"url": data_uri}},
148
  ],
149
  }