ta4tsering commited on
Commit
15c943a
·
1 Parent(s): 0ea2759

fix: update DotsVLProcessor class to handle processor attributes and adjust model loading requirements

Browse files
Files changed (2) hide show
  1. app.py +24 -12
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
  import sys
 
3
  import torch
4
  import gradio as gr
5
  from PIL import Image
@@ -24,22 +25,32 @@ def patch_configuration_dots(model_path: str) -> None:
24
  if not os.path.exists(config_path):
25
  return
26
 
27
- with open(config_path, "r") as f:
28
  source = f.read()
29
 
30
- if 'attributes = ["image_processor", "tokenizer"]' in source:
31
- return # already patched
32
-
33
- patched = source.replace(
34
- "class DotsVLProcessor(Qwen2_5_VLProcessor):\n"
35
- " def __init__(self, image_processor=None, tokenizer=None, chat_template=None, **kwargs):",
36
-
37
- "class DotsVLProcessor(Qwen2_5_VLProcessor):\n"
38
- ' attributes = ["image_processor", "tokenizer"]\n'
39
- " def __init__(self, image_processor=None, tokenizer=None, video_processor=None, chat_template=None, **kwargs):",
 
 
 
 
 
 
40
  )
41
 
42
- with open(config_path, "w") as f:
 
 
 
 
43
  f.write(patched)
44
 
45
 
@@ -73,6 +84,7 @@ def load_model():
73
  processor = AutoProcessor.from_pretrained(
74
  model_path,
75
  trust_remote_code=True,
 
76
  )
77
 
78
  return model, processor
 
1
  import os
2
  import sys
3
+ import re
4
  import torch
5
  import gradio as gr
6
  from PIL import Image
 
25
  if not os.path.exists(config_path):
26
  return
27
 
28
+ with open(config_path, "r", encoding="utf-8") as f:
29
  source = f.read()
30
 
31
+ patched = source
32
+
33
+ # Force processor mixin to treat dots.ocr as image+tokenizer only.
34
+ # This avoids newer transformers requiring BaseVideoProcessor.
35
+ if 'attributes = ["image_processor", "tokenizer"]' not in patched:
36
+ patched = re.sub(
37
+ r"(class\s+DotsVLProcessor\(Qwen2_5_VLProcessor\):\n)",
38
+ r'\1 attributes = ["image_processor", "tokenizer"]\n',
39
+ patched,
40
+ count=1,
41
+ )
42
+
43
+ # Handle both older and newer remote class signatures.
44
+ patched = patched.replace(
45
+ "def __init__(self, image_processor=None, tokenizer=None, chat_template=None, **kwargs):",
46
+ "def __init__(self, image_processor=None, tokenizer=None, video_processor=None, chat_template=None, **kwargs):",
47
  )
48
 
49
+ if patched == source:
50
+ print("No dots.ocr processor patch changes were required.")
51
+ return
52
+
53
+ with open(config_path, "w", encoding="utf-8") as f:
54
  f.write(patched)
55
 
56
 
 
84
  processor = AutoProcessor.from_pretrained(
85
  model_path,
86
  trust_remote_code=True,
87
+ use_fast=False,
88
  )
89
 
90
  return model, processor
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- transformers>=4.57.0
2
  torch>=2.4.0
3
  torchvision>=0.19.0
4
  Pillow>=10.0.0
 
1
+ transformers==4.56.2
2
  torch>=2.4.0
3
  torchvision>=0.19.0
4
  Pillow>=10.0.0