AndBobsYourUncle / stable-diffusion-discord-bot

A Discord bot, written in Go, that interfaces with the Automatic 1111's API interface.
MIT License
128 stars 35 forks source link

Documentation change and feature request #4

Closed bitburner closed 1 year ago

bitburner commented 1 year ago

During the setup, I had difficulty with what GCC to install. I installed a 32-bit version first by accident. Also, I think I had to add the %PATH% environment variable by hand for GO and GCC (maybe not needed if the default location is used). The changes you made to the installation section in the readme should help a little bit but be thinking maybe there could be more specific instructions so more basic users don't get caught up with the same hangups I did and don't bug you for the small stuff. For example, the link you provided to Sourceforge is just the page for that package and not a link to the 64bit package that is needed.

Maybe something more like this for less advanced windows users?

Windows Installation

Clone this repository

Install GIT for windows (this should already be installed if you are installing on the same windows machine as your Automatic1111 install) https://git-scm.com/download/win

Create or traverse to a folder you want the installation directory to be cloned to in windows explorer. In this example, I'm using a folder in the root of my local "C" drive "C:\tools". I open that folder in windows explorer and right-click in the empty space and choose "Git Bash here" from the contextual menu, this opens a git command window already in the directory.

Clone the repository using this git command in the console window you just opened:

git clone https://github.com/AndBobsYourUncle/stable-diffusion-discord-bot.git

*Note: from now on if you want to update the code you can do the same process to open a git command window and use the git command: git pull

The source is in Go and will need to be compiled into an EXE using Go and GCC

Install Go

https://go.dev/doc/install

By default, the installer will install Go to Program Files or Program Files (x86). You can change the location as needed. After installing, you will need to close and reopen any open command prompts so that changes to the environment made by the installer are reflected in the command prompt.

*I've noticed that if you install Go to an alternate location it sets the %PATH% environment variable to be the programs file folder not the alternate folder. You can change it by going to "settings" in the start menu then into "System" then under "about" (very bottom) there is a link under "related Settings" called "Advanced System Settings". This will open the System Control Panel already on the tab with the Environment Variables editor button. Click it to edit the list. The top entries are for the "User" and the bottom are for the "System". You may need to edit both locations. The Variable for go is not in "Path" and is it's own entry called "GOPATH" these should be pointing to the go directory. In my example, I installed go to C:\tools\go instead of the default program files folder and had to change the GOPATH variable manually with that path.

You will need 64bit GCC installed to compile the EXE

https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/mingw-w64-v10.0.0.zip/download

You can check if it was installed properly with

GCC --version

It should return something like this if installed correctly:

gcc.exe (GCC) 10.4.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

*The installer should add the location of GCC to your "Path" environmental variables but may not if you choose a non-default location, you can check there if it can't find GCC after installation. Also, don't forget to restart any command windows you had open before installation before using.

Build the bot with go build

Make sure you're in the project directory and build the bot with go build:

go build

If it's successful you will get no errors and return to a ready state. You will now have a stable_diffusion_bot.exe in your directory and are ready to move on to "usage".

*If you make any changes to files or do a "git pull" and the code is updated then you will need to re-build the EXE to gain those new code changes.


Ok I had mentioned this feature request in another thread but didn't want it to get lost. I was wondering if we can add "style" to the queue.go under newGeneration


styles: [
    "string"
],
bitburner commented 1 year ago

I'll make a more detailed feature request post about the styles and try to learn to set a label ;)

AndBobsYourUncle commented 1 year ago

Thank you very much for this writeup. I'm also planning on adding some automated Github releases to build this into executables for a variety of platforms (including Windows) every time I push a new release version.

I haven't personally went down the rabbit hole of getting Go installed in Windows, but this is definitely very helpful. I have a gaming PC that I run Stable Diffusion on (with Windows), but I ended up installing everything on my dual-booted Linux instead, since it was way easier.

And honestly, getting a system service setup that auto-starts without a login (that runs both A1111 and this bot) is also way easier in Linux than Windows (systemd FTW). My computer just boots up when power is present, and everything starts up magically, with no need to login after bootup and start any scripts.

But it does seem a lot more painful to install Go in Windows compared to macOS or Linux. I've setup Go in macOS, and Linux, dozens if not hundreds of times. Never tried in Windows. It seems almost as painful as getting Python setup in Windows. 😆

AndBobsYourUncle commented 1 year ago

After diving in, it appears the Go package I used for sqlite depended on cgo, which is a pain for cross compilation. I tried a bunch of stuff in Github, but getting reliable cross-compilation was a pain.

So, I've moved to using https://pkg.go.dev/modernc.org/sqlite, which is a C-free port of sqlite for Go. This would theoretically allow you to compile this app without installing mingw at all (maybe, but I haven't tried myself).

However, after I moved to this, I was able to set up a release Github action that cross compiles to all modern architectures. I've confirmed that it runs natively on my macOS arm64 (M1 Mac using darwin-arm64), my Linux server (linux-amd64), and even Windows (my gaming PC with windows-amd64).

So, from here on out, it seems that building it might not even be necessary, and just downloading and running the .exe from the release in Github might work perfectly.

Here's the release, if you'd like to try it out: https://github.com/AndBobsYourUncle/stable-diffusion-discord-bot/releases/tag/v0.1.0

bitburner commented 1 year ago

That's great news. I plan to try and maybe host this on a runpod or something and see how that works for dedicated. Right now just running it for friends etc and they're having a blast with it. Thanks for this.

AndBobsYourUncle commented 1 year ago

I'm going to close this since I've added this info to the readme, and now local builds are optional. Feel free to open a PR though if you'd like to contribute to the readme. You can fork this repository, make changes to a branch on your forked repo, and then open a Github pull request against this repository.

I could then accept and merge the PR, and it would update this repo's readme.