importbase64importpandasaspdfromioimportBytesIOfromPILimportImagedefimage_to_base64(image:Image)->str:img_bytes=BytesIO()image.save(img_bytes,'jpeg',quality=90)image_base64=base64.b64encode(img_bytes.getvalue()).decode('utf-8')returnimage_base64# let's build a CSV with a single row that contains an image# the same general approach works if you have multiple image rows or columnsimage=Image.open('cat.jpg')image_base64=image_to_base64(image)df=pd.DataFrame({'animal_image':[image_base64]})df.to_csv('prediction_dataset.csv'index=False)print(df)