Redact Client: Getting started
This guide explains how to install and use the Redact Client, a lightweight and recommended command-line tool for running redaction jobs efficiently. The Redact Client simplifies batching tasks and allows flexible parameter settings for your anonymization workflows.
In this guide, you’ll learn:
- How to install it
- How to use it
The GitHub repository of the Redact Client .
How to install it:
1. Install the Redact Client
Install the Redact Client using pip directly from our GitHub repository:
pip install git+https://github.com/brighter-ai/redact-client.git
After installing, you can test the installation by getting to the help page via:
redact_file v4 --help
Be aware that Redact Client supports two modes: redact_file
and redact_folder
. For both modes, there are two API versions supported: v3
and v4
. If not explicitly requested, always use the v4
version. You can learn more about redact_file
and redact_folder
in the How to use it section.
2. Test the Tool
We recommend testing the Redact Client using sample data. Ensure your input meets the data format requirements, which you can find here: [Supported Formats](https://docs.brighter.ai/docs/supported-formats).
To test the tool, use the following command in the terminal - make sure you are in the Python environment where Redact Client was installed:
redact_file v4 \
--file-path <file_path> \
--output-type <output_type> \
--service <service> \
--redact-url=<url>
<file_path>
... path to your input file.<output_type>
...images
orvideos
depending on your input.<service>
... for the desired task (e.g.blur
ordnat
).<url>
... on where the Redact API is running if you deploy on your premises.--api-key <api_key>
instead of--redact-url
if using the Redact Online cloud API.
Notes on default:
- If not specified otherwise, the default port for the Redact API is 8787.
- If not specified otherwise, the output path is the same as the input path and file names are extended by
*_redacted.*
.
File naming after redacting:
- a result image of an input image
image.jpg
is namedimage_redacted.jpg
if the output path is the same as the input path. - a result image of an input image
image.jpg
is namedimage.jpg
if the output path is not the same as input path.
The Redact Client will issue no new request if a corresponding result file already exists!
Full example
Redacting via DNAT an image image.jpg
via Redact Enterprise Orchestration running on the same machine as where Redact Client is installed. Copy this code for a quick sample usage into your terminal.
redact_file v4
--file-path tests/resources/obama.jpg \
--output-type images \
--service dnat \
--redact-url=http://127.0.0.1:8787
The resulting image is named image_redacted.jpg
and lies in the same path as image.jpg
. Running the same command directly again after receiving the image_redacted.jpg
does not trigger a second processing as redact client understands that the image is already redacted!
How to use it:
The two main use cases can be summed up as the:
- Command-Line Usage:
redact_file
for processing single files via the command line, theredact_folder
for processing batches of files via the command line
- API request:
- using the redact package to incorporate redact into your Python application / worker
1. Command-Line Usage
The best starting point is to get familiar with the redact_file
and redact_folder
API by reading through all available parameters:
redact_file v4 --help
redact_folder v4 --help
- Here are a few important parameter:
- speed_optimized: This parameter removes some steps in the pipeline and trade offs visual quality for speed. In practice the gains you get in speed are usually not worth the offset in visual quality.
- vehicle_recorded_data: This parameter assumes that videos/images come from a front camera in a vehicle. It therefore makes assumptions about the maximum size and location of license plates and faces. While this can help with data quality, it can be a compliance issue in situations where someone comes very close to the car.
- single_frame_optimized: This parameter removes the tracking part of the pipeline. For videos with low frame rates (<15 FPS) tracking can sometimes decrease performance, because the detected faces/license plates are too far from another in consecutive frames.
- *_determination_threshold: These two parameters can be used to optimise detection performance for a customer's data distribution. It is important to note that when the detection models are updated clients would need to find again the optimal values for their data distribution. Default thresholds are therefore recommended.
- areas_of_interest: This feature can be used for videos or images that contain multiple screen (e.g. a split screen setup). During anonymising each area of interest is regarded on its own and the video is put back together in the end.
redact_file API- redact single files
Here we build a redact request that processes a video by blurring only license plates and ignoring faces! The request is sent to our Redact Online cloud API and hence the API key is defined. To prefer speed over accuracy, we set --single-frame-optimized
. For this example, we assume there are license plates that are barely recognizable but we still want to blur them hence we set a low threshold via --license-plate-determination-threshold
. To have a complete insight into which requests the Redact Client is handling we set our logging to --verbose-logging
.
redact_file v4
--file-path video.mp4 \
--output-type videos \
--output-path ./output/video.mp4 \
--service blur \
--region germany \
--no-face \
--license-plate \
--single-frame-optimized \
--license-plate-determination-threshold 0.1 \
--api-key <api-key> \
--verbose-logging \
--redact-url=https://api.brighter.ai
Once the processing has completed, you will find the processed file relative to the command in the output folder and the redacted file is called video.mp4
.
redact_folder API - batch process entire folders
- To process a larger set of files, use the redact_folder command:
redact_folder v4
--input-dir [INPUT_DIR] \
--output-dir [OUTPUT_DIR] \
--output-type images \
--service dnat \
--redact-url=http://127.0.0.1:8787
- It has the optional argument --n-parallel-jobs for anonymizing several objects in parallel which can result in a significant speed-up when processing many small files.
2. Using API requests
The Redact Client provides high-level Python methods to interact with the API and reduce boilerplate code.
Basic Example
- To start a redaction job:
from redact import RedactInstance, ServiceType, OutputType redact = RedactInstance.create( service=ServiceType.blur, out_type=OutputType.images, redact_url='<http://127.0.0.1:8787'> ) with open('image.jpg', 'rb') as f: result = redact.start_job(file=f).wait_until_finished().download_result()
Using Redact Online with API Key
- If you're using the Redact Online Service, provide your API key:
- from redact import RedactInstance, ServiceType, OutputType redact = RedactInstance.create( service=ServiceType.blur, out_type=OutputType.images, redact_url='<https://api.brighter.ai/'>, api_key="VALID_API_KEY" )
Switching API Versions
If a specific API version is required, import from the relevant module:
# Import API version 4
from redact.v3 import RedactInstance, ServiceType, OutputType, JobLabels
Advanced Configurations
You can further customize the anonymization process using JobArguments to fine-tune options:
Example:
from redact import JobArguments, OutputType, RedactInstance, Region, ServiceType
redact = RedactInstance.create(
service=ServiceType.blur,
out_type=OutputType.images,
redact_url="http://127.0.0.1:8787",
)
job_args = JobArguments(
region=Region.united_states_of_america,
face=True,
license_plate=False
)
with open("tests/resources/obama.jpg", "rb") as f:
job = redact.start_job(file=f, job_args=job_args)
result = job.wait_until_finished().download_result()
Troubleshooting
If you encounter any issues during the installation or setup, please reach out to our team. We’ll assist you during the onboarding call to ensure a smooth deployment.
Updated 7 days ago