使用Google Cloud Video Intelligence API做视频检测最大的缺陷是无法自定义规则,若使用gemini-1.5-pro-002多模拟模型,则可以自定义检测的规则,具有更好的灵活性。
安装SDK
pip install --upgrade google-cloud-aiplatform
gcloud auth application-default login
直接上代码
import base64
import vertexai
from vertexai.generative_models import GenerativeModel, SafetySetting, Partdef multiturn_generate_content():vertexai.init(project="your_project_id", location="us-central1")model = GenerativeModel("gemini-1.5-pro-002",)chat = model.start_chat()print(chat.send_message(["""BDSM"""],generation_config=generation_config,safety_settings=safety_settings))print(chat.send_message([video2_1, """the video is BDSM or not? just output Yes or No."""],generation_config=generation_config,safety_settings=safety_settings))video2_1 = Part.from_uri(mime_type="video/mp4",uri="gs://your_bucktet/xxx.mp4",
)generation_config = {"max_output_tokens": 8192,"temperature": 1,"top_p": 0.95,
}safety_settings = [SafetySetting(category=SafetySetting.HarmCategory.HARM_CATEGORY_HATE_SPEECH,threshold=SafetySetting.HarmBlockThreshold.OFF),SafetySetting(category=SafetySetting.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,threshold=SafetySetting.HarmBlockThreshold.OFF),SafetySetting(category=SafetySetting.HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,threshold=SafetySetting.HarmBlockThreshold.OFF),SafetySetting(category=SafetySetting.HarmCategory.HARM_CATEGORY_HARASSMENT,threshold=SafetySetting.HarmBlockThreshold.OFF),
]multiturn_generate_content()