File tree 1 file changed +11
-8
lines changed
unstructured_inference/inference
1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change 9
9
import pdf2image
10
10
from PIL import Image , ImageSequence
11
11
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
18
14
from unstructured_inference .logger import logger
19
15
from unstructured_inference .models .base import get_model
20
16
from unstructured_inference .models .unstructuredmodel import (
@@ -327,14 +323,21 @@ def process_data_with_model(
327
323
) -> DocumentLayout :
328
324
"""Processes pdf file in the form of a file handler (supporting a read method) into a
329
325
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 ) as tmp_file :
329
+ tmp_filename = tmp_file .name
331
330
tmp_file .write (data .read ())
332
331
tmp_file .flush () # Make sure the file is written out
332
+
333
+ try :
333
334
layout = process_file_with_model (
334
- tmp_file . name ,
335
+ tmp_filename ,
335
336
model_name ,
336
337
** kwargs ,
337
338
)
339
+ finally :
340
+ os .remove (tmp_filename )
338
341
339
342
return layout
340
343
You can’t perform that action at this time.
0 commit comments