Skip to main content

PSD layer converter and processor

Project description

๐ŸŽจ psdfy

Convert any image into an editable Adobe Photoshop file with AI-powered layer segmentation.

Upload a photo, and psdfy automatically detects objects, creates separate layers for each one, and exports a ready-to-edit .psd file. Perfect for designers, photographers, and anyone who needs to work with layered images.


โœจ Features

  • ๐Ÿค– AI-Powered Segmentation - Uses SAM 2 to automatically detect and separate objects
  • ๐Ÿ“ฆ Multi-Layer PSD Export - Each detected object becomes an editable layer
  • ๐ŸŽฏ Text-Prompted Detection - Optional GroundingDINO integration for specific object detection
  • ๐ŸŒ Web UI - Simple browser interface for uploading and downloading
  • ๐Ÿ’ป CLI Tool - Command-line interface for automation and scripting
  • โ˜๏ธ Cloud Ready - S3 storage backend support for cloud deployments
  • ๐Ÿณ Docker Support - CPU and GPU Docker images included
  • โšก Fast Processing - Optimized for 1080p images (< 5 seconds on GPU)

๐Ÿš€ Quick Start

Option 1: Web UI (Easiest)

# Install psdfy
pip install psdfy

# Run installation wizard
psdfy install

# Start the service
psdfy start

# Open browser and go to http://localhost:3457

Then:

  1. Login with password (default: 123456)
  2. Upload an image
  3. Click "Convert to PSD"
  4. Download your layered PSD file

Option 1b: Lightweight Install (GroundingDINO Only)

If you want to set up psdfy without downloading the large SAM2 model weights (2GB+), use:

# Install psdfy
pip install psdfy

# Run installation wizard without SAM2 weights
psdfy install --no-weights

# Start the service
psdfy start

What you get with --no-weights:

  • โœ… GroundingDINO model (text-prompt based detection)
  • โœ… Web UI with "Text Prompt" mode only
  • โŒ SAM2 automatic segmentation (requires full install)
  • โŒ "Auto" mode in the UI (hidden)

When to use this:

  • Setting up on servers with limited bandwidth or disk space
  • Testing the UI before committing to full installation
  • Running text-prompt-only workflows
  • Downloading SAM2 weights later on a separate machine

Upgrading to full install:

# Download SAM2 weights later
psdfy install

This will add SAM2 support and enable the "Auto" mode in the UI.

Note: The combined "GroundingDINO + SAM2" refinement mode is coming soon.

Option 2: Docker (Recommended)

# CPU version
docker build -f docker/Dockerfile -t psdfy:latest .
docker run -p 3456:3456 -p 3457:3457 psdfy:latest

# GPU version (CUDA 12.1)
docker build -f docker/Dockerfile.gpu -t psdfy:gpu .
docker run --gpus all -p 3456:3456 -p 3457:3457 psdfy:gpu

Option 3: Python API

from app.utils.io import load_image
from app.services.segmenter import get_segmenter
from app.services.psd_writer import get_psd_writer

# Load image
image_array, (width, height), fmt = load_image(image_bytes)

# Segment objects
segmenter = get_segmenter()
masks = segmenter.segment_auto(image_array)

# Write PSD
psd_writer = get_psd_writer()
psd_bytes = psd_writer.write_psd(layers, width, height)

๐Ÿ“– Usage

Web UI

  1. Login - Enter password (default: 123456)
  2. Upload - Drag & drop or click to select image
  3. Configure - Choose segmentation mode:
    • Automatic - Detects all objects
    • Text Prompt - Specify objects (e.g., "person . table . book")
  4. Convert - Click "Convert to PSD"
  5. Download - Get your layered PSD file

CLI Commands

# Show version and system info
psdfy version

# Install/configure psdfy
psdfy install --password mypassword

# Start API and UI servers
psdfy start

# Stop servers
psdfy stop

# Diagnose and repair installation
psdfy fix --dry-run

# Update to latest version
psdfy update

# Check for issues
psdfy fix --redownload-weights

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Browser (Web UI)                      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚ (Cookie Auth)
                         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚         GUI Web Server (Port 3457)                       โ”‚
โ”‚  - Login page                                            โ”‚
โ”‚  - Upload interface                                      โ”‚
โ”‚  - Server-side proxy to API                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚ (X-Session-Id, X-Client-Signature)
                         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚         Proxy API Server (Port 3456)                     โ”‚
โ”‚  - /convert - Image to PSD conversion                   โ”‚
โ”‚  - /files - Download results                            โ”‚
โ”‚  - /auth - Session management                           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ–ผ                โ–ผ                โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ SAM 2  โ”‚      โ”‚ Mask   โ”‚      โ”‚ PSD    โ”‚
    โ”‚ Loader โ”‚      โ”‚ Post-  โ”‚      โ”‚ Writer โ”‚
    โ”‚        โ”‚      โ”‚ processโ”‚      โ”‚        โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ› ๏ธ Development

Setup

# Clone repository
git clone https://github.com/Mattel-Limbo/psdfy.git
cd psdfy

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in development mode
pip install -e ".[dev]"

Code Quality

# Run linter
ruff check app psdfy tests

# Format code
black app psdfy tests

# Type checking
mypy --strict app psdfy

# Run tests
pytest tests/ -v

Project Structure

