This project is a Flask-based web application that automatically generates tags for uploaded images using a published preexisting model.
Clone the repository, create a virtual environment, activate venv, install requirements. Setup env variables if needed:
MODEL_PATH=models/model.onnx
PORT=8000
DEBUG=False
Download the model and tags:
mkdir -p models
wget -O models/model.onnx https://huggingface.co/SmilingWolf/wd-v1-4-swinv2-tagger-v2/resolve/main/model.onnx
wget -O models/selected_tags.csv https://huggingface.co/SmilingWolf/wd-v1-4-swinv2-tagger-v2/raw/main/selected_tags.csv
Make sure your virtual environment is active.
Start the Flask server:
python app.py
Access the application at http://localhost:8000
in your web browser to use the web interface for uploading and tagging images.
For API usage, send POST requests to /evaluate
. Example using curl:
curl -X POST -F "file=@/path/to/your/image.jpg" -F "threshold=0.5" -F "format=json" http://localhost:8000/evaluate
This command uploads an image file, sets the tag threshold to 0.5, and requests JSON output.
Parameters:
file
: The image file to upload (can be specified multiple times for batch processing)threshold
: The minimum confidence score for tags (default: 0.1)format
: Output format, either 'json' or 'html' (default: 'json')The API will return a JSON array of objects, each containing the filename and its associated tags.