Livrare LOT 1 - Didi
This commit is contained in:
commit
5380c3fc63
990 changed files with 133308 additions and 0 deletions
41
ai_platform/modules/video-analysis/deploy/Dockerfile
Normal file
41
ai_platform/modules/video-analysis/deploy/Dockerfile
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# Video Analysis API Server
|
||||
# Multi-stage build for smaller final image
|
||||
|
||||
FROM python:3.11.12-slim AS builder
|
||||
|
||||
# Install uv
|
||||
COPY --from=ghcr.io/astral-sh/uv:0.10 /uv /usr/local/bin/uv
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy project files
|
||||
COPY pyproject.toml uv.lock README.md ./
|
||||
COPY src/ ./src/
|
||||
|
||||
# Install dependencies (allow resolving to pick up new deps)
|
||||
RUN uv sync --no-dev
|
||||
|
||||
# Production image
|
||||
FROM python:3.11.12-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy virtual environment from builder
|
||||
COPY --from=builder /app/.venv /app/.venv
|
||||
|
||||
# Copy source code
|
||||
COPY src/ ./src/
|
||||
|
||||
ENV PATH="/app/.venv/bin:$PATH"
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
ENV VIDEO_ANALYSIS_PORT=54600
|
||||
|
||||
# Health check (python urllib; no curl in slim)
|
||||
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
|
||||
CMD python -c "import urllib.request; import os; urllib.request.urlopen(f'http://localhost:{os.environ.get(\"VIDEO_ANALYSIS_PORT\", 54600)}/health')" || exit 1
|
||||
|
||||
EXPOSE 54600
|
||||
|
||||
CMD uvicorn video_analysis.app:app --host 0.0.0.0 --port ${VIDEO_ANALYSIS_PORT}
|
||||
|
||||
|
||||
116
ai_platform/modules/video-analysis/deploy/deploy.sh
Normal file
116
ai_platform/modules/video-analysis/deploy/deploy.sh
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Docker Compose Startup Script for Video Analysis
|
||||
#
|
||||
# Usage: ./deploy/deploy.sh [OPTIONS]
|
||||
#
|
||||
# Options:
|
||||
# --profile <api|api-vllm> Docker compose profile
|
||||
# --detach Run in detached mode
|
||||
# --down Stop and remove containers
|
||||
# --logs Show logs
|
||||
# --help Show this help message
|
||||
#
|
||||
# Required: Set environment variables in deploy/.env file or export them before running.
|
||||
# See ../.env.example (module root) for the full list of variables.
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# Load .env file ONLY from deploy/ directory
|
||||
if [[ -f "$SCRIPT_DIR/.env" ]]; then
|
||||
echo "Loading environment from: $SCRIPT_DIR/.env"
|
||||
set -a
|
||||
source "$SCRIPT_DIR/.env"
|
||||
set +a
|
||||
fi
|
||||
|
||||
PROFILE=""
|
||||
DETACH=""
|
||||
ACTION="up"
|
||||
|
||||
show_help() {
|
||||
sed -n '2,18p' "$0" | sed 's/^# //' | sed 's/^#//'
|
||||
exit 0
|
||||
}
|
||||
|
||||
check_required_var() {
|
||||
local var_name="$1"
|
||||
if [[ -z "${!var_name:-}" ]]; then
|
||||
echo "ERROR: Required environment variable $var_name is not set"
|
||||
echo "Set it in deploy/.env file or export it before running this script"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--profile)
|
||||
PROFILE="$2"
|
||||
shift 2
|
||||
;;
|
||||
--detach|-d)
|
||||
DETACH="-d"
|
||||
shift
|
||||
;;
|
||||
--down)
|
||||
ACTION="down"
|
||||
shift
|
||||
;;
|
||||
--logs)
|
||||
ACTION="logs"
|
||||
shift
|
||||
;;
|
||||
--help|-h)
|
||||
show_help
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
echo "Use --help for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Require profile when bringing up
|
||||
if [[ -z "$PROFILE" && "$ACTION" == "up" ]]; then
|
||||
echo "ERROR: --profile is required"
|
||||
echo "Options: api, api-vllm"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Fail-fast required vars for wrapper <-> vLLM wiring
|
||||
check_required_var "VIDEO_ANALYSIS_VLLM_BASE_URL"
|
||||
check_required_var "VIDEO_ANALYSIS_VLLM_MODEL"
|
||||
check_required_var "VIDEO_ANALYSIS_RUNS_DIR"
|
||||
check_required_var "VIDEO_ANALYSIS_EXTERNAL_URL"
|
||||
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
case $ACTION in
|
||||
up)
|
||||
echo "Starting Video Analysis with profile: $PROFILE"
|
||||
echo " vLLM base URL: $VIDEO_ANALYSIS_VLLM_BASE_URL"
|
||||
echo " vLLM model: $VIDEO_ANALYSIS_VLLM_MODEL"
|
||||
echo " runs dir: $VIDEO_ANALYSIS_RUNS_DIR"
|
||||
echo ""
|
||||
# shellcheck disable=SC2086
|
||||
exec docker compose --profile "$PROFILE" up $DETACH
|
||||
;;
|
||||
down)
|
||||
if [[ -z "$PROFILE" ]]; then
|
||||
echo "ERROR: --profile is required with --down"
|
||||
exit 1
|
||||
fi
|
||||
echo "Stopping Video Analysis containers..."
|
||||
exec docker compose --profile "$PROFILE" down
|
||||
;;
|
||||
logs)
|
||||
if [[ -z "$PROFILE" ]]; then
|
||||
echo "ERROR: --profile is required with --logs"
|
||||
exit 1
|
||||
fi
|
||||
exec docker compose --profile "$PROFILE" logs -f
|
||||
;;
|
||||
esac
|
||||
130
ai_platform/modules/video-analysis/deploy/docker-compose.yml
Normal file
130
ai_platform/modules/video-analysis/deploy/docker-compose.yml
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
# Video Analysis Module - Docker Compose Configuration
|
||||
#
|
||||
# Port Allocation (Dev AI Vision/Video: 54500-54600):
|
||||
# 54500 - vLLM BusterX (deepfake detection model)
|
||||
# 54600 - Video Analysis API
|
||||
#
|
||||
# Profiles:
|
||||
# api - API server only (requires external vLLM)
|
||||
# api-vllm - API + vLLM BusterX (GPU required)
|
||||
#
|
||||
# Required environment variables (set in deploy/.env file):
|
||||
# HF_TOKEN - Hugging Face token for model downloads
|
||||
# HF_CACHE_DIR - Cache directory for models
|
||||
# VIDEO_ANALYSIS_RUNS_DIR - Directory for analysis artifacts
|
||||
#
|
||||
# Naming Convention: didiAI-{module}-{service}
|
||||
#
|
||||
# Network:
|
||||
# Uses deploy_default network (shared with other modules)
|
||||
|
||||
networks:
|
||||
deploy_default:
|
||||
external: true
|
||||
|
||||
services:
|
||||
# ==========================================================================
|
||||
# vLLM Server - BusterX (Deepfake Detection Model)
|
||||
# ==========================================================================
|
||||
# Vision-language model for video deepfake detection
|
||||
# Runs on GPU 1 (Qwen3.5-35B-A3B uses GPU 0 via llm-inference module)
|
||||
# BusterX is based on Qwen2.5-VL-7B (~17GB VRAM with optimizations)
|
||||
vllm-buster:
|
||||
container_name: didiAI-video-vllm-buster
|
||||
image: vllm/vllm-openai:v0.8.5
|
||||
ports:
|
||||
- "54500:54500"
|
||||
networks:
|
||||
- deploy_default
|
||||
volumes:
|
||||
- ${HF_CACHE_DIR:-/cai2_ds_storage/hf_cache}:/root/.cache/huggingface
|
||||
environment:
|
||||
- HF_HOME=/root/.cache/huggingface
|
||||
- HUGGING_FACE_HUB_TOKEN=${HF_TOKEN}
|
||||
- CUDA_VISIBLE_DEVICES=1
|
||||
command: >
|
||||
--model l8cv/BusterX_plusplus
|
||||
--host 0.0.0.0
|
||||
--port 54500
|
||||
--served-model-name busterx
|
||||
--tensor-parallel-size 1
|
||||
--max-model-len 32768
|
||||
--gpu-memory-utilization 0.25
|
||||
--trust-remote-code
|
||||
--enable-prefix-caching
|
||||
--disable-log-requests
|
||||
deploy:
|
||||
resources:
|
||||
reservations:
|
||||
devices:
|
||||
- driver: nvidia
|
||||
device_ids: ['1']
|
||||
capabilities: [gpu]
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:54500/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 10
|
||||
start_period: 600s
|
||||
restart: unless-stopped
|
||||
profiles:
|
||||
- api-vllm
|
||||
|
||||
# ==========================================================================
|
||||
# Video Analysis API Server
|
||||
# ==========================================================================
|
||||
video-analysis-api:
|
||||
container_name: didiAI-video-api
|
||||
image: didiai-video-api
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: deploy/Dockerfile
|
||||
|
||||
ports:
|
||||
- "54600:54600"
|
||||
networks:
|
||||
- deploy_default
|
||||
|
||||
environment:
|
||||
# Server settings
|
||||
- VIDEO_ANALYSIS_HOST=0.0.0.0
|
||||
- VIDEO_ANALYSIS_PORT=54600
|
||||
# External URL for OpenAPI spec (REQUIRED)
|
||||
- VIDEO_ANALYSIS_EXTERNAL_URL=${VIDEO_ANALYSIS_EXTERNAL_URL}
|
||||
# vLLM connection (points to vllm-buster container)
|
||||
- VIDEO_ANALYSIS_VLLM_BASE_URL=${VIDEO_ANALYSIS_VLLM_BASE_URL:-http://didiAI-video-vllm-buster:54500}
|
||||
- VIDEO_ANALYSIS_VLLM_MODEL=${VIDEO_ANALYSIS_VLLM_MODEL:-busterx}
|
||||
- VIDEO_ANALYSIS_RUNS_DIR=${VIDEO_ANALYSIS_RUNS_DIR:-/app/runs}
|
||||
|
||||
# Optional tuning
|
||||
- VIDEO_ANALYSIS_FRAMES=${VIDEO_ANALYSIS_FRAMES:-16}
|
||||
- VIDEO_ANALYSIS_MAX_SIDE=${VIDEO_ANALYSIS_MAX_SIDE:-960}
|
||||
- VIDEO_ANALYSIS_JPEG_QUALITY=${VIDEO_ANALYSIS_JPEG_QUALITY:-85}
|
||||
- VIDEO_ANALYSIS_MAX_TOKENS=${VIDEO_ANALYSIS_MAX_TOKENS:-750}
|
||||
- VIDEO_ANALYSIS_TEMPERATURE=${VIDEO_ANALYSIS_TEMPERATURE:-0.000001}
|
||||
- VIDEO_ANALYSIS_REPETITION_PENALTY=${VIDEO_ANALYSIS_REPETITION_PENALTY:-1.05}
|
||||
|
||||
# Runtime config polling
|
||||
- VIDEO_ANALYSIS_DASHBOARD_URL=${VIDEO_ANALYSIS_DASHBOARD_URL:-http://didiAI-dashboard:51300}
|
||||
|
||||
# Semantic analysis settings
|
||||
- VIDEO_ANALYSIS_SEMANTIC_LLM_BASE_URL=${VIDEO_ANALYSIS_SEMANTIC_LLM_BASE_URL}
|
||||
- VIDEO_ANALYSIS_SEMANTIC_AGGREGATION_MODEL=${VIDEO_ANALYSIS_SEMANTIC_AGGREGATION_MODEL}
|
||||
- VIDEO_ANALYSIS_SEMANTIC_LLM_API_KEY=${VIDEO_ANALYSIS_SEMANTIC_LLM_API_KEY}
|
||||
|
||||
volumes:
|
||||
# Persist artifacts on the host (module-root runs/ folder)
|
||||
- ../runs:/app/runs
|
||||
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:54600/health')"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 20s
|
||||
|
||||
restart: unless-stopped
|
||||
profiles:
|
||||
- api
|
||||
- api-vllm
|
||||
|
||||
52
ai_platform/modules/video-analysis/deploy/nginx.conf
Normal file
52
ai_platform/modules/video-analysis/deploy/nginx.conf
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
upstream video_analysis_api {
|
||||
# With host networking, the API binds host:8007
|
||||
server 127.0.0.1:8007;
|
||||
keepalive 32;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
# Timeouts (video processing + vLLM may take time)
|
||||
proxy_connect_timeout 60s;
|
||||
proxy_send_timeout 300s;
|
||||
proxy_read_timeout 600s;
|
||||
|
||||
# Allow large video uploads
|
||||
client_max_body_size 500M;
|
||||
|
||||
# Disable buffering for large uploads / streaming
|
||||
proxy_buffering off;
|
||||
proxy_request_buffering off;
|
||||
|
||||
location /health {
|
||||
access_log off;
|
||||
proxy_pass http://video_analysis_api/health;
|
||||
proxy_http_version 1.1;
|
||||
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header Connection "";
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://video_analysis_api;
|
||||
proxy_http_version 1.1;
|
||||
|
||||
# Forward client info
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# Streaming friendliness (even if not currently used)
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header X-Accel-Buffering no;
|
||||
|
||||
proxy_cache off;
|
||||
chunked_transfer_encoding off;
|
||||
|
||||
# Request correlation
|
||||
proxy_set_header X-Request-ID $request_id;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
upstream video_analysis_api {
|
||||
server didiAI-video-api:8011;
|
||||
keepalive 32;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
proxy_connect_timeout ${NGINX_CONNECT_TIMEOUT};
|
||||
proxy_send_timeout ${NGINX_SEND_TIMEOUT};
|
||||
proxy_read_timeout ${NGINX_READ_TIMEOUT};
|
||||
|
||||
# Larger uploads (videos)
|
||||
client_max_body_size 500M;
|
||||
|
||||
location /health {
|
||||
access_log off;
|
||||
proxy_pass http://video_analysis_api/health;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://video_analysis_api;
|
||||
proxy_http_version 1.1;
|
||||
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
# SSE-friendly (safe even if you don't stream yet)
|
||||
proxy_set_header Connection '';
|
||||
proxy_set_header X-Accel-Buffering no;
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
chunked_transfer_encoding off;
|
||||
|
||||
proxy_set_header X-Request-ID $request_id;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue