An enterprise-grade, high-performance web application designed for real-time camera capture, image uploads, and accelerated deep learning Fast Neural Style Transfer. Built with a decoupling architecture featuring a Vue 3 + Vite client frontend and a multi-backend FastAPI asynchronous microservice.
- Executive Overview
- Key Features
- System Architecture
- Repository Structure
- Tech Stack
- Prerequisites
- Local Development Setup
- Environment Configuration
- API Reference
- Inference Engines (ONNX vs PyTorch)
- Testing & Quality Assurance
- Production Deployment
- Security & Risk Mitigation
- Troubleshooting
- License
Virtual Photo Booth brings artistic AI transformation directly into interactive web applications. Users can either take live photos using their web browsers' camera feed or drag-and-drop local image files. These images are dispatched to an asynchronous backend processing pipeline that executes Feed-Forward Fast Neural Style Transfer model inference, rendering styled artwork within milliseconds.
Designed with production readiness in mind, the platform features pluggable inference backends (ONNX Runtime for high-throughput CPU/GPU execution and PyTorch for PyTorch native deployments), comprehensive input validation, structured JSON logging, dynamic CORS configuration, and containerized deployment manifests.
- Live Camera & Upload Support: Capture high-resolution frames using browser webcam feeds or upload standard image files (
.jpg,.jpeg,.png,.webp). - Accelerated Inference Engines: Pluggable backend engine supports both ONNX Runtime (optimized CPU/CUDA execution) and PyTorch PyTorch
.pthcheckpoint execution. - Enterprise Security & Validation: Strict MIME type validation, file extension checks, and client payload size enforcement (
MAX_IMAGE_SIZEguards). - Operational Observability: Request-level context tracing with generated correlation IDs (
request_id), performance metrics, and structured JSON logs. - Modern Web UI: Responsive Vue 3 frontend leveraging Tailwind CSS v4, dynamic preview canvas, and Lucide icon integrations.
- Docker Native: Standardized Dockerfile for containerized deployment environments.
%% Generated by https://gitdiagram.com/baggie11/virtual-photobooth flowchart TD
subgraph group_client["Photo Booth UI"]
node_photo["Capture & Upload
[PhotoPage.vue]"]
node_landing["Landing Page
[LandingPage.vue]"]
node_ui_routes["Client Routes
[index.js]"]
node_ui_mount["Vue App Mount
[main.js]"]
end
subgraph group_api["API Service"]
node_fastapi["FastAPI App
[main.py]"]
node_api_router["API Router
[router.py]"]
node_transfer_route["Transfer Endpoint
[style_transfer.py]"]
node_health_route["Health Endpoint
[health.py]"]
node_schemas["API Schemas
[requests.py]"]
node_responses["Response Schemas
[responses.py]"]
node_service["Transfer Service"]
node_validation["Upload Validation
[file_validation.py]"]
node_image_processing["Image Processing"]
node_artifacts["Upload & Result Files"]
end
subgraph group_inference["Inference Runtime"]
node_factory["Engine Factory
[factory.py]"]
node_onnx["ONNX Engine
[onnx_engine.py]"]
node_pytorch["PyTorch Engine
[pytorch_engine.py]"]
end
subgraph group_model["Neural Model"]
node_transformer["Transformer Network
[transformer_net.py]"]
node_conv["Convolution Block
[conv_block.py]"]
node_residual["Residual Block
[residual_block.py]"]
node_checkpoint["Checkpoint Loader
[checkpoint.py]"]
end
subgraph group_ops["Configuration & Observability"]
node_settings["Runtime Settings
[config.py]"]
node_logging["JSON Logging
[logging.py]"]
end
node_browser(("User Browser"))
node_browser -->|"captures or uploads"| node_photo node_photo -->|"submits image"| node_transfer_route node_ui_mount -->|"mounts routes"| node_ui_routes node_ui_routes -->|"routes to"| node_landing node_ui_routes -->|"routes to"| node_photo node_fastapi -->|"registers"| node_api_router node_api_router -->|"includes"| node_health_route node_api_router -->|"includes"| node_transfer_route node_transfer_route -->|"calls"| node_service node_transfer_route -->|"uses request"| node_schemas node_transfer_route -->|"uses response"| node_responses node_health_route -->|"uses response"| node_responses node_service -->|"validates upload"| node_validation node_service -->|"preprocesses image"| node_image_processing node_service -->|"writes images"| node_artifacts node_service -.->|"runs configured engine"| node_factory node_fastapi -->|"builds engine"| node_factory node_factory -->|"selects backend"| node_onnx node_factory -->|"selects backend"| node_pytorch node_pytorch -->|"runs model"| node_transformer node_pytorch -->|"loads weights"| node_checkpoint node_transformer -->|"uses blocks"| node_conv node_transformer -->|"uses blocks"| node_residual node_fastapi -->|"loads settings"| node_settings node_factory -->|"selects engine paths"| node_settings node_fastapi -->|"configures logging"| node_logging node_factory -->|"logs engine setup"| node_logging
click node_photo "https://github.com/baggie11/virtual-photobooth/blob/main/frontend/src/components/PhotoPage.vue" click node_landing "https://github.com/baggie11/virtual-photobooth/blob/main/frontend/src/components/LandingPage.vue" click node_ui_routes "https://github.com/baggie11/virtual-photobooth/blob/main/frontend/src/router/index.js" click node_ui_mount "https://github.com/baggie11/virtual-photobooth/blob/main/frontend/src/main.js" click node_fastapi "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/main.py" click node_api_router "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/api/router.py" click node_transfer_route "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/api/routes/style_transfer.py" click node_health_route "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/api/routes/health.py" click node_schemas "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/schemas/requests.py" click node_responses "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/schemas/responses.py" click node_service "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/services/style_transfer_service.py" click node_validation "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/utils/file_validation.py" click node_image_processing "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/utils/image_processing.py" click node_artifacts "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/services/style_transfer_service.py" click node_factory "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/inference/factory.py" click node_onnx "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/inference/onnx_engine.py" click node_pytorch "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/inference/pytorch_engine.py" click node_transformer "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/models/transformer_net.py" click node_conv "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/models/conv_block.py" click node_residual "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/models/residual_block.py" click node_checkpoint "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/models/checkpoint.py" click node_settings "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/core/config.py" click node_logging "https://github.com/baggie11/virtual-photobooth/blob/main/backend/app/core/logging.py"
classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554 classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337 classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81 classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a class node_photo,node_landing,node_ui_routes,node_ui_mount,node_browser toneBlue class node_fastapi,node_api_router,node_transfer_route,node_health_route,node_schemas,node_responses,node_service,node_validation,node_image_processing,node_artifacts toneAmber class node_factory,node_onnx,node_pytorch toneMint class node_transformer,node_conv,node_residual,node_checkpoint toneRose class node_settings,node_logging toneIndigo
sequenceDiagram
autonumber
actor Client as User Browser (Vue 3 UI)
participant API as FastAPI Gateway
participant Service as Style Transfer Service
participant Engine as Inference Engine (ONNX / PyTorch)
participant Disk as Artifact Store
Client->>API: POST /style-transfer (multipart/form-data: image, style)
API->>Service: Validate payload (MIME, size, parameters)
alt Validation Failure
Service-->>API: Throw HTTP 400 / 413 / 415 Exception
API-->>Client: Error Response JSON (structured error detail)
end
Service->>Disk: Persist original frame to /uploads
Service->>Engine: Run neural style transform tensor pipeline
Engine-->>Service: Output transformed image tensor
Service->>Disk: Save rendered JPEG image to /results
Service-->>API: Return file path stream
API-->>Client: HTTP 200 (image/jpeg payload response)
photo-booth/
├── backend/ # FastAPI Application Microservice
│ ├── app/
│ │ ├── api/ # API Routing and endpoint specs
│ │ │ ├── routes/ # Health & Style Transfer endpoints
│ │ │ └── router.py # Central API Router aggregation
│ │ ├── core/ # System core (Config, Logging, Constants)
│ │ ├── inference/ # Pluggable Inference Engines (ONNX / PyTorch)
│ │ ├── schemas/ # Pydantic Request/Response models
│ │ ├── services/ # Core business & style transfer logic
│ │ └── main.py # FastAPI application instantiation & lifespan
│ ├── checkpoints/ # ONNX Model Artifacts (.onnx)
│ ├── models/ # PyTorch Model Checkpoints (.pth)
│ ├── tests/ # Pytest suite (API, validation, routing)
│ ├── uploads/ # Temporary upload staging directory
│ ├── results/ # Generated image output directory
│ ├── Dockerfile # Container build recipe
│ ├── requirements.txt # Python dependencies
│ └── .env.example # Environment variable blueprint
├── frontend/ # Vue 3 Client Application
│ ├── src/
│ │ ├── components/ # Reusable UI components & camera controls
│ │ ├── App.vue # Core Application layout
│ │ └── main.js # App mounting & Vue plugin initializations
│ ├── package.json # Frontend package dependencies & scripts
│ └── vite.config.js # Vite bundling & proxy configuration
└── README.md # Production Documentation
| Layer | Technologies & Tools |
|---|---|
| Frontend UI | Vue 3, Vite, Tailwind CSS v4, Lucide Vue Next, Vue Router |
| Backend API | FastAPI, Uvicorn (ASGI), Pydantic Settings, Python 3.10+ |
| AI / ML Engine | ONNX Runtime, PyTorch, Torchvision, Pillow, NumPy |
| Quality & Testing | Pytest, Python logging, HTTP status mapping |
| DevOps & Infra | Docker, OCI Container runtime standards |
Ensure your environment satisfies the following minimum requirements:
- Python:
3.10or higher - Node.js:
18.xor higher (LTS recommended) - Package Managers:
pip(Python) andnpm(Node) - Optional: Docker Desktop or
podmanfor containerized runtime.
Navigate to the backend directory, create a virtual environment, install requirements, and run the FastAPI app:
# Navigate to backend directory
cd backend
# Create & activate a virtual environment
python -m venv venv
# On Linux/macOS:
source venv/bin/activate
# On Windows (PowerShell):
.\venv\Scripts\Activate.ps1
# Install dependencies
pip install --upgrade pip
pip install -r requirements.txt
# Create local environment configuration from template
cp .env.example .env
# Start the ASGI Uvicorn development server
uvicorn app.main:app --host 127.0.0.1 --port 5000 --reloadNote: Verify backend operation by accessing the API health check at http://127.0.0.1:5000/health.
In a new terminal window, navigate to the frontend directory and launch Vite:
# Navigate to frontend directory
cd frontend
# Install Node dependencies
npm install
# Start Vite live reload dev server
npm run devThe application client will be hosted locally at http://localhost:5173.
The backend utilizes pydantic-settings to parse configuration from .env files or system environment variables.
| Variable Name | Type | Default Value | Description |
|---|---|---|---|
HOST |
string |
0.0.0.0 |
Network binding host address |
PORT |
int |
5000 |
Service port binding |
LOG_LEVEL |
string |
INFO |
Application log level (DEBUG, INFO, WARNING, ERROR) |
INFERENCE_BACKEND |
string |
onnx |
Active model engine backend (onnx or pytorch) |
MODEL_PATH |
path |
models/2nd_style_last_checkpoint.pth |
Absolute/relative path to PyTorch checkpoint |
ONNX_MODEL_PATH |
path |
checkpoints/style_transfer.onnx |
Absolute/relative path to ONNX model |
MAX_IMAGE_SIZE |
int |
5242880 (5 MB) |
Maximum permitted HTTP upload payload in bytes |
CORS_ORIGINS |
csv |
http://localhost:5173,http://127.0.0.1:5173 |
Allowed CORS origins (comma-separated string) |
ALLOWED_MIME_TYPES |
csv |
image/jpeg,image/jpg,image/png,image/webp |
Allowed MIME formats |
ALLOWED_IMAGE_EXTENSIONS |
csv |
.jpg,.jpeg,.png,.webp |
Allowed file extension suffixes |
Interactive API documentation is generated automatically by FastAPI:
- Swagger UI: http://127.0.0.1:5000/docs
- ReDoc UI: http://127.0.0.1:5000/redoc
- URL:
/health - Method:
GET - Response:
200 OK
{
"status": "ok",
"device": "cpu",
"checkpoint_found": true
}- URL:
/style-transfer - Method:
POST - Content-Type:
multipart/form-data - Form Parameters:
image(File, Required): Binary image file (.png,.jpg,.jpeg,.webp)style(String, Required): Style identifier string (e.g.mosaic,candy)
- Success Response:
200 OK(Returns binaryimage/jpegstream) - Error Responses:
400 Bad Request: Missing parameters or malformed request413 Payload Too Large: Uploaded image exceeds max bytes limit (MAX_IMAGE_SIZE)415 Unsupported Media Type: File format not permitted422 Unprocessable Entity: Input validation failure500 Internal Server Error: Deep learning inference runtime failure
curl -X POST "http://127.0.0.1:5000/style-transfer" \
-H "accept: image/jpeg" \
-H "Content-Type: multipart/form-data" \
-F "image=@/path/to/my_photo.jpg;type=image/jpeg" \
-F "style=mosaic" \
--output stylized_output.jpgThe service implements a unified abstraction for model execution, configurable via INFERENCE_BACKEND:
-
ONNX Engine (
INFERENCE_BACKEND=onnx) [Default & Recommended]:- High performance cross-platform execution with reduced startup overhead.
- Ideal for production microservices deployed on general-purpose cloud CPUs or specialized ONNX Execution Providers (CUDA, TensorRT).
-
PyTorch Engine (
INFERENCE_BACKEND=pytorch):- Direct execution via PyTorch native graph evaluation.
- Recommended during model research, re-training, or when evaluating custom PyTorch model checkpoints.
Automated backend unit tests are written using pytest and httpx.
# Navigate to backend directory
cd backend
# Execute test suite
pytest -v
# Run coverage analysis (optional)
pytest --cov=app tests/Test coverage encompasses route health validation, invalid MIME type rejections, oversized payload bounds, and missing style parameters.
To build and launch the production container image for the backend:
# Build Docker image
docker build -t photo-booth-backend:latest ./backend
# Run container with resource boundaries
docker run -d \
--name photo-booth-api \
-p 5000:5000 \
-e LOG_LEVEL=INFO \
-e INFERENCE_BACKEND=onnx \
-e CORS_ORIGINS="https://photobooth.yourdomain.com" \
photo-booth-backend:latestBefore routing live user traffic to your deployment, verify the following:
- CORS Security: Restrict
CORS_ORIGINSstrictly to authorized domain origins (do not use wildcard*in production). - Reverse Proxy Layer: Deploy Nginx, Cloudflare, or Traefik in front of Uvicorn for SSL/TLS termination, rate limiting, and HTTP request buffering.
- Process Management: Run Uvicorn with appropriate worker configurations. Due to PyTorch/ONNX memory overhead per process, evaluate GPU memory limits when scaling workers (
--workers 1or--workers 2). - Asset Mounts: Ensure model files (
checkpoints/style_transfer.onnxandmodels/2nd_style_last_checkpoint.pth) are baked into container images or mounted as persistent volumes. - Storage Housekeeping: Configure cron job / scheduled background job to regularly purge aged files in
uploads/andresults/.
- Payload Sanitization: Filenames uploaded by clients are sanitized using unique GUID timestamps to prevent directory traversal attacks (
../). - Resource Exhaustion Prevention: Incoming streams are verified against
MAX_IMAGE_SIZEprior to loading full tensor buffers into system memory. - Unprivileged Runtime: Containers should execute under non-root users when deployed in Kubernetes / ECS environments.
This repository is distributed under the MIT License. See the LICENSE file for complete details.