Video risk identification uses the business risk identification product—video risk identification—video on demand service.
Details | Caution and prerequisites |
|---|---|
Costs | Before calling an operator, you need to understand the model invocation costs associated with using the operator. For details, see Large model invocation billing. |
Authentication (API Key) | Before calling an operator, you need to generate an API Key for operator invocation. It is recommended to configure the API Key as an environment variable to ensure safer operator calls. For details, see Obtain and configure API Key. |
BaseURL | Before calling an operator, you need to determine the BaseURL for operator invocation based on the region where your current LAS service is deployed. This is used to configure the path parameter values for operator calls. |
Input column name | Note |
|---|---|
data_id | Column for the unique identifier of the input video |
url | Column containing the video content, supports directly accessible URL addresses |
title | (Optional) Video title column |
account_id | (Optional) Column for the sender's ID of the video |
operate_time | (Optional) Column for the second-level timestamp when the user sends the video |
video_type | (Optional) Video type column; required in AIGC conversation scenarios. The column value 'prompt' indicates a user-input video, 'response' indicates a model-generated video. An empty string is mainly used in non-AIGC conversation scenarios. |
session_id | (Optional) Conversation round column; required in AIGC conversation scenarios, used to indicate the round of the video in the conversation. |
A struct containing risk identification results
If a parameter does not have a default value, it is required.
Parameter name | Type | Default value | Description |
|---|---|---|---|
app_id | int | Required. Application ID enabled in the business risk identification product. | |
biztype | str | Required. Video risk identification scenario configured in the business risk identification product. | |
result_type | int | 0 | Slice content type |
interval | int | 2 | Frame capture frequency, unit (s) |
timeout | int | 120 | Timeout setting, unit (s) |
poll_interval | int | 10 | Polling interval setting, unit (s) |
num_coroutines | int | 5 | Number of concurrent coroutines |
The following code demonstrates how to use Daft (for distributed scenarios) to run the operator for video content risk identification.
from __future__ import annotations import os import daft from daft import col from daft.las.functions.udf import las_udf from daft.las.functions.video.video_risk_rec import VideoRiskRec if __name__ == "__main__": """ Prerequisite: Enable Business Risk Recognition - Video Risk Recognition - Video on Demand. Product link: https://www.volcengine.com/product/business-security app_id: Application ID enabled in the Business Risk Recognition product biztype: Scenario configured in the Business Risk Recognition product ACCESS_KEY and SECRET_KEY are also required for authentication """ app_id = int(os.getenv("APP_ID", "0")) biztype = os.getenv("BIZTYPE", "test_biztype") if os.getenv("DAFT_RUNNER", "native") == "ray": import logging import ray def configure_logging(): logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S.%s".format(), ) logging.getLogger("tracing.span").setLevel(logging.WARNING) logging.getLogger("daft_io.stats").setLevel(logging.WARNING) logging.getLogger("DaftStatisticsManager").setLevel(logging.WARNING) logging.getLogger("DaftFlotillaScheduler").setLevel(logging.WARNING) logging.getLogger("DaftFlotillaDispatcher").setLevel(logging.WARNING) ray.init(dashboard_host="0.0.0.0", runtime_env={"worker_process_setup_hook": configure_logging}) daft.set_runner_ray() daft.set_execution_config(actor_udf_ready_timeout=600) daft.set_execution_config(min_cpu_per_task=0) # Build the URL using environment variables tos_dir_url = os.getenv("TOS_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com") samples = { "video_id": ["8"], # The video risk identification service records the video id. The same id will return the cached result that has already been executed. "video_url": [ f"https://{tos_dir_url}/public/shared_video_dataset/music_sample.mp4" ], "title": ["测试视频1"], "account_id": ["user001"], } constructor_kwargs = { "app_id": app_id, "biztype": biztype, "result_type": 0, "interval": 2, "timeout": 300, "poll_interval": 3, } ds = daft.from_pydict(samples) ds = ds.with_column( "result", las_udf( VideoRiskRec, construct_args=constructor_kwargs, concurrency=1, batch_size=1, )(col("video_id"), col("video_url"), title_col=col("title"), account_id_col=col("account_id")), ) # Extract result fields ds = ds.with_column("VideoDecision", col("result")["VideoDecision"]) ds = ds.with_column("VideoDecisionDetail", col("result")["VideoDecisionDetail"]) ds = ds.with_column("AudioDecision", col("result")["AudioDecision"]) ds = ds.with_column("AudioDecisionDetail", col("result")["AudioDecisionDetail"]) ds = ds.with_column("Message", col("result")["Message"]) ds = ds.with_column("risk_result", col("result")["risk_result"]) ds.show() # Example output: # ╭──────────┬────────────────────────────────┬───────────┬────────────┬──────────────────────────┬───────────────┬─────────────────────┬───────────────┬─────────────────────┬─────────┬──────────────────────────╮ # │ video_id ┆ video_url ┆ title ┆ account_id ┆ result ┆ VideoDecision ┆ VideoDecisionDetail ┆ AudioDecision ┆ AudioDecisionDetail ┆ Message ┆ risk_result │ # │ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │ # │ String ┆ String ┆ String ┆ String ┆ Struct[VideoDecision: ┆ String ┆ String ┆ String ┆ String ┆ String ┆ String │ # │ ┆ ┆ ┆ ┆ String, ┆ ┆ ┆ ┆ ┆ ┆ │ # │ ┆ ┆ ┆ ┆ VideoDecisionDetail: ┆ ┆ ┆ ┆ ┆ ┆ │ # │ ┆ ┆ ┆ ┆ String, AudioDecision: ┆ ┆ ┆ ┆ ┆ ┆ │ # │ ┆ ┆ ┆ ┆ String, ┆ ┆ ┆ ┆ ┆ ┆ │ # │ ┆ ┆ ┆ ┆ AudioDecisionDetail: ┆ ┆ ┆ ┆ ┆ ┆ │ # │ ┆ ┆ ┆ ┆ String, Message: String, ┆ ┆ ┆ ┆ ┆ ┆ │ # │ ┆ ┆ ┆ ┆ risk_result: String] ┆ ┆ ┆ ┆ ┆ ┆ │ # ╞══════════╪════════════════════════════════╪═══════════╪════════════╪══════════════════════════╪═══════════════╪═════════════════════╪═══════════════╪═════════════════════╪═════════╪══════════════════════════╡ # │ 8 ┆ https://las-ai-qa-online.tos-… ┆ Test video 1 ┆ user001 ┆ {VideoDecision: PASS, ┆ PASS ┆ ┆ PASS ┆ ┆ success ┆ {"Result": {"RequestId": │ # │ ┆ ┆ ┆ ┆ VideoDe… ┆ ┆ ┆ ┆ ┆ ┆ "202… │ # ╰──────────┴────────────────────────────────┴───────────┴────────────┴──────────────────────────┴───────────────┴─────────────────────┴───────────────┴─────────────────────┴─────────┴──────────────────────────╯