{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Caption files created successfully.\n"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n",
"\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n",
"\u001b[1;31mClick here for more info. \n",
"\u001b[1;31mView Jupyter log for further details."
]
}
],
"source": [
"from pathlib import Path\n",
"\n",
"def create_caption_file(directory):\n",
" for image_path in Path(directory).rglob('*'):\n",
" if image_path.suffix.lower() in ['.jpg', '.jpeg', '.png']:\n",
" caption_file = image_path.with_suffix('.caption')\n",
" if not caption_file.exists():\n",
" caption_file.touch()\n",
"\n",
"if __name__ == \"__main__\":\n",
" directory = r'E:\\training_dir_staging'\n",
" create_caption_file(directory)\n",
" print(\"Caption files created successfully.\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}