Article Four: My text-to-img Journey - Automatic1111 System Tuning
This is the Forth post in a series of articles I have been writing about text-to-image software. In this series, I will talk about how the technology works, ways you can use it, how to set up your own system to batch out images, technical advice on hardware and software, advice on how you can get the images you want, and touch on some of the legal, ethical, and cultural challenges that we are seeing around this technology. My goal is to keep it practical so that anyone with a little basic computer knowledge can understand and use these articles to add another tool to their art toolbox, as cheaply and practically as possible. In this fourth post, I will provide steps to help you access the Automatic1111 stable-diffusion-webui from any computer on your home network and enable your Linux Ubuntu system to automatically start the webUI process after reboot and automatically restart when errors occur.
The first thing we have to do is stop your current webui process, if it is running. In the last article we started is with the command ./webui.sh from the /stable-diffusion-webui/ directory. If it is still running it that same terminal, go ahead stop it by pressing the keys “CRTL” and “C” at the same time. This should return your termal back to the normal prompt waiting for commands.
NOTE: IF you want to skip the –listen flag and NOT enable the ability to access the webUI from other computers, you can. The steps below to enable auto start of the service are the same, just remove the –listen flag from the script.
Now lets run the webui command again, this time allowing access to any computer on the same network. To do this, make sure you in the “stable-diffusion-webui” then type in the terminal window:
./webui.sh –listen
This will run for a minute. If all is successful, the last lines it will output will be similar to what you saw before, but the sting of number, called an IP address, will be different:
What you saw with out the flag –listen:
Running on local URL: http://127.0.0.1:7860
What you should see now will look different. Something like what you see below:
Running on local URL: http://192.168.1.9:7860
The above means that my computer has the IP address 192.168.1.9 currently associated with it and the 7860 stands for the port that the webui service is listening on. This port is always what the webui will use, if it is available. If I go to another computer/laptop/tablet that is connected to my same network and enter what your system IP and port that was listed http://xxx.xxx.xxx.xxx:7860 (in my case http://192.168.1.9:7860) in the chrome browser, it should show your Automatic1111 web ui.
Now you know that it works, go ahead and stop it by pressing the keys “CRTL” and “C” at the same time in the terminal window, but rember the IP address, or bookmark it in your browser.
Lets go ahead and automate the service. We are going to use the Systemd service in Ubuntu to automat and manage services.
The step-by-step instructions for adding a new service file to Systemd in Ubuntu Linux:
Create a new service file: Use a text editor to create a new file named webui with the extension .service in the /etc/systemd/system directory. For example:
sudo nano /etc/systemd/system/webui.service
OR
sudo pico /lib/systemd/system/webui.service
Define the service: In the new service file, define the service by specifying the unit name, the description, the service type, and the command or script to run. Below is the copy of my webui.service file. If you followed my install instructions in the previous article the only thing you need to change is the the <YOURUSERNAME> to match where your Automatic1111 stable-diffusion-webui directory is installed under your home directory. You will notice we are adding the flag “–listen” at the end of the start command. As noted above, you can remove that flag if you don't care about access from other computers. Copy the text below and edit the <YOURUSERNAME> section:
[Unit]
Description=Stable Diffusion AUTOMATIC1111 Web UI service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
User=<YOURUSERNAME>
WorkingDirectory=/home/<YOURUSERNAME>/stable-diffusion-webui
ExecStart=/usr/bin/env bash /home/<YOURUSERNAME>/stable-diffusion-webui/webui.sh --listen
StandardOutput=append:/var/log/sdwebui.log
StandardError=append:/var/log/sdwebui.log
Restart=always
RestartSec=2
[Install]
WantedBy=multi-user.target
Save the service file: Once you've webui.service file is edited and looks the same as above (having changed the <YOURUSERNAME>), save the file and exit the text editor.
Reload the Systemd daemon: Run the following command to reload the Systemd daemon and make it aware of the new service.
sudo systemctl daemon-reload
Start the service: Run the command to start the service.
sudo systemctl start webui
Check the service: Give the start command 30 seconds, but then you can check the status of the service by running the following command.
sudo systemctl status webui
Enable the service: To ensure that the service starts automatically at boot, run the command:
sudo systemctl enable webui
That's it! Your new service should now be running and configured to start automatically on boot. As an added bonus it will be running on your network!
Go ahead and make sure everything is running correctly by going to your other computer/laptop/tablet that is connected to my same network and enter what your system IP and port that was listed http://xxx.xxx.xxx.xxx:7860 or if you have the page still open or bookmarked, go ahead and refresh. Your webui should show up.
In conclusion, with Automatic1111 installed on your Linux server and its configuration fine-tuned, you can now enjoy uninterrupted connectivity and focus solely on your creative projects without worrying about the technicalities. Keep an eye out for the upcoming article, which will provide hints and suggestions to help you create the images you want, find models, and merge your own. Thank you for reading, and we hope to see you in the next post!
NOTES:
Safari Browser has some issues with the webUI, use Chrome or a similar browser
WebUI has some security, but I would not consider it secure. Some security features to note:
You can not install extensions or updates unless you are running local
If you start the webui with –listen you are share the interface on the network
If you start the webui with –share you are share with the world through huggyface.io, not recommended unless you want to share you GPU cycles.
Like all software, webui will crash at times. Setting up a systemctl script for webui to auto start/restart on reboot and when errors occur will save time and headaches.
Comments
Post a Comment