{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "db06489e-2e2e-4d7f-bfab-13cf42261688", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "im here\n" ] } ], "source": [ "print('im here')\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "9217fed7-ed85-4592-a480-ef15f0632501", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/jupyter\n" ] } ], "source": [ "cd .." ] }, { "cell_type": "code", "execution_count": 6, "id": "502b64af-59f1-4ae9-89f3-378458ba52be", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "replacing old file\n", "Untitled.ipynb\n", "README.md\n", "config.properties\n", ".gitattributes\n", "model_index.json\n", "Untitled1.ipynb\n", "Dockerfile\n", "stable_diffusion_handler.py\n", "replacing stable_diffusion_handler.py\n", "tokenizer_2/tokenizer_config.json\n", "tokenizer_2/special_tokens_map.json\n", "tokenizer_2/vocab.json\n", "tokenizer_2/merges.txt\n", "text_encoder/config.json\n", "text_encoder/pytorch_model.bin\n", "text_encoder_2/config.json\n", "text_encoder_2/pytorch_model.bin\n", "unet/config.json\n", "unet/diffusion_pytorch_model.bin\n", "tokenizer/tokenizer_config.json\n", "tokenizer/special_tokens_map.json\n", "tokenizer/vocab.json\n", "tokenizer/merges.txt\n", "scheduler/scheduler_config.json\n", "vae/config.json\n", "vae/diffusion_pytorch_model.bin\n", "MAR-INF/MANIFEST.json\n" ] } ], "source": [ "import zipfile\n", "\n", "# Path to the existing .mar file and the file to be replaced\n", "mar_path = \"export/sketch-model-3.mar\"\n", "file_to_replace = \"stable_diffusion_handler.py\"\n", "new_file_path = \"sketch-model-3/stable_diffusion_handler.py\"\n", "\n", "# # Create a temporary .mar file\n", "temp_mar_path = \"sketch-model-3-updated.mar\"\n", "\n", "print(\"replacing old file\")\n", "# Open the existing .mar and the temporary .mar\n", "with zipfile.ZipFile(mar_path, 'r') as zip_ref, zipfile.ZipFile(temp_mar_path, 'w', zipfile.ZIP_STORED) as new_zip:\n", " # Loop through existing files\n", " for item in zip_ref.infolist():\n", " print(item.filename)\n", " buffer = zip_ref.read(item.filename)\n", " \n", " # Replace the file if it matches the target file name\n", " if item.filename == file_to_replace:\n", " print('replacing ', item.filename)\n", " with open(new_file_path, \"rb\") as f:\n", " new_buffer = f.read()\n", " new_zip.writestr(item, new_buffer)\n", " else:\n", " new_zip.writestr(item, buffer)\n", "\n", "print('done')\n", "# Remove the original .mar file and replace it with the new one\n", "import os\n", "os.remove(mar_path)\n", "os.rename(temp_mar_path, mar_path)" ] } ], "metadata": { "environment": { "kernel": "conda-root-py", "name": "workbench-notebooks.m110", "type": "gcloud", "uri": "gcr.io/deeplearning-platform-release/workbench-notebooks:m110" }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "conda-root-py" }, "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.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }