<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def pdf_preprocess(pdf, batch=False):
 """ Load pdfs from local filepath if not already b64 encoded """

    if batch:
        return [pdf_preprocess(doc, batch=False) for doc in pdf]

    if os.path.isfile(pdf):
        # a filepath is provided, read and encode
        return b64encode(open(pdf, 'rb').read())
    else:
        # assume pdf is already b64 encoded
        return pdf