Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backend/ocr_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ def extract_text_from_mlx_output(generated):


GROUNDING_TOKEN_PATTERN = re.compile(
r'<\|ref\|>([^<]*)<\|/ref\|><\|det\|>\[\[([^\]]+)\]\]<\|/det\|>',
re.MULTILINE
r'<\|ref\|>(.*?)<\|/ref\|><\|det\|>\s*(\[\[.*?\]\])\s*<\|/det\|>',
re.DOTALL
)


Expand Down Expand Up @@ -1210,7 +1210,7 @@ def get_env_flag(name, default=False):
PDF_EVAL_MODE = get_env_flag('DEEPSEEK_OCR_PDF_EVAL_MODE', True)
PDF_MAX_NEW_TOKENS = max(
128,
int(os.environ.get('DEEPSEEK_OCR_PDF_MAX_NEW_TOKENS', '384' if PREFERRED_DEVICE_HINT == 'mps' else '1024'))
int(os.environ.get('DEEPSEEK_OCR_PDF_MAX_NEW_TOKENS', '1024'))
)

DEFAULT_MAX_NEW_TOKENS_MPS = max(256, int(os.environ.get('DEEPSEEK_OCR_MAX_NEW_TOKENS_MPS', '768')))
Expand Down
1 change: 1 addition & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ function getUvSetupEnv(paths) {
return {
...process.env,
UV_CACHE_DIR: paths.uvCacheDir,
UV_HTTP_TIMEOUT: process.env.UV_HTTP_TIMEOUT || '180',
PIP_CACHE_DIR: paths.pipCacheDir
};
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deepseek-ocr-client",
"version": "2.0.0",
"version": "2.0.1",
"description": "Electron GUI for DeepSeek-OCR-2",
"main": "main.js",
"scripts": {
Expand Down
39 changes: 39 additions & 0 deletions scripts/test-backend-helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
"""Focused regression tests for backend helper behavior."""

import unittest
from pathlib import Path
import sys

PROJECT_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(PROJECT_ROOT))

from backend import ocr_server


MULTI_BOX_TOKEN_TEXT = (
"Before\n"
"<|ref|>Important Safeguards<|/ref|>"
"<|det|>[[78, 321, 465, 349], [532, 134, 888, 172]]<|/det|>\n"
"After"
)


class MlxOutputNormalizationTests(unittest.TestCase):
def test_document_output_strips_grounding_tokens_with_multiple_boxes(self):
cleaned, raw_tokens = ocr_server.normalize_mlx_output("document", MULTI_BOX_TOKEN_TEXT)

self.assertEqual(raw_tokens, MULTI_BOX_TOKEN_TEXT)
self.assertEqual(cleaned, "Before\n\nAfter")
self.assertNotIn("<|ref|>", cleaned)
self.assertNotIn("<|det|>", cleaned)

def test_ocr_output_extracts_ref_text_from_multiple_box_grounding_token(self):
cleaned, raw_tokens = ocr_server.normalize_mlx_output("ocr", MULTI_BOX_TOKEN_TEXT)

self.assertEqual(raw_tokens, MULTI_BOX_TOKEN_TEXT)
self.assertEqual(cleaned, "Important Safeguards")


if __name__ == "__main__":
unittest.main()
Loading