Skip to main content

A simple FastAPI server to host WD14 Tagger

Project description

A simple FastAPI Server to run WD1.4-Tagger

Feel free to make PRs or use the code for your own needs

Changelog

You can keep track of all changes on the release page

Installation

Simple installation :

pip install wd14-tagger-api

This will install all the necessary dependencies, including a CPU support only version of PyTorch

I recommend that you install the GPU version to improve processing speed.

Don't forget to add the -d gpu flag

Note The first startup using a video card may take a long time ( up to 30-60 seconds ) but then the result of processing will be almost minimal

Windows

python -m venv venv
venv\Scripts\activate
pip install wd14-tagger-api
pip install onnxruntime-gpu

Linux

python -m venv venv
source venv\bin\activate
pip install wd14-tagger-api
pip install onnxruntime-gpu

Manual

# Clone REPO
git clone https://github.com/daswer123/wd14-tagger-api-server
cd wd14-tagger-api-server
# Create virtual env
python -m venv venv
venv/scripts/activate or source venv/bin/activate
# Install deps
pip install -r requirements.txt
pip install onnxruntime-gpu
# Launch server
python -m wd14_tagger_api
 

Starting Server

python -m wd14_tagger_api will run on default ip and port (localhost:8019)

usage: xtts_api_server [-h] [-hs HOST] [-p PORT] [-d DEVICE] [-wdm WD14 model] [-wdt WD14 threshold] [--replace-underscore]

Run WD14-Tagger within a FastAPI application

options:
  -h, --help show this help message and exit
  -hs HOST, --host HOST
  -p PORT, --port PORT
  -d DEVICE, --device DEVICE `cpu` or `gpu`
  -wdm WD14 Model, --wd14-model You can specify which model to use when loading the server.
  -wdt WD14 Threshold, --wd14-threshold  Threshold value for WD14
  --replace-underscore Will return spaces instead of underscore

Avalible Models

  • wd14-vit.v2
  • wd14-vit.v2
  • wd14-convnext.v1
  • wd14-convnext.v2
  • wd14-convnextv2.v1
  • wd14-swinv2-v1
  • wd-v1-4-moat-tagger.v2
  • mld-caformer.dec-5-97527
  • mld-tresnetd.6-30000

API Docs

API documentation can be accessed from http://localhost:8002/docs when the server is running. This documentation is automatically generated by FastAPI and provides an interactive interface to test the API endpoints.

Endpoints Overview

The server provides several endpoints related to image tagging functionality:

POST /update-settings/

This endpoint allows updating model settings dynamically.

  • Request Body: JSON object containing new settings values.
    • wd14_model: String (optional). The name of the model to use.
    • threshold: Float (optional). The threshold value for tag generation.

Example Request:

{
  "wd14_model": "new-model-name",
  "threshold": 0.5
}

Response: A confirmation message indicating that settings have been updated successfully.

POST /tag-image/

Upload an image file to get associated tags based on current model and threshold settings.

  • Form Data:
    • file: File. Image file to be tagged.

Response: A string of comma-separated tags generated for the uploaded image. If WD14_REPLACE_UNDERSCORE environment variable is set to true, underscores in tags are replaced with spaces.

Usage Examples

Below are examples using curl command-line tool to interact with the server:

Updating Model Settings

curl -X 'POST' \
'http://localhost:8002/update-settings/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"wd14_model": "new-model-name", "threshold": 0.5}'

Tagging an Image

curl -X 'POST' \
'http://localhost:8002/tag-image/' \
-H 'accept: application/json' \
-F 'file=@path_to_your_image.jpg;type=image/jpeg'

Replace "path_to_your_image.jpg" with the actual path to your image file you wish to tag.

Credit

  1. Thanks corkborg for its standalone version, I used it as a base for the server.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wd14_tagger_api-0.0.1.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

wd14_tagger_api-0.0.1-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file wd14_tagger_api-0.0.1.tar.gz.

File metadata

  • Download URL: wd14_tagger_api-0.0.1.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.0

File hashes

Hashes for wd14_tagger_api-0.0.1.tar.gz
Algorithm Hash digest
SHA256 428b0aa2879f9c4dfc4bd30ced5e93eb960d666d2eb4cd5f6a4e0319a2da76f1
MD5 645e1b3cb5d74d5e68c0ab98435c53ac
BLAKE2b-256 ba9f909e6c8e9d8d335e6beb0007daafce05432608e9a9c528943db89f5f44b5

See more details on using hashes here.

File details

Details for the file wd14_tagger_api-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for wd14_tagger_api-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb41afdd1b8f497c0e5f247e0dec0ebc9faff61673d30bff3de6286760a850e2
MD5 e3cc2db41f9d9509fcf3f526ae2528a8
BLAKE2b-256 b065b208bf8f6455d439e178953d508a7313eb0f1e3c2851af0aff76bdb5e6af

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page