CoolFace
Apppublic

mnoorchenar/VAE-Playground

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
App README

<div align="center">

<h1>🧠 VAE · MNIST Playground</h1> <img src="https://readme-typing-svg.demolab.com?font=Fira+Code&size=22&duration=3000&pause=1000&color=7C3AED&center=true&vCenter=true&width=700&lines=Train+a+Variational+Autoencoder+in+your+browser;Explore+the+2-D+latent+manifold+visually;Generate+new+digits+by+sampling+latent+space;Deep+learning+made+interactive+%26+accessible" alt="Typing SVG"/>

<br/>

![Python](https://www.python.org/) ![Flask](https://flask.palletsprojects.com/) ![PyTorch](https://pytorch.org/) ![Docker](https://www.docker.com/) ![HuggingFace](https://huggingface.co/mnoorchenar/spaces) ![Status](#)

<br/>

🧠 VAE Β· MNIST Playground β€” An interactive web application for training, visualising, and experimenting with Variational Autoencoders on the MNIST handwritten digit dataset, directly in your browser with zero setup.

<br/>


</div>

Table of Contents


✨ Features

<table> <tr> <td>⚑ <b>Live Training Dashboard</b></td> <td>Configure hyperparameters (epochs, batch size, learning rate, hidden & latent dims) and launch training with a real-time animated progress bar and loss curve</td> </tr> <tr> <td>🌐 <b>Latent Space Visualisation</b></td> <td>Scatter-plot the 2-D encoded representations of 10 000 MNIST samples, colour-coded by digit class, revealing the learned manifold structure</td> </tr> <tr> <td>πŸ” <b>Reconstruction Comparison</b></td> <td>Side-by-side view of original MNIST digits and their VAE reconstructions, updating on every click with a freshly sampled random batch</td> </tr> <tr> <td>✨ <b>Interactive Generation</b></td> <td>Two latent-space sliders let you navigate the learned manifold in real time and decode novel digit-like images on the fly; a full 15Γ—15 grid view is also available</td> </tr> <tr> <td>πŸ”’ <b>Secure by Design</b></td> <td>Role-based access, audit logs, encrypted data pipelines</td> </tr> <tr> <td>🐳 <b>Containerized Deployment</b></td> <td>Docker-first architecture, cloud-ready and scalable</td> </tr> </table>


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    vae-mnist-playground                         β”‚
β”‚                                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚   MNIST    │───▢│  VAE (PyTorch)  │───▢│   Flask API   β”‚   β”‚
β”‚  β”‚  Dataset   β”‚    β”‚  Encoder/Decoderβ”‚    β”‚   Backend     β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                    β”‚           β”‚
β”‚                                           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚                                           β”‚  Vanilla JS     β”‚  β”‚
β”‚                                           β”‚  + Matplotlib   β”‚  β”‚
β”‚                                           β”‚   Dashboard     β”‚  β”‚
β”‚                                           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

VAE Data Flow:

Input (784-D)
    β”‚
    β–Ό  Encoder FC (ReLU)
    β”‚
    β”œβ”€β”€β–Ά ΞΌ head ──┐
    └──▢ σ² head ──  z = ΞΌ + σ·Ρ   (reparameterization trick)
                  β”‚
                  β–Ό
           Latent z (2-D / n-D)
                  β”‚
                  β–Ό  Decoder FC (ReLU β†’ Sigmoid)
                  β”‚
           Output (784-D)

πŸš€ Getting Started

Prerequisites

  • β€”Python 3.10+
  • β€”Docker & Docker Compose
  • β€”Git

Local Installation

bash
# 1. Clone the repository
git clone https://github.com/mnoorchenar/vae-mnist-playground.git
cd vae-mnist-playground

# 2. Create a virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# 3. Install dependencies
pip install -r requirements.txt

# 4. Configure environment variables
cp .env.example .env
# Edit .env with your settings

# 5. Run the application
python app.py

Open your browser at http://localhost:7860 πŸŽ‰


🐳 Docker Deployment

bash
# Build and run with Docker Compose
docker compose up --build

# Or pull and run the pre-built image
docker pull mnoorchenar/vae-mnist-playground
docker run -p 7860:7860 mnoorchenar/vae-mnist-playground

πŸ“Š Dashboard Modules

ModuleDescriptionStatus
⚑ Training DashboardConfigure hyperparameters, launch training, watch real-time loss curve and progress barβœ… Live
πŸ—οΈ Architecture ViewerInteractive diagram of the full VAE topology with the ELBO loss formula explainedβœ… Live
🌐 Latent Space Explorer2-D scatter plot of encoded MNIST digits, colour-coded by classβœ… Live
πŸ” Reconstruction ViewerRandom-batch side-by-side comparison of originals vs VAE reconstructionsβœ… Live
✨ Generation ConsoleLatent-vector sliders for real-time digit generation + 15Γ—15 manifold gridβœ… Live
πŸ“¦ Model ExportDownload trained weights as a .pt checkpointπŸ—“οΈ Planned

🧠 ML Models

python
# Core Models Used in vae-mnist-playground
models = {
    "architecture":       "Variational Autoencoder (VAE)",
    "encoder":            "FC 784 β†’ hidden_dim β†’ (ΞΌ, log σ²)",
    "decoder":            "FC latent_dim β†’ hidden_dim β†’ 784",
    "loss_function":      "ELBO = BCE Reconstruction + KL Divergence",
    "reparameterization": "z = ΞΌ + Οƒ Β· Ξ΅,  Ξ΅ ~ N(0, I)"
}

Configurable hyperparameters at runtime:

ParameterDefaultRange
Epochs301 – 200
Batch size12832 / 64 / 128 / 256
Learning rate1e-31e-4 / 1e-3 / 1e-2
Hidden dimension400200 / 400 / 512
Latent dimension22 / 5 / 10 / 20

πŸ“ Project Structure

vae-mnist-playground/
β”‚
β”œβ”€β”€ πŸ“„ app.py                  # Flask app, VAE model, all routes & HTML template
β”‚
β”œβ”€β”€ πŸ“‚ data/                   # Auto-downloaded MNIST dataset cache
β”‚   └── MNIST/
β”‚
β”œβ”€β”€ πŸ“„ Dockerfile              # Container definition (port 7860)
β”œβ”€β”€ πŸ“„ docker-compose.yml      # Multi-service orchestration
β”œβ”€β”€ πŸ“„ requirements.txt        # Python dependencies
β”œβ”€β”€ πŸ“„ .env.example            # Environment variable template
└── πŸ“„ README.md               # This file
Note: The project uses a single-file architecture (app.py) for simplicity and Hugging Face Spaces compatibility. The HTML template, VAE class, training loop, and all Flask routes are co-located intentionally.

πŸ‘¨β€πŸ’» Author

<div align="center">

<table> <tr> <td align="center" width="100%">

<img src="https://avatars.githubusercontent.com/mnoorchenar" width="120" style="border-radius:50%; border: 3px solid #4f46e5;" alt="Mohammad Noorchenarboo"/>

<h3>Mohammad Noorchenarboo</h3>

<code>Data Scientist</code> &nbsp;|&nbsp; <code>AI Researcher</code> &nbsp;|&nbsp; <code>Biostatistician</code>

πŸ“ &nbsp;Ontario, Canada &nbsp;&nbsp; πŸ“§ &nbsp;mohammadnoorchenarboo@gmail.com

──────────────────────────────────────

![LinkedIn](https://www.linkedin.com/in/mnoorchenar)&nbsp; ![Personal Site](https://mnoorchenar.github.io/)&nbsp; ![HuggingFace](https://huggingface.co/mnoorchenar/spaces)&nbsp; ![Google Scholar](https://scholar.google.ca/citations?user=nn_Toq0AAAAJ&hl=en)&nbsp; ![GitHub](https://github.com/mnoorchenar)

</td> </tr> </table>

</div>


🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. 1.Fork the repository
  2. 2.Create a feature branch: git checkout -b feature/amazing-feature
  3. 3.Commit your changes: git commit -m 'Add amazing feature'
  4. 4.Push to the branch: git push origin feature/amazing-feature
  5. 5.Open a Pull Request

Disclaimer

<span style="color:red">This project is developed strictly for educational and research purposes and does not constitute professional advice of any kind. All datasets used are either synthetically generated or publicly available (MNIST is a public domain dataset) β€” no real user data is stored. This software is provided "as is" without warranty of any kind; use at your own risk.</span>


πŸ“œ License

Distributed under the MIT License. See `LICENSE` for more information.


<div align="center">

<img src="https://capsule-render.vercel.app/api?type=waving&color=0:7c3aed,100:06b6d4&height=120&section=footer&text=Made%20with%20%E2%9D%A4%EF%B8%8F%20by%20Mohammad%20Noorchenarboo&fontColor=ffffff&fontSize=18&fontAlignY=80" width="100%"/>

![GitHub Stars](https://github.com/mnoorchenar/vae-mnist-playground) ![GitHub Forks](https://github.com/mnoorchenar/vae-mnist-playground/fork)

<sub>The name "vae-mnist-playground" is used purely for academic and research purposes. Any similarity to existing product names or trademarks is entirely coincidental. This project has no affiliation with any commercial entity.</sub>

</div>