File size: 3,904 Bytes
ba99fa4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
{
"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
}
|