File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed
unstructured_inference/inference Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change 99import pdf2image
1010from PIL import Image , ImageSequence
1111
12- from unstructured_inference .inference .elements import (
13- TextRegion ,
14- )
15- from unstructured_inference .inference .layoutelement import (
16- LayoutElement ,
17- )
12+ from unstructured_inference .inference .elements import TextRegion
13+ from unstructured_inference .inference .layoutelement import LayoutElement
1814from unstructured_inference .logger import logger
1915from unstructured_inference .models .base import get_model
2016from unstructured_inference .models .unstructuredmodel import (
@@ -327,14 +323,21 @@ def process_data_with_model(
327323) -> DocumentLayout :
328324 """Processes pdf file in the form of a file handler (supporting a read method) into a
329325 DocumentLayout by using a model identified by model_name."""
330- with tempfile .NamedTemporaryFile () as tmp_file :
326+
327+ # Create a named temporary file without automatic deletion
328+ with tempfile .NamedTemporaryFile (delete = False , mode = "w+b" ) as tmp_file :
329+ tmp_filename = tmp_file .name
331330 tmp_file .write (data .read ())
332331 tmp_file .flush () # Make sure the file is written out
332+
333+ try :
333334 layout = process_file_with_model (
334- tmp_file . name ,
335+ tmp_filename ,
335336 model_name ,
336337 ** kwargs ,
337338 )
339+ finally :
340+ os .remove (tmp_filename )
338341
339342 return layout
340343
You can’t perform that action at this time.
0 commit comments