Sign In

Search prompt: "png_jpg_Source_code_inspector" - Google Colab

Search prompt: "png_jpg_Source_code_inspector" - Google Colab

The program essentially copies the source code of the images, filtering out unwanted characters, thus allowing you to obtain prompts from the images easily and quickly, without using other tools. The program only allows viewing the source code, so you can see the tags only if they were saved in the image at the time of its creation, just like Civitai does.

Now you can upload multiple files at once, and the program displays the progress in a more interesting way.


import re
from google.colab import files
#@markdown Just click, no need to connect to Google Drive. When executing the code, you will be given the option to upload images. You can upload as many as you want, and as they are uploaded to the execution environment, the images will be processed.
#@markdown
#@markdown The Limit parameter is used to speed up the code and avoid showing too much irrelevant content. Adjust it based on the number of tags you need to see, between 500 and 4000. You'll be able to see an image with more than 40 tags, so it's exaggerating to set it too high.
import ipywidgets as widgets

def remove_invalid_characters(text):
    cleaned_text = re.sub(r'[^a-zA-Z0-9,:<> ]', '', text)
    return cleaned_text

def extract_first_500_bytes(image_bytes):
    Limit = 700 #@param {type:"slider", min:500, max:25000, step:100}
    first_500_bytes = image_bytes[:Limit]  # Limit to the first 500 bytes
    try:
        text_without_characters = remove_invalid_characters(first_500_bytes.decode('utf-8'))
    except UnicodeDecodeError:
        text_without_characters = remove_invalid_characters(first_500_bytes.decode('latin-1'))
    return text_without_characters

# Function to upload files to Colab
def upload_files():
    files_uploaded = files.upload()
    return files_uploaded

# Main code
uploaded_files = upload_files()
for file_name, file_content in uploaded_files.items():
    image_bytes = file_content
    text_without_characters = extract_first_500_bytes(image_bytes)
    print(f"Text without invalid characters in {file_name}:")
    print(text_without_characters)

Open in the Cat

Open in Colab

0

Comments