fix read write tmpfile on windows by Blaxzter · Pull Request #323 · Unstructured-IO/unstructured-inference

And wound it defeat the purpose of a temp file to leave it on device after things have been done with it?
I guess you could do something like this if you dont want to use a temp folder

def process_data_with_model(
    data: BinaryIO,
    model_name: Optional[str],
    **kwargs,
) -> DocumentLayout:
    """Processes pdf file in the form of a file handler (supporting a read method) into a
    DocumentLayout by using a model identified by model_name."""
    file_name = ''
    with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
        tmp_file.write(data.read())
        tmp_file.flush()  # Make sure the file is written out
        file_name = tmp_file.name
        
    try:
        layout = process_file_with_model(
            file_name,
            model_name,
            **kwargs,
        )
    finally:
        os.remove(file_name)

    return layout