Photo-to-cartoon web app with a React frontend, a packaged Flask backend, and a free AnimeGAN fallback.
Cartoonist is a focused photo-to-cartoon app.
- Upload a portrait, selfie, or scene in the browser
- Send the image to a Flask API for processing
- Get back a stylized cartoon result as a PNG
- Run with a free AnimeGANv2 fallback or your own trained Pix2Pix checkpoint
The current app is intentionally single-purpose: photo to cartoon only.
- Drag-and-drop React UI built with Vite
- Flask API packaged under
backend/ - Free AnimeGANv2 fallback on startup
- Optional local Pix2Pix checkpoint support
- Before/after preview with one-click download
- Simple local setup for development
- Python
- Flask + Flask-CORS
- PyTorch
- React 18
- Vite
- Axios
- React Dropzone
Cartoonist/
|-- backend/
| |-- app.py # Flask app and API routes
| |-- free_models.py # Free AnimeGAN fallback loader
| |-- __init__.py
| `-- __main__.py # Enables: python -m backend
|-- frontend/
| |-- src/
| | |-- App.tsx
| | |-- App.css
| | |-- api.ts
| | |-- index.css
| | `-- main.tsx
| `-- package.json
|-- data/ # Dataset utilities
|-- models/ # Training/inference model definitions
|-- config.py
|-- requirements.txt
|-- start_ui.py # Helper script to start the packaged backend
`-- train_pix2pix.py # Train your own Pix2Pix checkpoint
pip install -r requirements.txtpython -m backend --port 5000The API will be available at http://localhost:5000/api.
cd frontend
npm install
npm run devOpen http://localhost:3000.
Cartoonist supports two backend modes:
If you do not pass a local checkpoint, the backend loads a free AnimeGANv2 portrait model through torch.hub.
python -m backendNotes:
- The first run downloads the fallback model
- The downloaded files are cached under
backend/model_cache/ - This is the easiest way to get the app working locally
If you have trained your own paired photo-to-cartoon model, start the backend with it:
python -m backend --pix2pix outputs/pix2pix/final_model.pthReturns backend health and model readiness.
Example:
{
"cartoon_model": "AnimeGANv2 Face Portrait v2",
"device": "cpu",
"pix2pix": true
}Uploads one image file using the image form field and returns a PNG result.
Create a paired dataset like this:
datasets/my_dataset/
|-- A/
| |-- train/
| `-- test/
`-- B/
|-- train/
`-- test/
Acontains the original photosBcontains the matching cartoon targets- filenames must match exactly across pairs
Train the model:
python train_pix2pix.py --dataset datasets/my_datasetThen use the checkpoint in the app:
python -m backend --pix2pix outputs/pix2pix/final_model.pth- Frontend dev server:
http://localhost:3000 - Backend API:
http://localhost:5000 - Main frontend entry:
frontend/src/main.tsx - Main backend entry:
backend/__main__.py
start_ui.py is also available if you want a simple helper that prints the frontend steps and launches the packaged backend for you.
Some older research and experimentation files are still in the repo, including demo.py, inference.py, and train_stylegan.py.
They are not part of the current shipped web app. The active product flow in this repository is photo to cartoon through the React UI and the packaged Flask backend.
This project is licensed under the MIT License. See LICENSE.
- Pix2Pix: Isola et al., "Image-to-Image Translation with Conditional Adversarial Networks"
- AnimeGANv2 fallback model via PyTorch Hub