visual-notebook / README.md
Sid-WC121
fixx1
1756fb6
|
Raw History Blame Contribute Delete
9.13 kB
metadata
title: Visual Notebook
emoji: πŸ““
colorFrom: blue
colorTo: indigo
sdk: docker
app_port: 7860
pinned: false

Visual Notebook

Interactive data exploration notebook with DuckDB + Polars backend and React frontend.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Browser                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚           React + TypeScript                  β”‚  β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚  β”‚ Notebook β”‚ β”‚  Charts  β”‚ β”‚  Transform    β”‚  β”‚  β”‚
β”‚  β”‚  β”‚   Cells  β”‚ β”‚ (ECharts)β”‚ β”‚   Panel       β”‚  β”‚  β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚  β”‚
β”‚  β”‚                     β”‚  REST API (/api/*)      β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               FastAPI Backend                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚              API Routes Layer                 β”‚  β”‚
β”‚  β”‚  upload Β· schema Β· rows Β· ops Β· history Β· viz β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                        β”‚                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  DuckDB    β”‚ β”‚   Polars    β”‚ β”‚  Checkpoints  β”‚   β”‚
β”‚  β”‚  (query)   β”‚ β”‚  (sample)   β”‚ β”‚  (Parquet)    β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                        β”‚                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚           Domain Layer                        β”‚  β”‚
β”‚  β”‚  DataFrameRef Β· History Β· Operations Β· Viz    β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Features

  • CSV Upload - Drag-and-drop CSV files up to 500 MB
  • Schema Exploration - Automatic type inference, null counts, unique values, min/max/mean/std stats
  • Data Table - Paginated row preview with column type badges
  • Transformations - Filter, sort, select, rename, group-by, fill-nulls, clip operations
  • Undo/Redo - Full history tree with branching support
  • 6 Chart Types - Histogram, scatter, top-N bar, timeline, heatmap, geo map
  • Export - Download filtered/transformed data as CSV
  • Checkpoints - Save and restore data snapshots (Parquet + JSON metadata)
  • Session-based - Each browser session gets its own isolated DuckDB instance

Quick Start

Prerequisites

  • Python 3.11+
  • Node.js 20+
  • uv (Python package manager)

Backend

cd backend
uv pip install -e .
uvicorn visual_notebook.main:app --reload --port 8000

Frontend

cd frontend
npm install
npm run dev

The frontend dev server starts at http://localhost:5173 and proxies API requests to the backend at http://localhost:8000.

Environment Variables

Variable Default Description
DATA_DIR datasets Directory containing CSV data files
CHECKPOINT_DIR checkpoints Directory for checkpoint storage
MAX_UPLOAD_SIZE 524288000 Max CSV upload size in bytes (500 MB)
PREVIEW_ROWS 50 Default number of preview rows
CORS_ORIGINS http://localhost:5173 Allowed CORS origins
HOST 0.0.0.0 Server bind host
PORT 8000 Server bind port
VITE_API_URL (empty) Frontend API URL override

Docker

docker build -t visual-notebook .
docker run -p 7860:7860 -v $(pwd)/datasets:/app/datasets visual-notebook

One image, one URL β€” FastAPI serves both the API and the React frontend on port 7860.

Deploy to Hugging Face Spaces

The app deploys as a single Docker container to HF Spaces:

  1. Create a new Docker Space at huggingface.co/new-space
  2. Add these GitHub Secrets (repo β†’ Settings β†’ Secrets β†’ Actions):
    • HF_USERNAME β€” your HF username
    • HF_TOKEN β€” your HF access token
    • HF_SPACE_ID β€” username/space-name
  3. Push to main β€” the hf-space-deploy.yml workflow builds and deploys automatically

Your app will be live at: https://huggingface.co/spaces/<username>/<space-name>

Hugging Face Spaces (Federated Compute)

The federated compute worker is a separate project deployed to Hugging Face Spaces. It is not part of this repository.

See docs/federated-compute.md for the full architecture.

Project Structure

visual-notebook/
β”œβ”€β”€ pyproject.toml              # Workspace root config
β”œβ”€β”€ Dockerfile                  # Combined backend+frontend build
β”œβ”€β”€ docker-compose.yml          # Multi-service development
β”œβ”€β”€ .dockerignore               # Docker build exclusions
β”œβ”€β”€ .gitignore                  # Git exclusions
β”œβ”€β”€ .env.example                # Environment variable template
β”œβ”€β”€ README.md                   # This file
β”‚
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ pyproject.toml          # Backend dependencies
β”‚   └── visual_notebook/
β”‚       β”œβ”€β”€ main.py             # FastAPI app entry point
β”‚       β”œβ”€β”€ config.py           # Settings from env vars
β”‚       β”œβ”€β”€ session.py          # Session management
β”‚       β”œβ”€β”€ api/
β”‚       β”‚   β”œβ”€β”€ deps.py         # Dependency injection
β”‚       β”‚   β”œβ”€β”€ schemas.py      # Pydantic models
β”‚       β”‚   └── routes.py       # API routes
β”‚       β”œβ”€β”€ data/
β”‚       β”‚   β”œβ”€β”€ types.py        # Column type classification
β”‚       β”‚   β”œβ”€β”€ csv_loader.py   # CSV loading & registration
β”‚       β”‚   └── schema.py       # Schema inference
β”‚       β”œβ”€β”€ domain/
β”‚       β”‚   β”œβ”€β”€ dataframe.py    # DataFrameRef (DuckDB/Polars)
β”‚       β”‚   β”œβ”€β”€ history.py      # Undo/redo/branch history
β”‚       β”‚   β”œβ”€β”€ operations.py   # Operations registry
β”‚       β”‚   β”œβ”€β”€ checkpoints.py  # Checkpoint persistence
β”‚       β”‚   └── validators.py   # Validation helpers
β”‚       └── viz/
β”‚           β”œβ”€β”€ _common.py      # Chart utilities
β”‚           β”œβ”€β”€ histogram.py    # Histogram chart
β”‚           β”œβ”€β”€ scatter.py      # Scatter plot
β”‚           β”œβ”€β”€ bar_topn.py     # Top-N bar chart
β”‚           β”œβ”€β”€ timeline.py     # Timeline/area chart
β”‚           β”œβ”€β”€ heatmap.py      # Heatmap
β”‚           └── map.py          # Geo map spec
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ package.json            # Frontend dependencies
β”‚   β”œβ”€β”€ vite.config.ts          # Vite + API proxy config
β”‚   β”œβ”€β”€ Dockerfile              # Nginx-based frontend build
β”‚   β”œβ”€β”€ nginx.conf              # Reverse proxy config
β”‚   └── src/
β”‚       β”œβ”€β”€ api/                # API client & hooks
β”‚       β”œβ”€β”€ store/              # Zustand state stores
β”‚       β”œβ”€β”€ lib/                # Utilities
β”‚       └── components/         # React components
β”‚
β”œβ”€β”€ datasets/
β”‚   └── orders.csv              # Demo data
β”‚
β”œβ”€β”€ docs/                       # Documentation
β”‚
└── .github/workflows/          # CI/CD pipelines
    β”œβ”€β”€ deploy.yml              # CI + GHCR Docker push
    └── hf-space-deploy.yml     # HF Spaces deploy

License

MIT