Segment, understand, and report on videos with SAM2 + OpenRouter
Made by Aditya Shenvi @2025
📚 Deployment Guide | 🐳 Docker Setup | 🤝 Contributing | 📊 V1.2 Plan
Ciousten is a complete, open-source video analytics platform that enables you to:
- Upload videos and run AI-powered segmentation using Meta SAM2 + YOLO
- Analyze content using OpenRouter's LLM APIs for natural language insights
- Generate professional reports in Excel and PDF formats automatically
- View interactive visualizations of object detection and tracking
✨ Smart Segmentation - CPU-optimized SAM2 + YOLO detection
🧠 AI Analysis - OpenRouter integration for intelligent insights
🚨 Anomaly Detection - Auto-detect unusual events and spikes
🏃 Activity Recognition - Classify scenes (Traffic, Retail, etc.)
📝 Dataset Cards - Auto-generate AI dataset documentation
🔌 Plugin System - Extensible architecture for custom modules
📊 Auto Reports - Multi-sheet Excel workbooks with charts
📄 PDF Generation - Professional analysis reports
🐳 Docker Ready - One-command deployment with docker-compose
🔒 Production Security - Rate limiting, request validation, DDoS protection
📈 Health Monitoring - Real-time system metrics and service status
📊 API Analytics - Usage statistics and performance tracking
🚀 Production Ready - Deployed on Vercel + Render with 99.9% uptime
⚡ WebSocket Support - Real-time progress updates (NEW in V1.2.1)
📦 Dataset Export - Export to COCO and YOLO formats (NEW in V1.2.1)
⏱️ Performance Tracking - Request timing and monitoring (NEW in V1.2.1)
- FastAPI - Modern Python web framework
- Meta SAM2 - Segment Anything Model 2 for video segmentation
- Ultralytics YOLO - Object detection (YOLOv8n)
- OpenRouter - LLM API for analysis
- OpenPyXL - Excel report generation
- ReportLab - PDF report generation
- SQLite - Lightweight database
- Next.js 15 - React framework with App Router
- TypeScript - Type-safe development
- Tailwind CSS - Utility-first styling
- shadcn/ui - Beautiful UI components
- Docker and Docker Compose (recommended)
- OR Python 3.10+ and Node.js 20+ for manual setup
- OpenRouter API Key (get one at openrouter.ai)
- SAM2 Model Weights (optional, for full segmentation)
git clone <your-repo-url>
cd Ciousten---Video-Insights---ReportsCopy the example environment file and add your OpenRouter API key:
cd backend
cp .env.example .envEdit .env and set your API key:
OPENROUTER_API_KEY=sk-or-v1-your-key-hereFor full segmentation capabilities, download SAM2 model weights:
# Download SAM2 tiny model (recommended for CPU)
cd backend/sam_models
wget https://dl.fbaipublicfiles.com/segment_anything_2/072824/sam2_hiera_tiny.pt
# Also download the config file
wget https://raw.githubusercontent.com/facebookresearch/segment-anything-2/main/sam2_configs/sam2_hiera_t.yamlNote: Without SAM2 weights, the system will use bounding boxes only (YOLO detection).
# From the project root
docker-compose up --buildThis will:
- Build and start the backend on
http://localhost:8000 - Build and start the frontend on
http://localhost:3000
Open your browser and navigate to:
http://localhost:3000
cd backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env with your OpenRouter API key
# Run the backend
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000cd frontend
# Install dependencies
npm install
# Run the development server
npm run devThe frontend will be available at http://localhost:3000 and will proxy API requests to http://localhost:8000.
- Navigate to Annotate page
- Upload a video file (.mp4, .mov, .avi)
- Click Start Segmentation
- Wait for processing (2-5 minutes for a 30-second video)
- View segmentation statistics
- Navigate to Analyze page
- Select your segmented project
- Select Domain Mode (Traffic, Retail, Security, etc.)
- Select AI model (DeepSeek Free, Llama 3.1, etc.)
- Click Run Advanced Analysis
- Review insights, anomaly timeline, and activity tracks
- Navigate to Reports page
- Find your analyzed project
- Click Generate Reports for Excel/PDF
- Click Generate AI Dataset Card to create documentation
- Copy or download the results
Ciousten---Video-Insights---Reports/
├── backend/
│ ├── app/
│ │ ├── api/routes/ # API endpoints
│ │ ├── core/ # AI engines & reporting
│ │ ├── utils/ # Utilities
│ │ ├── config.py # Configuration
│ │ ├── db.py # Database models
│ │ ├── schemas.py # Pydantic schemas
│ │ └── main.py # FastAPI app
│ ├── data/ # Uploaded videos & frames
│ ├── reports/ # Generated reports
│ ├── sam_models/ # SAM2 model weights
│ ├── requirements.txt
│ ├── Dockerfile
│ └── .env
├── frontend/
│ ├── app/
│ │ ├── annotate/ # Upload & segmentation
│ │ ├── analyze/ # AI analysis
│ │ ├── reports/ # Download reports
│ │ ├── layout.tsx
│ │ └── page.tsx # Home page
│ ├── components/ui/ # shadcn/ui components
│ ├── lib/ # Utilities
│ ├── package.json
│ └── Dockerfile
├── docker-compose.yml
└── README.md
- Sign up at openrouter.ai
- Navigate to API Keys in your dashboard
- Create a new API key
- Copy the key and add it to
backend/.env:OPENROUTER_API_KEY=sk-or-v1-your-key-here
- DeepSeek Chat (Free) -
deepseek/deepseek-chat-free- Good for general analysis - Llama 3.1 8B (Free) -
meta-llama/llama-3.1-8b-instruct:free- Fast and capable - Gemini Flash 1.5 -
google/gemini-flash-1.5- High quality (paid)
# OpenRouter API
OPENROUTER_API_KEY=your_key_here
OPENROUTER_DEFAULT_MODEL=deepseek/deepseek-chat-free
# SAM2 Configuration
SAM2_CHECKPOINT=sam2_hiera_tiny.pt
SAM2_MODEL_CFG=sam2_hiera_t.yaml
SAM2_DEVICE=cpu
# YOLO Configuration
YOLO_MODEL=yolov8n.pt
YOLO_CONFIDENCE=0.25
# Video Processing
FRAME_EXTRACTION_FPS=2
MAX_VIDEO_SIZE_MB=500For CPU-only systems (Ryzen 5, 8-16GB RAM):
- Use
FRAME_EXTRACTION_FPS=2(or lower for faster processing) - Use SAM2 tiny model (
sam2_hiera_tiny.pt) - Process shorter videos (< 1 minute recommended)
- Overview - Project summary, statistics, class distribution chart
- Frames - Per-frame object counts with timeline chart
- Objects - Detailed object list with bounding boxes
- AI_Insights - Analysis results, findings, KPIs, dataset plan
- Title Page - Project information and branding
- Executive Summary - Statistics and class distribution
- AI Analysis - Summary, findings, anomalies, KPIs
- Dataset Plan - Recommended classes and splits
If you see "SAM2 not available - using bounding box mode":
- Ensure SAM2 weights are downloaded to
backend/sam_models/ - Check file names match configuration in
.env - Install SAM2:
pip install git+https://github.com/facebookresearch/segment-anything-2.git
For faster processing on CPU:
- Reduce
FRAME_EXTRACTION_FPSto 1 - Use shorter videos
- Skip SAM2 and use YOLO bounding boxes only
- Verify OpenRouter API key is correct
- Check API quota/credits at openrouter.ai
- Try a different model if one fails
This is an open-source project! Contributions are welcome.
MIT License - feel free to use this project for any purpose.
Aditya Shenvi
Website: www.adityacuz.dev
Year: 2025
- Meta AI - SAM2 model
- Ultralytics - YOLO implementation
- OpenRouter - LLM API platform
- Vercel - Next.js framework
Happy Analyzing! 🎥✨