psdfy/
โ”œโ”€โ”€ app/                    # FastAPI application
โ”‚   โ”œโ”€โ”€ api_app/           # Proxy API server (port 3456)
โ”‚   โ”œโ”€โ”€ ui_app/            # Web UI server (port 3457)
โ”‚   โ”œโ”€โ”€ services/          # Business logic (segmentation, PSD writing, etc.)
โ”‚   โ”œโ”€โ”€ models/            # AI model loaders (SAM 2, GroundingDINO)
โ”‚   โ”œโ”€โ”€ storage/           # Storage backends (local, S3)
โ”‚   โ””โ”€โ”€ utils/             # Helper utilities
โ”œโ”€โ”€ psdfy/                 # CLI tool
โ”‚   โ”œโ”€โ”€ commands/          # CLI commands (install, start, stop, etc.)
โ”‚   โ”œโ”€โ”€ config.py          # Configuration management
โ”‚   โ””โ”€โ”€ weights.py         # Model weights downloader
โ”œโ”€โ”€ web/                   # Web UI assets
โ”‚   โ””โ”€โ”€ templates/         # HTML templates
โ”œโ”€โ”€ tests/                 # Test suite
โ”œโ”€โ”€ docker/                # Docker configurations
โ””โ”€โ”€ scripts/               # Utility scripts (benchmarking, etc.)

๐Ÿ“‹ Requirements

  • Python: 3.11 or higher
  • RAM: 8GB minimum (16GB recommended)
  • GPU (optional): NVIDIA GPU with CUDA 12.1+ for faster processing
  • Disk: 5GB for model weights

๐Ÿ”ง Configuration

Configuration is stored in ~/.psdfy/config.toml:

[app]
host = "localhost"
api_port = 3456
ui_port = 3457
device = "cpu"  # or "cuda", "mps"

[auth]
ui_password_hash = "..."
client_secret = "..."

[models]
sam2_weights_path = "~/.psdfy/weights/sam2_hiera_large.pt"
enable_sam2 = true                                          # Set to false with --no-weights
dino_weights_path = "~/.psdfy/weights/groundingdino_swint_ogc.pth"
enable_grounding_dino = true                                # Always true after install

Model Availability:

The UI automatically detects which models are available and shows only the corresponding segmentation modes:

Install Command enable_sam2 enable_grounding_dino UI Modes Available
psdfy install true true Auto (SAM 2), Text Prompt
psdfy install --no-weights false true Text Prompt only

To check available modes programmatically, call GET /capabilities:

curl http://localhost:3456/api/capabilities

Response:

{
  "modes": ["auto", "prompt"],
  "default_mode": "auto",
  "sam2_available": true,
  "dino_available": true
}

๐Ÿ› Troubleshooting

Port Already in Use

# Change ports
psdfy start --api-port 3500 --ui-port 3501

Model Weights Not Found

# Re-download weights
psdfy fix --redownload-weights

Reset Password

# Reset to default (123456)
psdfy fix --reset-password

Check System Health

# Run diagnostics
psdfy fix --dry-run

๐Ÿ“Š Performance

Resolution GPU (RTX 3080) CPU (i7-12700)
512x512 ~0.5s ~3s
1080x1080 ~1.5s ~8s
2160x2160 ~4s ~20s

๐Ÿ“ API Examples

Convert Image (cURL)

# Get session
SESSION=$(curl -X POST http://localhost:3456/auth/client-signature \
  -H "Content-Type: application/json" \
  -d '{"clientSecret":"your-secret"}' | jq -r '.sessionId')

# Convert image
curl -X POST http://localhost:3456/convert \
  -H "X-Session-Id: $SESSION" \
  -H "X-Client-Signature: your-signature" \
  -F "file=@image.jpg" \
  -F "mode=auto" \
  -o output.psd

Convert Image (Python)

import requests

# Get session
response = requests.post(
    "http://localhost:3456/auth/client-signature",
    json={"clientSecret": "your-secret"}
)
session_id = response.json()["sessionId"]

# Convert image
with open("image.jpg", "rb") as f:
    response = requests.post(
        "http://localhost:3456/convert",
        headers={
            "X-Session-Id": session_id,
            "X-Client-Signature": "your-signature"
        },
        files={"file": f},
        data={"mode": "auto"}
    )

# Save PSD
with open("output.psd", "wb") as f:
    f.write(response.content)

๐Ÿ“„ License

MIT License - see LICENSE file for details


๐Ÿค Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“ž Support


๐ŸŽฏ Roadmap

  • Batch processing support
  • Advanced layer ordering heuristics
  • Real-time preview in browser
  • Multi-user support with API keys
  • Webhook notifications
  • Custom model fine-tuning

Made with โค๏ธ for designers and developers

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

psdfy-0.3.2.tar.gz (74.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

psdfy-0.3.2-py3-none-any.whl (76.4 kB view details)

Uploaded Python 3

File details

Details for the file psdfy-0.3.2.tar.gz.

File metadata

  • Download URL: psdfy-0.3.2.tar.gz
  • Upload date:
  • Size: 74.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for psdfy-0.3.2.tar.gz
Algorithm Hash digest
SHA256 b13569bad99ab11bbf0f0071b5c14c686f796ef7c4ca9d6c53bf37fd176d0bd5
MD5 8fbc4ea59431fb73ae3a115cea823bd7
BLAKE2b-256 d945cbb8c8ecf3f8012ebf2dd87b60404ea55dbc75d9d502904eddfd8de37f0c

See more details on using hashes here.

File details

Details for the file psdfy-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: psdfy-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 76.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for psdfy-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4d48a0bad871ac81525fa4ba6fcda07760219628bf2e8e69471c0d694e46fa3e
MD5 749184cede949fba2a7445c3953b4756
BLAKE2b-256 7ab87d9eba964f6557df2d7e835a21a9e0db5039f207f75394a16250db463d4b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page