sparrow-parse 1.0.7__py3-none-any.whl → 1.0.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sparrow_parse/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = '1.0.7'
1
+ __version__ = '1.0.8'
@@ -75,7 +75,6 @@ class MLXInference(ModelInference):
75
75
  print(f"Failed to parse JSON: {e}")
76
76
  return output_text
77
77
 
78
-
79
78
  def load_image_data(self, image_filepath, max_width=1250, max_height=1750):
80
79
  """
81
80
  Load and resize image while maintaining its aspect ratio.
@@ -155,7 +154,8 @@ class MLXInference(ModelInference):
155
154
  def _process_images(self, model, processor, config, file_paths, input_data, apply_annotation):
156
155
  """
157
156
  Process images and generate responses for each.
158
-
157
+ If apply_annotation=True, don't resize to maintain accurate coordinates.
158
+
159
159
  :param model: The loaded model
160
160
  :param processor: The loaded processor
161
161
  :param config: Model configuration
@@ -166,28 +166,54 @@ class MLXInference(ModelInference):
166
166
  """
167
167
  results = []
168
168
  for file_path in file_paths:
169
- image, width, height = self.load_image_data(file_path)
170
-
169
+ # Load image differently based on annotation requirement
170
+ if apply_annotation:
171
+ # For annotation, just load the image without resizing
172
+ image = load_image(file_path)
173
+ # We'll skip the resize_shape parameter when generating
174
+ else:
175
+ # For non-annotation cases, load with potential resizing
176
+ image, width, height = self.load_image_data(file_path)
177
+ # We'll use resize_shape when generating
178
+
171
179
  # Prepare messages based on model type
172
180
  messages = self._prepare_messages(input_data, apply_annotation)
173
-
181
+
174
182
  # Generate and process response
175
183
  prompt = apply_chat_template(processor, config, messages)
176
- response, _ = generate(
177
- model,
178
- processor,
179
- prompt,
180
- image,
181
- resize_shape=(width, height),
182
- max_tokens=4000,
183
- temperature=0.0,
184
- verbose=False
185
- )
186
- results.append(self.process_response(response))
184
+
185
+ if apply_annotation:
186
+ # When annotation is required, don't use resize_shape
187
+ # This preserves original coordinate system
188
+ response, _ = generate(
189
+ model,
190
+ processor,
191
+ prompt,
192
+ image,
193
+ max_tokens=4000,
194
+ temperature=0.0,
195
+ verbose=False
196
+ )
197
+ else:
198
+ # For non-annotation cases, use resize_shape for memory efficiency
199
+ response, _ = generate(
200
+ model,
201
+ processor,
202
+ prompt,
203
+ image,
204
+ resize_shape=(width, height),
205
+ max_tokens=4000,
206
+ temperature=0.0,
207
+ verbose=False
208
+ )
209
+
210
+ processed_response = self.process_response(response)
211
+ results.append(processed_response)
187
212
  print(f"Inference completed successfully for: {file_path}")
188
-
213
+
189
214
  return results
190
215
 
216
+
191
217
  def transform_query_with_bbox(self, text_input):
192
218
  """
193
219
  Transform JSON schema in text_input to include value, bbox, and confidence.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sparrow-parse
3
- Version: 1.0.7
3
+ Version: 1.0.8
4
4
  Summary: Sparrow Parse is a Python package (part of Sparrow) for parsing and extracting information from documents.
5
5
  Home-page: https://github.com/katanaml/sparrow/tree/main/sparrow-data/parse
6
6
  Author: Andrej Baranovskij
@@ -1,4 +1,4 @@
1
- sparrow_parse/__init__.py,sha256=GIukrVnl8Ykjex2rUbxdz2Ov1PRc_MomFmxwSzRJH9w,21
1
+ sparrow_parse/__init__.py,sha256=iCEPnhz-knfGRAO4Ep2uQaYf4xwhPIjjcgAcNjga8kc,21
2
2
  sparrow_parse/__main__.py,sha256=Xs1bpJV0n08KWOoQE34FBYn6EBXZA9HIYJKrE4ZdG78,153
3
3
  sparrow_parse/text_extraction.py,sha256=uhYVNK5Q2FZnw1Poa3JWjtN-aEL7cyKpvaltdn0m2II,8948
4
4
  sparrow_parse/extractors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -13,9 +13,9 @@ sparrow_parse/vllm/huggingface_inference.py,sha256=RqYmP-wh_cm_BZ271HbejnZe30S5E
13
13
  sparrow_parse/vllm/inference_base.py,sha256=AmWF1OUjJLxSEK_WCbcRpXHX3cKk8nPJJHha_X-9Gs4,844
14
14
  sparrow_parse/vllm/inference_factory.py,sha256=FTM65O-dW2WZchHOrNN7_Q3-FlVoAc65iSptuuUuClM,1166
15
15
  sparrow_parse/vllm/local_gpu_inference.py,sha256=SIyprv12fYawwfxgQ7ZOTM5WmMfQqhO_9vbereRpZdk,652
16
- sparrow_parse/vllm/mlx_inference.py,sha256=inQ5J2Bd3I9D0MFiRO1xuPWYzqtDRMUDZxrxrjYXcgI,11761
17
- sparrow_parse-1.0.7.dist-info/METADATA,sha256=h95SW5I1uLw-xwERtMgIoZKQxxNXhMfOj_hfVHSuX18,7229
18
- sparrow_parse-1.0.7.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
19
- sparrow_parse-1.0.7.dist-info/entry_points.txt,sha256=HV5nnQVtr2m-kn6hzY_ynp0zugNCcGovbmnfmQgOyhw,53
20
- sparrow_parse-1.0.7.dist-info/top_level.txt,sha256=n6b-WtT91zKLyCPZTP7wvne8v_yvIahcsz-4sX8I0rY,14
21
- sparrow_parse-1.0.7.dist-info/RECORD,,
16
+ sparrow_parse/vllm/mlx_inference.py,sha256=j4DWq6e_9iQSt7CmWuA7OD7RoXkCrxzCNq4UffBuaoQ,12882
17
+ sparrow_parse-1.0.8.dist-info/METADATA,sha256=clalm_6WpyInHCLH10dyMGX4dgJrPHIXwSU9ltSFZKM,7229
18
+ sparrow_parse-1.0.8.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
19
+ sparrow_parse-1.0.8.dist-info/entry_points.txt,sha256=HV5nnQVtr2m-kn6hzY_ynp0zugNCcGovbmnfmQgOyhw,53
20
+ sparrow_parse-1.0.8.dist-info/top_level.txt,sha256=n6b-WtT91zKLyCPZTP7wvne8v_yvIahcsz-4sX8I0rY,14
21
+ sparrow_parse-1.0.8.dist-info/RECORD,,