Page:
Installing on Linux
1
Installing on Linux
Skylar Grant edited this page 2025-01-06 18:35:10 -05:00
Installing the AI Tagger Server on Linux (Headless)
This guide is primarily developed using Ubuntu 22.04, but any other Debian-based distribution should work as well.
Install Miniconda3
# Update and upgrade the system
sudo apt update && sudo apt upgrade -y
# Install the required packages
sudo apt install -y unzip
# Download and install Miniconda3
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
# Remove the installer
rm ~/miniconda3/miniconda.sh
# Add Miniconda to PATH
echo "export PATH=~/miniconda3/bin:\$PATH" >> ~/.bashrc
# Update PATH now so we can use conda right away
export PATH=~/miniconda3/bin:$PATH
conda init
Install the AI Tagger Server
# Create a folder for the server
mkdir -p ~/nsfw_ai_model_server
# Download the latest server release
wget https://github.com/skier233/nsfw_ai_model_server/releases/latest/download/nsfw_ai_model_server.zip -O ~/nsfw_ai_model_server/nsfw_ai_model_server.zip
# Unzip the server
unzip ~/nsfw_ai_model_server/nsfw_ai_model_server.zip -d ~/nsfw_ai_model_server
# Remove the zip file
rm ~/nsfw_ai_model_server/nsfw_ai_model_server.zip
cd ~/nsfw_ai_model_server
mv 2.0/* .
# Enable execution of the scripts
chmod +x install.sh start.sh update.sh
Install the Model(s)
- Download the relevant models from the models page
scp
or otherwise copy the model(s) to the serverscp ~/Downloads/gentler_river.zip user@server:~/
unzip
the model(s) and copy theirmodels
andconfig
folders to the~/nsfw_ai_model_server
folder:unzip ~/gentler_river.zip -d ~/nsfw_ai_model_server
- Optionally, check the
~/nsfw_ai_model_server/config/config.yaml
file and adjust the paths to the modelsnano ~/nsfw_ai_model_server/config/config.yaml
Install the Conda Environment
cd ~/nsfw_ai_model_server
source ./install.sh
- If you're using premium models, you'll get an error about not finding a license file, it will provide a URL to authenticate with Patron and download the license file.
- Download the license file and place it in the
~/nsfw_ai_model_server/models
folder, then start the server again. - Depending on the models used, you may need to do this again (once for Premium models, once for VIP models).
- Download the license file and place it in the
Start the Server
cd ~/nsfw_ai_model_server
source ./start.sh
Update the Server
cd ~/nsfw_ai_model_server
source ./update.sh
Daemonize the Server
There is also a script to daemonize the server, located here, along with one to uninstall the daemon, here.
- Create a systemd service file:
sudo nano /etc/systemd/system/nsfw_ai_model_server.service
- Modify then paste the following into the file:
[Unit] Description=Skier233s NSFW AI Model Server After=network.target [Service] Type=simple User=<USERNAME> Group=<GROUPNAME> WorkingDirectory=/home/<USERNAME>/nsfw_ai_model_server ExecStart=/bin/bash -c "source /home/<USERNAME>/miniconda3/etc/profile.d/conda.sh && conda activate ai_model_server && python server.py" Restart=on-failure Environment="PATH=/home/<USERNAME>/miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" [Install] WantedBy=multi-user.target
- Replace
<USERNAME>
and<GROUPNAME>
with your username and groupname respectively.
- Replace
- Reload the systemd daemon and start the service:
sudo systemctl daemon-reload sudo systemctl enable --now nsfw_ai_model_server