This commit implements a full-stack AI photo editing application that allows users to regenerate only selected areas of images using AI. Features implemented: - Frontend (React + Fabric.js): * Interactive canvas with selection tools (rectangle, ellipse, lasso) * Real-time selection preview and editing * Mode toggle (A: patch only, B: patch + context) * Feather slider for edge blending (0-50px) * Prompt input for AI instructions * Edit history viewer with revert capability * Responsive UI with dark theme - Backend (FastAPI): * RESTful API for projects and edits * SQLite database for metadata storage * Image processing pipeline with PIL/OpenCV * AI provider interface (pluggable) * Support for OpenAI, Stability AI, and mock providers * Feathered alpha blending for smooth compositing * Complete edit history tracking * File-based storage for images and edits - Image Processing: * Patch extraction from bounding boxes * Mask generation for all selection types * Feathered edge blending * Patch compositing back to full image * No pixels modified outside selection * All edits reversible - Infrastructure: * Docker Compose orchestration * Production and development configurations * Nginx reverse proxy for frontend * Hot-reload support for development * Volume persistence for data Architecture follows specification exactly: - Only selected regions are regenerated - Full image pixels preserved outside mask - Two-mode operation (cost vs quality) - Complete edit history and reversibility - Self-hosted with external AI API calls All components are fully functional and ready for deployment.
76 lines
1.4 KiB
Python
76 lines
1.4 KiB
Python
from pydantic import BaseModel, EmailStr
|
|
from typing import Optional, List, Dict, Any
|
|
from datetime import datetime
|
|
|
|
|
|
# User schemas
|
|
class UserCreate(BaseModel):
|
|
email: EmailStr
|
|
password: str
|
|
|
|
|
|
class UserResponse(BaseModel):
|
|
id: int
|
|
email: str
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Project schemas
|
|
class ProjectCreate(BaseModel):
|
|
name: str
|
|
|
|
|
|
class ProjectResponse(BaseModel):
|
|
id: int
|
|
user_id: int
|
|
name: str
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Edit schemas
|
|
class EditRequest(BaseModel):
|
|
prompt: str
|
|
mode: str = "A" # "A" or "B"
|
|
selection_type: str # "rectangle", "ellipse", "lasso"
|
|
bbox: Dict[str, int] # {x, y, width, height}
|
|
feather_px: int = 0
|
|
selection_data: Optional[Dict[str, Any]] = None
|
|
|
|
|
|
class EditResponse(BaseModel):
|
|
id: int
|
|
project_id: int
|
|
created_at: datetime
|
|
mode: str
|
|
prompt: str
|
|
selection_type: str
|
|
bbox_json: str
|
|
feather_px: int
|
|
ai_provider: str
|
|
status: str
|
|
error_message: Optional[str] = None
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Image upload
|
|
class UploadResponse(BaseModel):
|
|
project_id: int
|
|
original_url: str
|
|
current_url: str
|
|
|
|
|
|
# Generic responses
|
|
class StatusResponse(BaseModel):
|
|
status: str
|
|
message: Optional[str] = None
|
|
data: Optional[Any] = None
|