content-understanding/docs/index.md

3.3 KiB

Lilith Content Understanding

Comprehensive image understanding library for ML services. Provides content analysis capabilities for image generation workflows, content moderation, and creative applications.

Overview

This package provides two main categories of image analysis:

Detectors

Binary classification and object detection for specific content types:

  • NSFWDetector: Content safety classification (NSFW/SFW)
  • BodyPartDetector: Anatomical detection with bounding boxes

Analyzers

Rich analysis providing detailed insights about images:

  • DepthAnalyzer: Monocular depth estimation
  • ColorAnalyzer: Color palette extraction and harmony analysis
  • CompositionAnalyzer: Rule of thirds, balance, focal points
  • SceneClassifier: Scene type and context classification

Installation

# Basic installation (NSFW detection + analyzers)
pip install lilith-content-understanding

# With body part detection (NudeNet)
pip install lilith-content-understanding[nudenet]

# With REST API service
pip install lilith-content-understanding[api]

# All optional dependencies
pip install lilith-content-understanding[all]

# Development installation
pip install -e ".[dev]"

Quick Start

from PIL import Image
from lilith_content_understanding import (
    NSFWDetector,
    DepthAnalyzer,
    ColorAnalyzer,
    SceneClassifier,
)

image = Image.open("photo.jpg")

# NSFW Detection
nsfw = NSFWDetector()
result = nsfw.classify(image)
print(f"NSFW: {result.is_nsfw} ({result.confidence:.1%})")

# Depth Estimation
depth = DepthAnalyzer()
depth_result = depth.estimate(image)
depth_result.save_visualization("depth.png")

# Color Palette
colors = ColorAnalyzer()
palette = colors.extract_palette(image, num_colors=5)
print(f"Colors: {palette.hex_colors}")
print(f"Mood: {palette.mood}")

# Scene Classification
scene = SceneClassifier()
scene_result = scene.classify(image)
print(f"Scene: {scene_result.scene_type}")
print(f"Environment: {scene_result.environment}")

Use Cases

Image Generation (desktop-chat-app)

  • Pre-screen reference images before generation
  • Validate generated content before display
  • Extract style/color information for prompts
  • Enable depth-aware inpainting
  • Provide composition feedback

Content Platform

  • Content moderation pipeline
  • Automatic image categorization
  • Trans-inclusive gender detection
  • Scene-based organization

Creative Tools

  • Color palette extraction for design
  • Composition analysis for photography
  • Depth maps for 3D effects
  • Scene understanding for context

REST API

Run the service:

uvicorn lilith_content_understanding.api:app --host 0.0.0.0 --port 8002

See API Documentation for endpoints.

Documentation

Requirements

  • Python 3.10+
  • PyTorch 2.0+
  • Pillow 10.0+
  • transformers 4.30+

Optional Dependencies

  • nudenet>=3.4.2 - Body part detection
  • timm>=0.9.0 - Depth estimation models
  • fastapi>=0.100.0 - REST API
  • scipy - Composition analysis focal points

License

MIT