GithubHelp home page GithubHelp logo

speckly / sucorn Goto Github PK

View Code? Open in Web Editor NEW
2.0 4.0 1.0 696 KB

ML/DL Life Cycle utilities with support for BingImageCreator and Discord

License: Apache License 2.0

Python 100.00%
classification data-gathering deep-learning discord keras-tensorflow statistics supervised-learning

sucorn's Introduction

sucorn

pronounced as su-kon

A project to automate the creation of AI generated images using Dall-E 3 hosted on Bing Image Creator, and to classify which ones are good and which ones are bad, so that time spent during the ML/DL life cycle is reduced The goals of this project include

  • deprecated automatic collection of images using pyautogui,
  • automatic collection of images through the BingImageCreator reverse-engineered API
  • WIP automatic collection of images through stable diffusion's text2img, hopefully with automatic parameter tuning
  • Automatic collection of Microsoft Session cookies using WebDriver
  • Displaying these images on Discord for remote labelling
  • Labelling these images from both remote (Discord) and local (tkinter) for training
  • Using Discord for easy, persistent remote access of images
  • use pandas and matplotlib for displaying statistics locally and on Discord
  • WIP training of Keras classifier
  • WIP training of Stable Diffusion LoRA (LoRA not included in this repo)

Setup

Warning

There is no .exe file because I am a stupid smelly nerd

It is recommended that a venv is used as there are a lot of dependencies (50>)

python setup.py

Bot

Requires your bot token in .env, follow the setup guide

python sucorn.py

Data collection phase

Warning

Use this ethically, as this makes requests to BingImageCreator. Avoid using too many instances as it will result in executing a DoS attack on this host.

utilities/reverse_api/get_cookie.py

Load account names in the normal list in usernames.json and run this file. This will automatically get the session cookie for each account and store it into cookies.json. Credentials are taken from .env. The loaded list contains account names with the cookie acquired and stored

utilities/reverse_api/run.py || run_linux.py

[!INFO] Replaces all double quotation marks in prompt with single quotation marks in Linux, keyboard ctrl shift r does not work either

Creates n-number of instances that will use the reverse engineered API to generate images from imagedir/prompt.txt. n-number of instances depends on how many pairs are found in cookies.json If imagedir does not exist then utilities/reverse_api/prompt.txt will be used to create imagedir/prompt.txt

python run.py imagedir --delay 10 --max 20

Each instance here will have a cooldown of 10 seconds after downloading all images from the query before

Keys:

  • Tab: Brings the child processes to front
  • End: Terminates all child processes
  • Ctrl + Shift + R: Reloads prompt from utilities/reverse_api/new_prompt.txt. Currently unavailable
If it doesn't work

Try changing the parameters located in BingImageCreator.py TODO: instructions here

utilities/reverse_api/.env

WIP

GENERAL=your_password_here
speckly=your_password_here

utilities/automation.py

Warning

This feature is deprecated, use utilities/reverse_api

Makes use of pyautogui to automatically navigate the GUI, using mouse clicks and keyboard presses. The output is links pasted in a Discord channel. Run the Discord slash command /nuclear_cat copy=<copy channel>

Data preparation phase

features/sucorn_statistics.py

This is both a feature and utility, feature used for the /statistics slash command in Discord, utility can be used in the command line.

python sucorn_statistics.py

Providing no options will iterate through all subfolders in ./images

python sucorn_statistics.py --csv sample_statistics.csv --mode write

Writes these results out to a given csv file, ommitting the --mode flag will read the csv and display it using matplotlib

utilities/labelling.py

For supervised learning, we need to label the images

Warning

Do not run this with reverse_api/run.py, as there will be duplicate file names and overwriting will occur, will fix this later

labelling.py foldername

Ensure that foldername is a valid foldername in ./images The following keys will label the image by moving it into its subfolder

  • 0 for negative
  • 1 for positive
  • 2 for neutral
  • ESC to quit

remove later

py BingImageCreator.py --cookie-file test_cookie.txt --debug-file debug.log --prompt "an astronaut on the moon"

