基于业务风险识别产品-视频风险识别-视频点播服务进行视频风险识别。
细分项 | 注意与前提 |
|---|---|
费用 | 调用算子前,您需先了解使用算子时的模型调用费用,详情请参见大模型调用计费。 |
鉴权(API Key) | 调用算子前,您需要先生成算子调用的API Key,并建议将API Key配置为环境变量,便于更安全地调用算子,详情请参见获取 API Key 并配置。 |
BaseURL | 调用算子前,您需要先根据您当前使用的LAS服务所在地域,了解算子调用的BaseURL,用于配置算子调用路径参数取值。 |
输入列名 | 说明 |
|---|---|
data_id | 输入视频唯一标志列 |
url | 视频内容所在的列,支持可直接访问的 url 地址 |
title | (可选)视频标题列 |
account_id | (可选)视频发送者的ID列 |
operate_time | (可选)用户发送视频的秒级时间戳列 |
video_type | (可选)视频类型列,AIGC对话场景下必传,列值为 prompt 表示用户输入视频,列值为 response 表示模型生成视频;空字符串主要作用于非AIGC对话场景 |
session_id | (可选)对话轮次列,AIGC对话场景下必传,用于表示该视频在对话中的轮次 |
一个结构体,包含风险识别结果
如参数没有默认值,则为必填参数
参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
app_id | int | 必填,在业务风险识别产品中开通的应用ID | |
biztype | str | 必填,在业务风险识别产品中配置的视频风险识别场景 | |
result_type | int | 0 | 切片内容类型 |
interval | int | 2 | 截帧频率,单位(s) |
timeout | int | 120 | 超时时间设置,单位(s) |
poll_interval | int | 10 | 轮询间隔设置,单位(s) |
num_coroutines | int | 5 | 并发协程数量 |
下面的代码展示了如何使用 Daft(适用于分布式)运行算子进行视频内容风险识别。
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__": """ 算子使用前置条件:开通业务风险识别产品-文本风险识别,产品链接见:https://www.volcengine.com/product/business-security app_id: 在业务风险识别产品中开通的应用ID biztype: 在业务风险识别产品中配置的场景 还需要设置 ACCESS_KEY,SECRET_KEY 用来鉴权 """ 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) # 使用环境变量构建URL tos_dir_url = os.getenv("TOS_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com") samples = { "video_id": ["8"], # 视频风险识别服务会记录视频 id,同一个 id 会返回已经执行的缓存的结果 "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")), ) # 提取结果字段 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() # 示例输出: # ╭──────────┬────────────────────────────────┬───────────┬────────────┬──────────────────────────┬───────────────┬─────────────────────┬───────────────┬─────────────────────┬─────────┬──────────────────────────╮ # │ 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-… ┆ 测试视频1 ┆ user001 ┆ {VideoDecision: PASS, ┆ PASS ┆ ┆ PASS ┆ ┆ success ┆ {"Result": {"RequestId": │ # │ ┆ ┆ ┆ ┆ VideoDe… ┆ ┆ ┆ ┆ ┆ ┆ "202… │ # ╰──────────┴────────────────────────────────┴───────────┴────────────┴──────────────────────────┴───────────────┴─────────────────────┴───────────────┴─────────────────────┴─────────┴──────────────────────────╯