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.
82 lines
2.4 KiB
Python
82 lines
2.4 KiB
Python
from fastapi import APIRouter, HTTPException, Depends
|
|
from fastapi.responses import FileResponse
|
|
from sqlalchemy.orm import Session
|
|
from pathlib import Path
|
|
|
|
from app.database import get_db
|
|
from app.models.project import Project
|
|
from app.services.edit_service import EditService
|
|
|
|
router = APIRouter(prefix="/projects", tags=["images"])
|
|
|
|
|
|
@router.get("/{project_id}/original")
|
|
def get_original_image(
|
|
project_id: int,
|
|
db: Session = Depends(get_db)
|
|
):
|
|
"""Get the original uploaded image"""
|
|
project = db.query(Project).filter(Project.id == project_id).first()
|
|
if not project:
|
|
raise HTTPException(status_code=404, detail="Project not found")
|
|
|
|
edit_service = EditService()
|
|
image_path = edit_service.get_original_image_path(project_id)
|
|
|
|
if not image_path.exists():
|
|
raise HTTPException(status_code=404, detail="Original image not found")
|
|
|
|
return FileResponse(
|
|
image_path,
|
|
media_type="image/png",
|
|
headers={"Cache-Control": "public, max-age=3600"}
|
|
)
|
|
|
|
|
|
@router.get("/{project_id}/current")
|
|
def get_current_image(
|
|
project_id: int,
|
|
db: Session = Depends(get_db)
|
|
):
|
|
"""Get the current edited image"""
|
|
project = db.query(Project).filter(Project.id == project_id).first()
|
|
if not project:
|
|
raise HTTPException(status_code=404, detail="Project not found")
|
|
|
|
edit_service = EditService()
|
|
image_path = edit_service.get_current_image_path(project_id)
|
|
|
|
if not image_path.exists():
|
|
raise HTTPException(status_code=404, detail="Current image not found")
|
|
|
|
return FileResponse(
|
|
image_path,
|
|
media_type="image/png",
|
|
headers={"Cache-Control": "no-cache"}
|
|
)
|
|
|
|
|
|
@router.get("/{project_id}/history/{edit_id}/result")
|
|
def get_edit_result(
|
|
project_id: int,
|
|
edit_id: int,
|
|
db: Session = Depends(get_db)
|
|
):
|
|
"""Get the result image from a specific edit"""
|
|
project = db.query(Project).filter(Project.id == project_id).first()
|
|
if not project:
|
|
raise HTTPException(status_code=404, detail="Project not found")
|
|
|
|
edit_service = EditService()
|
|
edit_dir = edit_service.get_edit_dir(project_id, edit_id)
|
|
result_path = edit_dir / "result.png"
|
|
|
|
if not result_path.exists():
|
|
raise HTTPException(status_code=404, detail="Edit result not found")
|
|
|
|
return FileResponse(
|
|
result_path,
|
|
media_type="image/png",
|
|
headers={"Cache-Control": "public, max-age=3600"}
|
|
)
|