codeShare commited on
Commit
f586004
·
verified ·
1 Parent(s): 9dd943b

Delete colab_notebooks/🔓encrypt_kaggle_dataset.ipynb

Browse files
colab_notebooks/🔓encrypt_kaggle_dataset.ipynb DELETED
@@ -1 +0,0 @@
1
- {"cells":[{"cell_type":"code","source":["# 🔓 Session A , encrypt dataset\n","\n","# =============================================================================\n","#@markdown # **CELL 3A (Simplified)**: Encrypt → ZIP + config files to Drive folder\n","# =============================================================================\n","# This cell:\n","# • Reads your images.zip\n","# • Encrypts every image\n","# • Creates encrypted_dataset_for_kaggle.zip\n","# • Creates password.txt + config txt files\n","# • Puts ALL files in a folder in your Google Drive\n","\n","from google.colab import drive\n","import os\n","import shutil\n","import zipfile\n","import glob\n","from PIL import Image\n","import io\n","import hashlib\n","\n","!pip install -q pynacl\n","\n","from nacl.secret import SecretBox\n","from nacl.utils import random\n","\n","# Mount Drive\n","drive.mount('/content/drive', force_remount=True)\n","\n","# =============================================================================\n","#@markdown ### 🔧 Settings\n","# =============================================================================\n","input_zip_path = '/content/drive/MyDrive/images.zip' #@param {type:\"string\"}\n","encryption_password = \"banana\" #@param {type:\"string\"}\n","\n","output_drive_base_path = \"/content/drive/MyDrive/\" #@param {type:\"string\"}\n","output_folder_name = \"encrypted_dataset_for_kaggle\" #@param {type:\"string\"}\n","\n","# Additional config values\n","MODEL_ID = \"codeShare/FLUX.2-klein-AIO-SDNQ-4bit-dynamic\" #@param {type:\"string\"}\n","edit_prompt = \"improve this illustration. fine art color contrast with pleasant quality. the background is dark gray.\" #@param {type:\"string\"}\n","resolution = \"1024 x 1024 (Square)\" #@param {type:\"string\"}\n","\n","# =============================================================================\n","# ===== KEY DERIVATION =====\n","# =============================================================================\n","def derive_key(password):\n"," return hashlib.sha256(password.encode()).digest()\n","\n","SECRET_KEY = derive_key(encryption_password)\n","box = SecretBox(SECRET_KEY)\n","\n","# =============================================================================\n","# ===== IMAGE → BYTES =====\n","# =============================================================================\n","def pil_to_bytes(img):\n"," buf = io.BytesIO()\n"," img.save(buf, format=\"JPEG\", quality=95)\n"," return buf.getvalue()\n","\n","# =============================================================================\n","# ===== ENCRYPT =====\n","# =============================================================================\n","def encrypt_bytes(data):\n"," nonce = random(SecretBox.NONCE_SIZE)\n"," return box.encrypt(data, nonce)\n","\n","# =============================================================================\n","# ====================== LOAD & ENCRYPT ======================\n","# =============================================================================\n","print(\"📦 Extracting images...\")\n","input_images_dir = '/content/input_images'\n","\n","if os.path.exists(input_images_dir):\n"," shutil.rmtree(input_images_dir)\n","os.makedirs(input_images_dir, exist_ok=True)\n","\n","with zipfile.ZipFile(input_zip_path, 'r') as z:\n"," z.extractall(input_images_dir)\n","\n","image_files = sorted(glob.glob(os.path.join(input_images_dir, '*.*')))\n","image_files = [f for f in image_files if f.lower().endswith(('.png','.jpg','.jpeg','.webp','.gif'))]\n","\n","print(f\"✅ Found {len(image_files)} images to encrypt.\")\n","\n","encrypted_image_data_for_zip = []\n","\n","for img_path in image_files:\n"," img = Image.open(img_path).convert(\"RGB\")\n"," img_bytes = pil_to_bytes(img)\n"," enc_msg = encrypt_bytes(img_bytes)\n"," encrypted_image_data_for_zip.append((os.path.basename(img_path), enc_msg))\n","\n","print(f\"🔐 Encrypted {len(encrypted_image_data_for_zip)} images.\")\n","\n","# =============================================================================\n","# ====================== CREATE OUTPUT FOLDER ======================\n","# =============================================================================\n","output_drive_full_path = os.path.join(output_drive_base_path, output_folder_name)\n","os.makedirs(output_drive_full_path, exist_ok=True)\n","\n","print(f\"📁 Output folder created: {output_drive_full_path}\")\n","\n","# =============================================================================\n","# ====================== SAVE ENCRYPTED ZIP ======================\n","# =============================================================================\n","print(\"\\n💾 Creating encrypted_dataset_for_kaggle.zip ...\")\n","\n","temp_zip = \"/content/temp_encrypted.zip\"\n","\n","with zipfile.ZipFile(temp_zip, 'w') as ez:\n"," for original_fname, enc_msg in encrypted_image_data_for_zip:\n"," encrypted_filename = f\"{os.path.splitext(original_fname)[0]}_encrypted.bin\"\n"," combined_bytes = enc_msg.nonce + enc_msg.ciphertext\n"," ez.writestr(encrypted_filename, combined_bytes)\n","\n","final_zip_path = os.path.join(output_drive_full_path, \"encrypted_dataset_for_kaggle.zip\")\n","shutil.move(temp_zip, final_zip_path)\n","\n","print(f\"✅ Saved: {final_zip_path}\")\n","\n","# =============================================================================\n","# ====================== SAVE CONFIG FILES ======================\n","# =============================================================================\n","print(\"\\n📝 Saving config files...\")\n","\n","password_txt_path = os.path.join(output_drive_full_path, \"password.txt\")\n","model_id_path = os.path.join(output_drive_full_path, \"model_id.txt\")\n","edit_prompt_path = os.path.join(output_drive_full_path, \"edit_prompt.txt\")\n","resolution_path = os.path.join(output_drive_full_path, \"resolution.txt\")\n","\n","# Write files\n","with open(password_txt_path, 'w', encoding='utf-8') as f:\n"," f.write(encryption_password)\n","\n","with open(model_id_path, 'w', encoding='utf-8') as f:\n"," f.write(MODEL_ID)\n","\n","with open(edit_prompt_path, 'w', encoding='utf-8') as f:\n"," f.write(edit_prompt)\n","\n","with open(resolution_path, 'w', encoding='utf-8') as f:\n"," f.write(resolution)\n","\n","print(f\"🔑 Saved: {password_txt_path}\")\n","print(f\"🧠 Saved: {model_id_path}\")\n","print(f\"🎨 Saved: {edit_prompt_path}\")\n","print(f\"📐 Saved: {resolution_path}\")\n","\n","# =============================================================================\n","# ====================== CLEANUP ======================\n","# =============================================================================\n","if os.path.exists(input_images_dir):\n"," shutil.rmtree(input_images_dir)\n","\n","# =============================================================================\n","# ====================== DONE ======================\n","# =============================================================================\n","print(\"\\n🎉 DONE! Files saved to Google Drive:\")\n","print(f\" 📂 {output_drive_full_path}/\")\n","print(f\" • encrypted_dataset_for_kaggle.zip\")\n","print(f\" • password.txt\")\n","print(f\" • model_id.txt\")\n","print(f\" • edit_prompt.txt\")\n","print(f\" • resolution.txt\")"],"metadata":{"id":"9XzM6NLc6BWo"},"execution_count":null,"outputs":[]}],"metadata":{"colab":{"provenance":[{"file_id":"https://huggingface.co/codeShare/FLUX.2-klein-AIO-SDNQ-4bit-dynamic/blob/main/colab_notebooks/🔓encrypt_kaggle_dataset.ipynb","timestamp":1777245195151},{"file_id":"https://huggingface.co/codeShare/FLUX.2-klein-AIO-SDNQ-4bit-dynamic/blob/main/colab_notebooks/🔓encrypt_kaggle_dataset.ipynb","timestamp":1777241978499},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/enc_run_klein_edit_aio.ipynb","timestamp":1777237782988},{"file_id":"https://huggingface.co/codeShare/FLUX.2-klein-AIO-SDNQ-4bit-dynamic/blob/main/run_klein_edit_aio.ipynb","timestamp":1777129973676},{"file_id":"https://huggingface.co/codeShare/FLUX.2-klein-AIO-SDNQ-4bit-dynamic/blob/main/notebooks/klein_edit_aio.ipynb","timestamp":1777127335701},{"file_id":"https://huggingface.co/codeShare/FLUX.2-klein-AIO-SDNQ-4bit-dynamic/blob/main/notebooks/klein_edit_aio.ipynb","timestamp":1776991571771},{"file_id":"https://huggingface.co/codeShare/FLUX.2-klein-AIO-SDNQ-4bit-dynamic/blob/main/notebooks/klein_edit_aio.ipynb","timestamp":1776952244463},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/klein_prepare_lora_set.ipynb","timestamp":1776905776793},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/klein_prepare_lora_set.ipynb","timestamp":1776904822796},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/klein_prepare_lora_set.ipynb","timestamp":1776896778295},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/klein_prepare_lora_set.ipynb","timestamp":1776814708184},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/klein_prepare_lora_set.ipynb","timestamp":1776796861814},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/klein_prepare_lora_set.ipynb","timestamp":1776795061697},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/klein_prepare_lora_set.ipynb","timestamp":1776794307247},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/klein_prepare_lora_set.ipynb","timestamp":1776790556621},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/klein_prepare_lora_set.ipynb","timestamp":1776789720072},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/klein_prepare_lora_set.ipynb","timestamp":1776787634021},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/klein_prepare_lora_set.ipynb","timestamp":1776773678064},{"file_id":"151XI3nRFxLRbwRc8V6OfWyqp-zTnfySv","timestamp":1776764241991},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/klein_edit.ipynb","timestamp":1776702729526},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/vertical_slice_prepper.ipynb","timestamp":1776687886662},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/vertical_slice_prepper.ipynb","timestamp":1776366149549},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/lora_vertical_slice_dataset_creator.ipynb","timestamp":1776287741995},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/lora_vertical_slice_dataset_creator.ipynb","timestamp":1776178739426},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/lora_vertical_slice_dataset_creator.ipynb","timestamp":1776027716448},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/lora_vertical_slice_dataset_creator.ipynb","timestamp":1773663661932},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/civit_caption_prepper.ipynb","timestamp":1773663290922},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/civit_caption_prepper.ipynb","timestamp":1773264797996},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/civit_caption_prepper.ipynb","timestamp":1773163850245},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/civit_caption_prepper.ipynb","timestamp":1773090196076},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/civit_caption_prepper.ipynb","timestamp":1773089575687},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/civit_caption_prepper.ipynb","timestamp":1773080355474},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/Drive to WebP.ipynb","timestamp":1772998638620},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/Drive to WebP.ipynb","timestamp":1763646205520},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/Drive to WebP.ipynb","timestamp":1760993725927},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1760450712160},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1756712618300},{"file_id":"https://huggingface.co/codeShare/JupyterNotebooks/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1747490904984},{"file_id":"https://huggingface.co/codeShare/JupyterNotebooks/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1740037333374},{"file_id":"https://huggingface.co/codeShare/JupyterNotebooks/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1736477078136},{"file_id":"https://huggingface.co/codeShare/JupyterNotebooks/blob/main/YT-playlist-to-mp3.ipynb","timestamp":1725365086834}]},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0}