sucorn's People

Contributors

speckly avatar

Stargazers

 avatar  avatar

Watchers

Kostas Georgiou avatar  avatar  avatar  avatar

Forkers

djlpcopilot

sucorn's Issues

A whole thread of errors!?

RUN.PY WHY CANT YOU RUN CROSSPLATFORM RRRRRRRRGH!!!!!!

Anyways heres the bugs that need to be SQUASHED INTO OBLIVION:

Exception in thread Thread-1 (listen):
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
Traceback (most recent call last):
File "/Users/jacobbender/Sucorn-Dj-DALLE-BOT/utilities/reverse_api/run.py", line 139, in
keyboard.on_press_key('ins', organize_windows)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/keyboard/init.py", line 510, in on_press_key
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
return hook_key(key, lambda e: e.event_type == KEY_UP or callback(e), suppress=suppress)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/keyboard/init.py", line 294, in listen
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/keyboard/init.py", line 493, in hook_key
_os_keyboard.listen(self.direct_callback)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/keyboard/_darwinkeyboard.py", line 430, in listen
scan_codes = key_to_scan_codes(key)
^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/keyboard/init.py", line 324, in key_to_scan_codes
raise ValueError('Key {} is not mapped to any known key.'.format(repr(key)), e)
raise OSError("Error 13 - Must be run as administrator")
ValueError: ("Key 'ins' is not mapped to any known key.", ValueError('Unrecognized character: insert'))
Usage: open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-s ][-b ] [-a ] [-u URL] [filenames] [--args arguments]
Help: Open opens files from a shell.
By default, opens each file using the default application for that file.
If the file is in the form of a URL, the file will be opened as a URL.
Options:
-a Opens with the specified application.
--arch ARCH Open with the given cpu architecture type and subtype.
-b Opens with the specified application bundle identifier.
-e Opens with TextEdit.
-t Opens with default text editor.
-f Reads input from standard input and opens with TextEdit.
-F --fresh Launches the app fresh, that is, without restoring windows. Saved persistent state is lost, excluding Untitled documents.
-R, --reveal Selects in the Finder instead of opening.
-W, --wait-apps Blocks until the used applications are closed (even if they were already running).
--args All remaining arguments are passed in argv to the application's main() function instead of opened.
-n, --new Open a new instance of the application even if one is already running.
-j, --hide Launches the app hidden.
-g, --background Does not bring the application to the foreground.
-h, --header Searches header file locations for headers matching the given filenames, and opens them.
-s For -h, the SDK to use; if supplied, only SDKs whose names contain the argument value are searched.
Otherwise the highest versioned SDK in each platform is used.
-u, --url URL Open this URL, even if it matches exactly a filepath
-i, --stdin PATH Launches the application with stdin connected to PATH; defaults to /dev/null
-o, --stdout PATH Launches the application with /dev/stdout connected to PATH;
--stderr PATH Launches the application with /dev/stderr connected to PATH to
--env VAR Add an enviroment variable to the launched process, where VAR is formatted AAA=foo or just AAA for a null string value.
Fatal Python error: _enter_buffered_busy: could not acquire lock for <_io.BufferedWriter name=''> at interpreter shutdown, possibly due to daemon threads
Python runtime state: finalizing (tstate=0x00000001064caaf8)

Current thread 0x00000001feab8c00 (most recent call first):

Extension modules: objc._objc, CoreFoundation._CoreFoundation, CoreFoundation._inlines, Foundation._Foundation, Foundation._inlines, AppKit._AppKit, AppKit._inlines, Quartz.CoreGraphics._callbacks, Quartz.CoreGraphics._doubleindirect, Quartz.CoreGraphics._sortandmap, Quartz.CoreGraphics._coregraphics, Quartz.CoreGraphics._inlines, Quartz.ImageKit._imagekit, Quartz.CoreVideo._CVPixelBuffer, Quartz.QuartzCore._quartzcore, Quartz.PDFKit._PDFKit, Quartz.QuickLookUI._QuickLookUI (total: 17)
zsh: abort /usr/local/bin/python3 imagedir --delay 10 --max 20
(base) jacobbender@Jacobs-MacBook-Pro Sucorn-Dj-DALLE-BOT %

