{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/tag_randomizer.ipynb","timestamp":1758655941612},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/tag_randomizer.ipynb","timestamp":1756665629195},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/tag_randomizer.ipynb","timestamp":1756583352986},{"file_id":"https://huggingface.co/datasets/codeShare/lora-training-data/blob/main/tag_randomizer.ipynb","timestamp":1756465686090}],"authorship_tag":"ABX9TyM6ZobxKmtJHV7qktFB4zbd"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","source":["import os\n","import random\n","import string\n","from google.colab import files\n","\n","# Create output directory if it doesn't exist\n","output_dir = '/content/output/'\n","os.makedirs(output_dir, exist_ok=True)\n","\n","# Upload text files\n","print(\"Please upload your text files:\")\n","uploaded = files.upload()\n","\n","# Process uploaded files\n","all_items = []\n","for filename, content in uploaded.items():\n"," if filename.endswith('.txt'):\n"," # Decode content and treat entire file content as one item, removing trailing whitespace\n"," file_content = content.decode('utf-8').rstrip()\n"," if file_content: # Only add non-empty content\n"," # Replace newlines with empty string\n"," file_content = file_content.replace('\\n', ' ')\n"," # Replace double quotes with single quotes\n"," file_content = file_content.replace('\"', \"'\")\n"," # Remove specified symbols: {}, [], ^\n"," for symbol in '{}[]^':\n"," file_content = file_content.replace(symbol, '')\n"," all_items.append(file_content)\n","\n","# Join items with '|' separator\n","combined_text = '|'.join(all_items)\n","\n","# Generate random filename (e.g., 8 characters long)\n","random_filename = ''.join(random.choices(string.ascii_lowercase + string.digits, k=8)) + '.txt'\n","output_path = os.path.join(output_dir, random_filename)\n","\n","# Write combined text to output file\n","with open(output_path, 'w') as f:\n"," f.write(combined_text)\n","\n","print(f\"Combined text saved to: {output_path}\")\n","print(f\"Content: {combined_text}\")\n","\n","# Optional: Display the output file content\n","with open(output_path, 'r') as f:\n"," print(f\"Verified content from file: {f.read()}\")"],"metadata":{"id":"rIBdbHYDhKvE"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# Import required library\n","import random\n","\n","# Input text\n","input_text = 'A,B,C|D,E,F|G,H,I' #@param {type:'string'}\n","\n","# Split the text into groups\n","groups = input_text.split('|')\n","\n","# Randomize letters within each group\n","randomized_groups = []\n","for group in groups:\n"," letters = group.split(',')\n"," random.shuffle(letters)\n"," randomized_groups.append(','.join(letters))\n","\n","# Join the groups back together\n","output_text = '|'.join(randomized_groups)\n","\n","# Write to a text file\n","with open('randomized_output.txt', 'w') as file:\n"," file.write(output_text)\n","\n","# Print the result to verify\n","print(\"Randomized output:\", output_text)\n","\n","# Download the file in Colab\n","from google.colab import files\n","files.download('randomized_output.txt')"],"metadata":{"id":"XifDdzLoC-P2"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# Install required libraries\n","!pip install pdf2image\n","!apt-get install poppler-utils\n","\n","from pdf2image import convert_from_path\n","from google.colab import files\n","import os\n","import zipfile\n","from datetime import datetime\n","\n","# Create output directory\n","output_dir = \"converted_pngs\"\n","if not os.path.exists(output_dir):\n"," os.makedirs(output_dir)\n","\n","# Upload PDF files\n","print(\"Please upload your PDF files:\")\n","uploaded = files.upload()\n","\n","# Convert PDFs to PNGs\n","for pdf_file in uploaded.keys():\n"," if pdf_file.lower().endswith('.pdf'):\n"," print(f\"Converting {pdf_file}...\")\n"," # Convert PDF to images with high quality (300 DPI)\n"," images = convert_from_path(pdf_file, dpi=300, fmt='png')\n","\n"," # Save each page as PNG\n"," pdf_name = os.path.splitext(pdf_file)[0]\n"," for i, image in enumerate(images):\n"," output_path = os.path.join(output_dir, f\"{pdf_name}_page_{i+1}.png\")\n"," image.save(output_path, 'PNG', quality=100)\n"," print(f\"Finished converting {pdf_file}\")\n","\n","# Create zip file\n","timestamp = datetime.now().strftime(\"%Y%m%d_%H%M%S\")\n","zip_filename = f\"converted_pngs_{timestamp}.zip\"\n","with zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED) as zipf:\n"," for root, _, files_to_zip in os.walk(output_dir):\n"," for file_to_zip in files_to_zip:\n"," if file_to_zip.endswith('.png'):\n"," zipf.write(os.path.join(root, file_to_zip),\n"," os.path.join(\"converted_pngs\", file_to_zip))\n","\n","# Download the zip file\n","files.download(zip_filename)\n","\n","print(f\"All PNGs have been saved to {zip_filename} and download initiated.\")"],"metadata":{"id":"dUzHKM75ACOu","outputId":"a6276f7b-aa60-46e6-8c7c-cf30acaa4331","colab":{"base_uri":"https://localhost:8080/","height":491}},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Collecting pdf2image\n"," Downloading pdf2image-1.17.0-py3-none-any.whl.metadata (6.2 kB)\n","Requirement already satisfied: pillow in /usr/local/lib/python3.12/dist-packages (from pdf2image) (11.3.0)\n","Downloading pdf2image-1.17.0-py3-none-any.whl (11 kB)\n","Installing collected packages: pdf2image\n","Successfully installed pdf2image-1.17.0\n","Reading package lists... Done\n","Building dependency tree... Done\n","Reading state information... Done\n","The following NEW packages will be installed:\n"," poppler-utils\n","0 upgraded, 1 newly installed, 0 to remove and 38 not upgraded.\n","Need to get 186 kB of archives.\n","After this operation, 697 kB of additional disk space will be used.\n","Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 poppler-utils amd64 22.02.0-2ubuntu0.10 [186 kB]\n","Fetched 186 kB in 0s (1,139 kB/s)\n","Selecting previously unselected package poppler-utils.\n","(Reading database ... 126441 files and directories currently installed.)\n","Preparing to unpack .../poppler-utils_22.02.0-2ubuntu0.10_amd64.deb ...\n","Unpacking poppler-utils (22.02.0-2ubuntu0.10) ...\n","Setting up poppler-utils (22.02.0-2ubuntu0.10) ...\n","Processing triggers for man-db (2.10.2-1) ...\n","Please upload your PDF files:\n"]},{"output_type":"display_data","data":{"text/plain":[""],"text/html":["\n"," \n"," \n"," Upload widget is only available when the cell has been executed in the\n"," current browser session. Please rerun this cell to enable.\n"," \n"," "]},"metadata":{}}]}]}