File size: 22,060 Bytes
e49993e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 |
# MCP & Agent Integration for Laban Movement Analysis
This project provides comprehensive MCP (Model Context Protocol) integration and agent-ready APIs for professional movement analysis with pose estimation, AI action recognition, and automation capabilities.
## π Quick Start
### 1. Install All Dependencies
```bash
# Clone the repository
git clone https://github.com/[your-repo]/labanmovementanalysis
cd labanmovementanalysis
# Install core dependencies
pip install -r backend/requirements.txt
# Install MCP and enhanced features
pip install -r backend/requirements-mcp.txt
```
### 2. Start the MCP Server
```bash
# Start MCP server for AI assistants
python -m backend.mcp_server
```
### 3. Configure Your AI Assistant
Add to your Claude Desktop or other MCP-compatible assistant configuration:
```json
{
"mcpServers": {
"laban-movement-analysis": {
"command": "python",
"args": ["-m", "backend.mcp_server"],
"env": {
"PYTHONPATH": "/path/to/labanmovementanalysis"
}
}
}
}
```
## π οΈ Enhanced MCP Tools
### 1. `analyze_video`
Comprehensive video analysis with enhanced features including SkateFormer AI and multiple pose models.
**Parameters:**
- `video_path` (string): Path or URL to video (supports YouTube, Vimeo, local files)
- `model` (string, optional): Advanced pose model selection:
- **MediaPipe**: `mediapipe-lite`, `mediapipe-full`, `mediapipe-heavy`
- **MoveNet**: `movenet-lightning`, `movenet-thunder`
- **YOLO**: `yolo-v8-n/s/m/l`, `yolo-v11-n/s/m/l`
- `enable_visualization` (boolean, optional): Generate annotated video
- `include_keypoints` (boolean, optional): Include raw keypoint data
- `use_skateformer` (boolean, optional): Enable AI action recognition
**Examples:**
```
Analyze the dance video at https://youtube.com/watch?v=dQw4w9WgXcQ using SkateFormer AI
Analyze movement in video.mp4 using yolo-v11-s model with visualization
Process the exercise video with mediapipe-full and include keypoints
```
### 2. `get_analysis_summary`
Get human-readable summaries with enhanced AI insights.
**Parameters:**
- `analysis_id` (string): ID from previous analysis
**Enhanced Output Includes:**
- SkateFormer action recognition results
- Movement quality metrics (rhythm, complexity, symmetry)
- Temporal action segmentation
- Video source metadata (YouTube/Vimeo titles, etc.)
**Example:**
```
Get a detailed summary of analysis dance_2024-01-01T12:00:00 including AI insights
```
### 3. `list_available_models`
Comprehensive list of all 20+ pose estimation models with detailed specifications.
**Enhanced Model Information:**
- Performance characteristics (speed, accuracy, memory usage)
- Recommended use cases (real-time, research, production)
- Hardware requirements (CPU, GPU, memory)
- Keypoint specifications (17 COCO, 33 MediaPipe)
**Example:**
```
What pose estimation models are available for real-time processing?
List all YOLO v11 model variants with their specifications
```
### 4. `batch_analyze`
Enhanced batch processing with parallel execution and progress tracking.
**Parameters:**
- `video_paths` (array): List of video paths/URLs (supports mixed sources)
- `model` (string, optional): Pose estimation model for all videos
- `parallel` (boolean, optional): Enable parallel processing
- `use_skateformer` (boolean, optional): Enable AI analysis for all videos
- `output_format` (string, optional): Output format ("summary", "structured", "full")
**Enhanced Features:**
- Mixed source support (local files + YouTube URLs)
- Progress tracking and partial results
- Resource management and optimization
- Failure recovery and retry logic
**Examples:**
```
Analyze all dance videos in the playlist with SkateFormer AI
Batch process exercise videos using yolo-v11-s with parallel execution
```
### 5. `compare_movements`
Advanced movement comparison with AI-powered insights.
**Parameters:**
- `analysis_id1` (string): First analysis ID
- `analysis_id2` (string): Second analysis ID
- `comparison_type` (string, optional): Type of comparison ("basic", "detailed", "ai_enhanced")
**Enhanced Comparison Features:**
- SkateFormer action similarity analysis
- Movement quality comparisons (rhythm, complexity, symmetry)
- Temporal pattern matching
- Statistical significance testing
**Example:**
```
Compare the movement patterns between the two dance analyses with AI insights
Detailed comparison of exercise form between beginner and expert videos
```
### 6. `real_time_analysis` (New)
Start/stop real-time WebRTC analysis.
**Parameters:**
- `action` (string): "start" or "stop"
- `model` (string, optional): Real-time optimized model
- `stream_config` (object, optional): WebRTC configuration
**Example:**
```
Start real-time movement analysis using mediapipe-lite
```
### 7. `filter_videos_advanced` (New)
Advanced video filtering with AI-powered criteria.
**Parameters:**
- `video_paths` (array): List of video paths/URLs
- `criteria` (object): Enhanced filtering criteria including:
- Traditional LMA metrics (direction, intensity, fluidity)
- SkateFormer actions (dancing, jumping, etc.)
- Movement qualities (rhythm, complexity, symmetry)
- Temporal characteristics (duration, segment count)
**Example:**
```
Filter videos for high-energy dance movements with good rhythm
Find exercise videos with proper form (high fluidity and symmetry)
```
## π€ Enhanced Agent API
### Comprehensive Python Agent API
```python
from gradio_labanmovementanalysis import LabanMovementAnalysis
from gradio_labanmovementanalysis.agent_api import (
LabanAgentAPI,
PoseModel,
MovementDirection,
MovementIntensity,
analyze_and_summarize
)
# Initialize with all features enabled
analyzer = LabanMovementAnalysis(
enable_skateformer=True,
enable_webrtc=True,
enable_visualization=True
)
agent_api = LabanAgentAPI(analyzer=analyzer)
```
### Advanced Analysis Workflows
```python
# YouTube video analysis with AI
result = agent_api.analyze(
"https://youtube.com/watch?v=...",
model=PoseModel.YOLO_V11_S,
use_skateformer=True,
generate_visualization=True
)
# Enhanced batch processing
results = agent_api.batch_analyze(
["video1.mp4", "https://youtube.com/watch?v=...", "https://vimeo.com/..."],
model=PoseModel.YOLO_V11_S,
parallel=True,
use_skateformer=True
)
# AI-powered movement filtering
filtered = agent_api.filter_by_movement_advanced(
video_paths,
skateformer_actions=["dancing", "jumping"],
movement_qualities={"rhythm": 0.8, "complexity": 0.6},
traditional_criteria={
"direction": MovementDirection.UP,
"intensity": MovementIntensity.HIGH,
"min_fluidity": 0.7
}
)
# Real-time analysis control
agent_api.start_realtime_analysis(model=PoseModel.MEDIAPIPE_LITE)
live_metrics = agent_api.get_realtime_metrics()
agent_api.stop_realtime_analysis()
```
### Enhanced Quick Functions
```python
from gradio_labanmovementanalysis import (
quick_analyze_enhanced,
analyze_and_summarize_with_ai,
compare_videos_detailed
)
# Enhanced analysis with AI
data = quick_analyze_enhanced(
"https://youtube.com/watch?v=...",
model="yolo-v11-s",
use_skateformer=True
)
# AI-powered summary
summary = analyze_and_summarize_with_ai(
"dance_video.mp4",
include_skateformer=True,
detail_level="comprehensive"
)
# Detailed video comparison
comparison = compare_videos_detailed(
"video1.mp4",
"video2.mp4",
include_ai_analysis=True
)
```
## π Enhanced Gradio 5 Agent Features
### Comprehensive API Endpoints
The unified Gradio 5 app exposes these endpoints optimized for agents:
1. **`/analyze_standard`** - Basic LMA analysis
2. **`/analyze_enhanced`** - Advanced analysis with all features
3. **`/analyze_agent`** - Agent-optimized structured output
4. **`/batch_analyze`** - Efficient multiple video processing
5. **`/filter_videos`** - Movement-based filtering
6. **`/compare_models`** - Model performance comparison
7. **`/real_time_start`** - Start WebRTC real-time analysis
8. **`/real_time_stop`** - Stop WebRTC real-time analysis
### Enhanced Gradio Client Usage
```python
from gradio_client import Client
# Connect to unified demo
client = Client("http://localhost:7860")
# Enhanced single analysis
result = client.predict(
video_input="https://youtube.com/watch?v=...",
model="yolo-v11-s",
enable_viz=True,
use_skateformer=True,
include_keypoints=False,
api_name="/analyze_enhanced"
)
# Agent-optimized batch processing
batch_results = client.predict(
files=["video1.mp4", "video2.mp4"],
model="yolo-v11-s",
api_name="/batch_analyze"
)
# Advanced movement filtering
filtered_results = client.predict(
files=video_list,
direction_filter="up",
intensity_filter="high",
fluidity_threshold=0.7,
expansion_threshold=0.5,
api_name="/filter_videos"
)
# Model comparison analysis
comparison = client.predict(
video="test_video.mp4",
model1="mediapipe-full",
model2="yolo-v11-s",
api_name="/compare_models"
)
```
## π Enhanced Output Formats
### AI-Enhanced Summary Format
```
π Movement Analysis Summary for "Dance Performance"
Source: YouTube (10.5 seconds, 30fps)
Model: YOLO-v11-S with SkateFormer AI
π Traditional LMA Metrics:
β’ Primary direction: up (65% of frames)
β’ Movement intensity: high (80% of frames)
β’ Average speed: fast (2.3 units/frame)
β’ Fluidity score: 0.85/1.00 (very smooth)
β’ Expansion score: 0.72/1.00 (moderately extended)
π€ SkateFormer AI Analysis:
β’ Detected actions: dancing (95% confidence), jumping (78% confidence)
β’ Movement qualities:
- Rhythm: 0.89/1.00 (highly rhythmic)
- Complexity: 0.76/1.00 (moderately complex)
- Symmetry: 0.68/1.00 (slightly asymmetric)
- Smoothness: 0.85/1.00 (very smooth)
- Energy: 0.88/1.00 (high energy)
β±οΈ Temporal Analysis:
β’ 7 movement segments identified
β’ Average segment duration: 1.5 seconds
β’ Transition quality: smooth (0.82/1.00)
π― Overall Assessment: Excellent dance performance with high energy,
good rhythm, and smooth transitions. Slightly asymmetric but shows
advanced movement complexity.
```
### Enhanced Structured Format
```json
{
"success": true,
"video_metadata": {
"source": "youtube",
"title": "Dance Performance",
"duration": 10.5,
"platform_id": "dQw4w9WgXcQ"
},
"model_info": {
"pose_model": "yolo-v11-s",
"ai_enhanced": true,
"skateformer_enabled": true
},
"lma_metrics": {
"direction": "up",
"intensity": "high",
"speed": "fast",
"fluidity": 0.85,
"expansion": 0.72
},
"skateformer_analysis": {
"actions": [
{"type": "dancing", "confidence": 0.95, "duration": 8.2},
{"type": "jumping", "confidence": 0.78, "duration": 2.3}
],
"movement_qualities": {
"rhythm": 0.89,
"complexity": 0.76,
"symmetry": 0.68,
"smoothness": 0.85,
"energy": 0.88
},
"temporal_segments": 7,
"transition_quality": 0.82
},
"performance_metrics": {
"processing_time": 12.3,
"frames_analyzed": 315,
"keypoints_detected": 24
}
}
```
### Comprehensive JSON Format
Complete analysis including frame-by-frame data, SkateFormer attention maps, movement trajectories, and statistical summaries.
## ποΈ Enhanced Architecture
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AI Assistant Integration β
β (Claude, GPT, Local Models via MCP) β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββ
β MCP Server β
β βββββββββββββββ βββββββββββββββ ββββββββββββββββββββββββββββ
β β Video β β Enhanced β β Real-time ββ
β β Analysis β β Batch β β WebRTC ββ
β β Tools β β Processing β β Analysis ββ
β βββββββββββββββ βββββββββββββββ ββββββββββββββββββββββββββββ
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββ
β Enhanced Agent API Layer β
β βββββββββββββββ βββββββββββββββ ββββββββββββββββββββββββββββ
β β Movement β β AI-Enhanced β β Advanced ββ
β β Filtering β β Comparisons β β Workflows ββ
β βββββββββββββββ βββββββββββββββ ββββββββββββββββββββββββββββ
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββ
β Core Analysis Engine β
β β
β πΉ Video Input π€ Pose Models π SkateFormer AI β
β βββββββββββββββ βββββββββββββββ ββββββββββββββββββββββββ
β βLocal Files β βMediaPipe(3) β β Action Recognition ββ
β βYouTube URLs β βMoveNet(2) β βMovement Qualities ββ
β βVimeo URLs β βYOLO(8) β βTemporal Segments ββ
β βDirect URLs β β β βAttention Analysis ββ
β βββββββββββββββ βββββββββββββββ ββββββββββββββββββββββββ
β β
β π LMA Engine πΉ WebRTC π¨ Visualization β
β βββββββββββββββ βββββββββββββββ ββββββββββββββββββββββββ
β βDirection β βLive Camera β β Pose Overlays ββ
β βIntensity β βReal-time β β Motion Trails ββ
β βSpeed/Flow β βSub-100ms β β Metric Displays ββ
β βExpansion β βAdaptive FPS β β AI Visualizations ββ
β βββββββββββββββ βββββββββββββββ ββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
## π Advanced Agent Workflows
### 1. Comprehensive Dance Analysis Pipeline
```python
# Multi-source dance video analysis
videos = [
"local_dance.mp4",
"https://youtube.com/watch?v=dance1",
"https://vimeo.com/dance2"
]
# Batch analyze with AI
results = agent_api.batch_analyze(
videos,
model=PoseModel.YOLO_V11_S,
use_skateformer=True,
parallel=True
)
# Filter for high-quality performances
excellent_dances = agent_api.filter_by_movement_advanced(
videos,
skateformer_actions=["dancing"],
movement_qualities={
"rhythm": 0.8,
"complexity": 0.7,
"energy": 0.8
},
traditional_criteria={
"intensity": MovementIntensity.HIGH,
"min_fluidity": 0.75
}
)
# Generate comprehensive report
report = agent_api.generate_analysis_report(
results,
include_comparisons=True,
include_recommendations=True
)
```
### 2. Real-time Exercise Form Checker
```python
# Start real-time analysis
agent_api.start_realtime_analysis(
model=PoseModel.MEDIAPIPE_FULL,
enable_skateformer=True
)
# Monitor form in real-time
while exercise_in_progress:
metrics = agent_api.get_realtime_metrics()
# Check form quality
if metrics["fluidity"] < 0.6:
send_feedback("Improve movement smoothness")
if metrics["symmetry"] < 0.7:
send_feedback("Balance left and right movements")
time.sleep(0.1) # 10Hz monitoring
# Stop and get session summary
agent_api.stop_realtime_analysis()
session_summary = agent_api.get_session_summary()
```
### 3. Movement Pattern Research Workflow
```python
# Large-scale analysis for research
research_videos = get_research_dataset()
# Batch process with comprehensive analysis
results = agent_api.batch_analyze(
research_videos,
model=PoseModel.YOLO_V11_L, # High accuracy for research
use_skateformer=True,
include_keypoints=True, # Full data for research
parallel=True
)
# Statistical analysis
patterns = agent_api.extract_movement_patterns(
results,
pattern_types=["temporal", "spatial", "quality"],
clustering_method="hierarchical"
)
# Generate research insights
insights = agent_api.generate_research_insights(
patterns,
include_visualizations=True,
statistical_tests=True
)
```
## π§ Advanced Configuration & Customization
### Environment Variables
```bash
# Core configuration
export LABAN_DEFAULT_MODEL="mediapipe-full"
export LABAN_CACHE_DIR="/path/to/cache"
export LABAN_MAX_WORKERS=4
# Enhanced features
export LABAN_ENABLE_SKATEFORMER=true
export LABAN_ENABLE_WEBRTC=true
export LABAN_SKATEFORMER_MODEL_PATH="/path/to/skateformer"
# Performance tuning
export LABAN_GPU_ENABLED=true
export LABAN_BATCH_SIZE=8
export LABAN_REALTIME_FPS=30
# Video download configuration
export LABAN_YOUTUBE_QUALITY="720p"
export LABAN_MAX_DOWNLOAD_SIZE="500MB"
export LABAN_TEMP_DIR="/tmp/laban_downloads"
```
### Custom MCP Tools
```python
# Add custom MCP tool
from backend.mcp_server import server
@server.tool("custom_movement_analysis")
async def custom_analysis(
video_path: str,
custom_params: dict
) -> dict:
"""Custom movement analysis with specific parameters."""
# Your custom implementation
return results
# Register enhanced filters
@server.tool("filter_by_sport_type")
async def filter_by_sport(
videos: list,
sport_type: str
) -> dict:
"""Filter videos by detected sport type using SkateFormer."""
# Implementation using SkateFormer sport classification
return filtered_videos
```
### WebRTC Configuration
```python
# Custom WebRTC configuration
webrtc_config = {
"video_constraints": {
"width": 1280,
"height": 720,
"frameRate": 30
},
"processing_config": {
"max_latency_ms": 100,
"quality_adaptation": True,
"model_switching": True
}
}
agent_api.configure_webrtc(webrtc_config)
```
## π€ Contributing to Agent Features
### Adding New MCP Tools
1. Define tool in `backend/mcp_server.py`
2. Implement core logic in agent API
3. Add comprehensive documentation
4. Include usage examples
5. Write integration tests
### Extending Agent API
1. Add methods to `LabanAgentAPI` class
2. Ensure compatibility with existing workflows
3. Add structured output formats
4. Include error handling and validation
5. Update documentation
### Enhancing SkateFormer Integration
1. Extend action recognition types
2. Add custom movement quality metrics
3. Implement temporal analysis features
4. Add visualization components
5. Validate with research datasets
## π Resources & References
- [MCP Specification](https://github.com/anthropics/mcp)
- [SkateFormer Research Paper](https://kaist-viclab.github.io/SkateFormer_site/)
- [Gradio 5 Documentation](https://www.gradio.app/docs)
- [Unified Demo Application](demo/app.py)
- [Core Component Code](backend/gradio_labanmovementanalysis/)
## π― Production Deployment
### Docker Deployment
```dockerfile
FROM python:3.9-slim
COPY . /app
WORKDIR /app
RUN pip install -r backend/requirements.txt
RUN pip install -r backend/requirements-mcp.txt
EXPOSE 7860 8080
CMD ["python", "-m", "backend.mcp_server"]
```
### Kubernetes Configuration
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: laban-mcp-server
spec:
replicas: 3
selector:
matchLabels:
app: laban-mcp
template:
metadata:
labels:
app: laban-mcp
spec:
containers:
- name: mcp-server
image: laban-movement-analysis:latest
ports:
- containerPort: 8080
env:
- name: LABAN_MAX_WORKERS
value: "2"
- name: LABAN_ENABLE_SKATEFORMER
value: "true"
```
---
**π€ Transform your AI assistant into a movement analysis expert with comprehensive MCP integration and agent-ready automation.** |