Error: SystemExit2

Screenshot 2024-07-22 at 15 37 36
I think this might have had been what your commit was supposed to fix, but for some odd reason, when running the debugger tests to make sure that this works crossplatform, my python debugger returns the error shown.

data; (Not secure) is where this takes me to

Screenshot 2024-04-26 at 14 16 47
No cookies found in cookies.json, proceed to input usernames/email addresses? (default N):

(YOU SAID MAC ALREADY HAD COOKIES.JSON but it doesn't, it has USERNAMES.json)

ok i am calming down. sorry if i overreacted

New traceback issue (Run.py for Mac and Windows)

according to the run.py reserved for mac and windows, when I ran the file, I got traceback (most recent call last):
File "/Users/jacobbender/Sucorn-Dj-DALLE-BOT/utilities/reverse_api/run.py", line 123, in
prompt = p_file.read()
^^^^^^^^^^^^^
io.UnsupportedOperation: not readable

I ran it as admin.

sudo /usr/local/bin/python3 /Users/jacobbender/Sucorn-Dj-DALLE-BOT/utilities/reverse_api/run.py imagedir --delay 10 --max 20

Debug found the following: Exception has occurred: Forbidden 403 Forbidden (error code: 50001): Missing Access File "/Users/jacobbender/Sucorn-Dj-DALLE-BOT/features/aclient.py", line 87, in setup_hook await self.tree.sync(guild=MY_GUILD) File "/Users/jacobbender/Sucorn-Dj-DALLE-BOT/sucorn.py", line 285, in <module> client.run(os.getenv('TOKEN')) discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access

Exception has occurred: Forbidden
403 Forbidden (error code: 50001): Missing Access
File "/Users/jacobbender/Sucorn-Dj-DALLE-BOT/features/aclient.py", line 87, in setup_hook
await self.tree.sync(guild=MY_GUILD)
File "/Users/jacobbender/Sucorn-Dj-DALLE-BOT/sucorn.py", line 285, in
client.run(os.getenv('TOKEN'))
discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access

WHAT IS THIS BS!!!!!!!!!

BingImageCreator.py is asking for prompt. When I give it the prompt it says "Unrecognized Arguments"

Screenshot 2024-07-22 at 15 56 45
I give it the second argument but what does BingimageCreator.py say "Unrecognized Arguments".
IN full context:
I gave BingImageCreator.py the second argument, which was the prompt, of my anime boys bouncing on giant space hoppers, but BingImageCreator.py returns "Unrecognized arguments" despite me giving the prompt that I wanted. Same happens when I use quotation marks. as of now I am also going to try it with the apostrophe to see if it works and if it doesn't i will let you know.

Mac is really being STUBBORN! Also run.py sorta works.

Traceback (most recent call last):
File "/Users/jacobbender/Sucorn-Dj-DALLE-BOT/utilities/reverse_api/run.py", line 139, in
open_console_window(account, token, prompt, out_path, args.delay, args.max, platform=pf)
File "/Users/jacobbender/Sucorn-Dj-DALLE-BOT/utilities/reverse_api/run.py", line 52, in open_console_window
creationflags=subprocess.CREATE_NEW_CONSOLE
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'subprocess' has no attribute 'CREATE_NEW_CONSOLE'
Screenshot 2024-06-02 at 11 59 55

In addition, in the terminal that run.py opened:
Waiting for results...
.Failed: Exception: Could not get results

(I think Run.py got dogged)

MAC OS, WHY ARE YOU SO STUBBORN! JUST LET SUCORN LIVE IN HARMONY WITH YOU!!!!!!!

Huge traceback preventing me from getting my mac fork of Sucorn online.

(base) jacobbender@Jacobs-MacBook-Pro Sucorn-Dj-DALLE-BOT % /usr/local/bin/python3 /Users/jacobbender/Sucorn-Dj-DALLE-BOT/sucorn.py
2024-05-06 11:39:38 INFO discord.client logging in using static token
2024-05-06 11:39:39: CPU Usage 25.3%, Memory Usage 116496.0 KB
Traceback (most recent call last):
File "/Users/jacobbender/Sucorn-Dj-DALLE-BOT/sucorn.py", line 287, in
client.run(os.getenv('TOKEN'))
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/discord/client.py", line 860, in run
asyncio.run(runner())
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/discord/client.py", line 849, in runner
await self.start(token, reconnect=reconnect)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/discord/client.py", line 777, in start
await self.login(token)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/discord/client.py", line 621, in login
await self.setup_hook()
File "/Users/jacobbender/Sucorn-Dj-DALLE-BOT/features/aclient.py", line 87, in setup_hook
await self.tree.sync(guild=MY_GUILD)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/discord/app_commands/tree.py", line 1069, in sync
data = await self._http.bulk_upsert_guild_commands(self.client.application_id, guild.id, payload=payload)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/discord/http.py", line 739, in request
raise Forbidden(response, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access

All errors are gone but upon running the sucorn code, i am receiving this error: Traceback (most recent call last): File "/Users/jacobbender/Sucorn-Dj-DALLE-BOT/sucorn.py", line 35, in <module> from aclient import MyClient, PosNegView ImportError: cannot import name 'MyClient' from 'aclient' (/opt/anaconda3/lib/python3.11/site-packages/aclient/__init__.py) (base) jacobbender@Jacobs-MacBook-Pro Sucorn-Dj-DALLE-BOT %

just when I thought sucorn was ready to go, it returns this after I run the code

Traceback (most recent call last):
File "/Users/jacobbender/Sucorn-Dj-DALLE-BOT/sucorn.py", line 35, in
from aclient import MyClient, PosNegView
ImportError: cannot import name 'MyClient' from 'aclient' (/opt/anaconda3/lib/python3.11/site-packages/aclient/init.py)
(base) jacobbender@Jacobs-MacBook-Pro Sucorn-Dj-DALLE-BOT %
to fix the import error, we need to import the MyClient and PosNegView classes from the aclient module.

see you when you get up

while running the new setup.py file, traceback error occured

i did all the steps correctly so far

then after entering my prompt, traceback said "Traceback (most recent call last):
File "/Users/jacobbender/Sucorn-Dj-DALLE-BOT/setup.py", line 41, in
with open(f"{DIRECTORY}/reverse_api/prompt.txt", "w", encoding="utf-8") as f:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/Users/jacobbender/Sucorn-Dj-DALLE-BOT/reverse_api/prompt.txt'"

the prompt if you are curious is: anime artstyle: a 23 year old black haired Filipino male in athletic clothing and a white blonde female in athletic clothing happily riding and bouncing through the night sky on giant plain red space hopper balls With a handle on it for them to Hang onto while straddling the ball bouncing, both ball and handle must be of the same color, on the front center of the balls bear a bouncing kangaroo print drawing picture on them, the male and female are sitting directly on a ball holding
onto its handles with their two hands their legs visibly must be in front of the ball both of their feet are down, both of the space hopper balls off the ground, field of clouds in the night sky colored anime closeup perspective
and i inserted the prompt as one line.

Issue: Upon trying to "automatically" receive the cookies via entering my email address and username, it wants me to do it multiple times without quitting + Also I can't think of anything else to do after running into the open chrome browser, do I log in manually or?

Screenshot 2024-04-24 at 08 56 56

Screenshot 2024-04-24 at 08 23 06

Images are in order of the title.

  1. stuck at the data screen when opening up chrome, but when i discovered the problem was it couldn't detect a cookies.json file and I selected N to input it manually, i had to keep inputting my username and email and i don't know how to move on to the next thing.
  2. Like i said in the discord, I decided on just manually entering into bing image creator until a solution was found (which probably won't happen until you finish what you need to do on DND) but yeah, I figured just entering my account manually was the way to get the cookie retrieved.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.