Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: category and export files by rank #143

Open
112292454 opened this issue Apr 21, 2023 · 2 comments
Open

Feature request: category and export files by rank #143

112292454 opened this issue Apr 21, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@112292454
Copy link

Since we have already done the function of manually adding rank tags, why not provide a way to classify and export them through rank (locally moving files may be sufficient, like six folder/zip, mapped each ranks).This feature may seem relatively simple, but I don't know how to organize/obtain rank information through wib.sqlite3——and the code is a bit heavy

BTW, I found that marking on the t2i interface and moving it to the save folder did not take effect. It doesn't seem like https://github.com/tsngo/stable-diffusion-webui-aesthetic-image-scorer is written in the file itself, but through the plugin's database. Should we include rank information when moving files?

@AlUlkesh AlUlkesh added the enhancement New feature or request label Apr 21, 2023
@Gukigit
Copy link

Gukigit commented May 15, 2023

Yes, this will be very useful. I spent a day ranking thousands of images and found it impossible to export them in bulk

@Moahmmed1900
Copy link

I've made a quick python script just for the time being.
First, you need to make a copy of the database to new folder. (database found in "extensions/stable-diffusion-webui-images browser/wib.sqlite3")

Then in the new folder, make a new python file "main.py" and paste the below:

import sqlite3
from zipfile import ZipFile
from datetime import datetime
import os

MIN_RANK = 3
MAX_RANK = 4

CATEGORY = "txt2img-images" # txt2img-images, img2img-images, extras-images

def main():
    connection = sqlite3.connect("wib.sqlite3")

    cursor = connection.cursor()

    results = cursor.execute(f"SELECT file, ranking FROM ranking WHERE ranking.ranking <= {MAX_RANK} AND ranking.ranking >= {MIN_RANK};")

    results = results.fetchall()

    to_be_ziped_images = []

    print("Following images will be zipped: ")
    counter = 1
    for image in results:
        if CATEGORY in str(image[0]):
            print(f'{counter}: {image[0]}')
            to_be_ziped_images.append(image[0])
            counter = counter + 1

    if len(to_be_ziped_images) > 0:
        with ZipFile(f'bulk_extract_{datetime.now().strftime("%Y_%m_%d_%H_%M_%S")}.zip', 'w') as zip:
            for image in to_be_ziped_images:
                zip.write(filename=image, arcname=os.path.basename(image))

        print('All images zipped successfully!')
    else:
        print("No images to be extracted")

if __name__ == "__main__":
    main()

Lastly, modify the variables (MIN_RANK, MAX_RANK, CATEGORY) to your needs.

Then just run the script ("python main.py"), it will print the list of image that it found with your criteria, then a new zip file will be created with the images.

Final notes,
1- The script was tested on automatic1111.
2- The script was ran on the same system the WebUI was running on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants