Skip to content

vishwaswami24/Cartoonist

Repository files navigation

Cartoonist

Cartoonist tech stack

Python badge Flask badge PyTorch badge React badge Vite badge

Photo-to-cartoon web app with a React frontend, a packaged Flask backend, and a free AnimeGAN fallback.

Screenshot 2026-03-28 172838

Overview

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.

Features

  • 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

Tech Stack

  • Python
  • Flask + Flask-CORS
  • PyTorch
  • React 18
  • Vite
  • Axios
  • React Dropzone

Project Structure

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

Quick Start

1. Install Python dependencies

pip install -r requirements.txt

2. Start the backend

python -m backend --port 5000

The API will be available at http://localhost:5000/api.

3. Start the frontend

cd frontend
npm install
npm run dev

Open http://localhost:3000.

How The Model Works

Cartoonist supports two backend modes:

Free mode

If you do not pass a local checkpoint, the backend loads a free AnimeGANv2 portrait model through torch.hub.

python -m backend

Notes:

  • 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

Local Pix2Pix checkpoint

If you have trained your own paired photo-to-cartoon model, start the backend with it:

python -m backend --pix2pix outputs/pix2pix/final_model.pth

API

GET /api/status

Returns backend health and model readiness.

Example:

{
  "cartoon_model": "AnimeGANv2 Face Portrait v2",
  "device": "cpu",
  "pix2pix": true
}

POST /api/cartoonize

Uploads one image file using the image form field and returns a PNG result.

Training Your Own Pix2Pix Model

Create a paired dataset like this:

datasets/my_dataset/
|-- A/
|   |-- train/
|   `-- test/
`-- B/
    |-- train/
    `-- test/
  • A contains the original photos
  • B contains the matching cartoon targets
  • filenames must match exactly across pairs

Train the model:

python train_pix2pix.py --dataset datasets/my_dataset

Then use the checkpoint in the app:

python -m backend --pix2pix outputs/pix2pix/final_model.pth

Development Notes

  • 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.

Legacy Files

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.

License

This project is licensed under the MIT License. See LICENSE.

Acknowledgments

  • Pix2Pix: Isola et al., "Image-to-Image Translation with Conditional Adversarial Networks"
  • AnimeGANv2 fallback model via PyTorch Hub

About

Photo-to-cartoon web app built with React, Flask, and PyTorch using AnimeGANv2 fallback and optional Pix2Pix checkpoints.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors