Skip to content

pinellolab/gradio-dna-diffusion

Repository files navigation

DNA-Diffusion Gradio App

An interactive web application for generating cell type-specific DNA regulatory sequences using the DNA-Diffusion model from Pinello Lab.

DNA-Diffusion Demo

Features

  • 🎰 Interactive Slot Machine Interface: Visualize DNA sequence generation in real-time with 200 spinning slots
  • 🧬 Cell Type-Specific Generation: Generate sequences for K562, GM12878, and HepG2 cell lines
  • ⚑ Real-time Feedback: Continuous animation while the model generates sequences
  • 🎨 Beautiful UI: Retro-futuristic design with neon effects and smooth animations
  • πŸ€– Powered by DNA-Diffusion: State-of-the-art diffusion model for DNA sequence generation

Quick Start

Prerequisites

  • Python 3.8+
  • CUDA-capable GPU (optional, but recommended for faster generation)
  • Git
  • uv package manager (for DNA-Diffusion installation)

Installation

  1. Clone this repository:
git clone https://github.com/pinellolab/gradio-dna-diffusion.git
cd gradio-dna-diffusion
  1. Install uv package manager:
curl -LsSf https://astral.sh/uv/install.sh | sh
  1. Clone and install DNA-Diffusion:
git clone https://github.com/pinellolab/DNA-Diffusion.git
cd DNA-Diffusion
uv sync
cd ..
  1. Install Gradio app dependencies:
pip install -r requirements.txt

Running Locally

  1. Basic usage:
DNA-Diffusion/.venv/bin/python app.py
  1. With options:
# Run on a specific port
DNA-Diffusion/.venv/bin/python app.py --port 8080

# Create a public share link
DNA-Diffusion/.venv/bin/python app.py --share

# Run on all network interfaces
DNA-Diffusion/.venv/bin/python app.py --host 0.0.0.0
  1. Open your browser to http://localhost:7860

How to Use

  1. Select a cell type using the radio buttons (K562, GM12878, or HepG2)
  2. Click GENERATE or pull the lever to start sequence generation
  3. Watch the slots spin while the model generates a 200bp regulatory sequence
  4. The generated sequence will be displayed below once complete

Project Structure

gradio-dna-diffusion/
β”œβ”€β”€ app.py                    # Main Gradio application
β”œβ”€β”€ dna_diffusion_model.py    # Model wrapper for DNA-Diffusion
β”œβ”€β”€ dna-slot-machine.html     # Interactive HTML interface
β”œβ”€β”€ requirements.txt          # Python dependencies
β”œβ”€β”€ README.md                 # This file
└── DNA-Diffusion/           # DNA-Diffusion repository (gitignored)

Deployment to Hugging Face Spaces

Option 1: Direct Deployment

  1. Create a new Space on Hugging Face Spaces
  2. Select Gradio as the SDK
  3. Clone your Space locally:
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
cd YOUR_SPACE_NAME
  1. Copy the required files:
cp path/to/gradio-dna-diffusion/app.py .
cp path/to/gradio-dna-diffusion/dna_diffusion_model.py .
cp path/to/gradio-dna-diffusion/dna-slot-machine.html .
cp path/to/gradio-dna-diffusion/requirements.txt .
  1. Create app metadata (README.md):
---
title: DNA Diffusion Slot Machine
emoji: 🧬
colorFrom: green
colorTo: blue
sdk: gradio
sdk_version: 4.44.1
app_file: app.py
pinned: false
---
  1. Push to Hugging Face:
git add .
git commit -m "Initial commit"
git push

Option 2: Using GitHub Integration

  1. Push this repository to GitHub
  2. Create a new Space on Hugging Face
  3. Link it to your GitHub repository
  4. The Space will automatically build and deploy

GPU Requirements

For optimal performance, enable GPU in your Space:

  1. Go to Settings β†’ Hardware
  2. Select T4 GPU or better
  3. The model will automatically use GPU if available

Development

Running without DNA-Diffusion Model

The app can run in mock mode for UI development:

python app.py

This will use random sequence generation instead of the actual model.

Customizing the Interface

  • Edit dna-slot-machine.html to modify the visual interface
  • The interface communicates with Gradio backend via postMessage API
  • Cell types and generation parameters can be extended in app.py

Technical Details

  • Model: DNA-Diffusion from Pinello Lab (HuggingFace: ssenan/DNA-Diffusion)
  • Sequence Length: 200bp regulatory elements
  • Cell Types: K562, GM12878, HepG2 (hESCT0 available in model but not in UI)
  • Generation Time: 2-5 seconds on GPU, 20-30 seconds on CPU
  • Framework: Gradio 4.44.1 with custom HTML/JS interface

Troubleshooting

Model fails to load

  • Ensure DNA-Diffusion is properly installed with uv sync
  • Check that you're using the DNA-Diffusion virtual environment
  • Verify CUDA is available if using GPU: python -c "import torch; print(torch.cuda.is_available())"

Interface doesn't display

  • Check that dna-slot-machine.html exists in the same directory as app.py
  • Clear browser cache and reload
  • Check browser console for JavaScript errors

Generation is slow

  • Use a CUDA-capable GPU for 10x faster generation
  • The first generation includes model warm-up time
  • CPU generation typically takes 20-30 seconds

Citation

If you use this application in your research, please cite:

@article{dnadiffusion2024,
  title={DNA-Diffusion: Leveraging Generative Models for Controlling Chromatin Accessibility and Gene Expression via Synthetic Regulatory Elements},
  author={DaSilva, Lucas Ferreira and Senan, Simon and Patel, Zain Munir and Reddy, Aniketh Janardhan and Gabbita, Sameer and Nussbaum, Zach and CΓ³rdova, CΓ©sar Miguel Valdez and Wenteler, Aaron and Weber, Noah and Tunjic, Tin M. and Khan, Talha Ahmad and Li, Zelun and Smith, Cameron and Bejan, Matei and Louis, Lithin Karmel and Cornejo, Paola and Connell, Will and Wong, Emily S. and Meuleman, Wouter and Pinello, Luca},
  journal={bioRxiv},
  year={2024},
  doi={10.1101/2024.02.01.578352},
  url={https://www.biorxiv.org/content/10.1101/2024.02.01.578352v1}
}

License

DNA-Diffusion Gradio Interface is made available for free to academic and non-profit researchers under the Apache License, Version 2.0.

If you plan to use this code or the synthetic sequences generated by the model for profit, please contact [email protected] for more information.

See LICENSE file for full details.

Acknowledgments

  • Pinello Lab for the DNA-Diffusion model
  • Gradio for the web framework
  • DNA-Diffusion team for the pretrained models

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published