liaoch/mermaid-rendering
1
๐งโโ๏ธ Mermaid Diagram Renderer
A simple web application for rendering Mermaid diagrams using Gradio, designed for deployment on Hugging Face Spaces.
Features
- Web-based interface for entering Mermaid code
- Multiple output formats: PNG, SVG, PDF
- Theme selection: Default, Forest, Dark, Neutral
- Easy file download of generated diagrams
- Built with Gradio for seamless Hugging Face Spaces deployment
Deploy to Hugging Face Spaces
- Create a new Space on Hugging Face Spaces
- Choose SDK: Select "Gradio"
- Upload files: Copy these files to your Space:
app.pymermaid_renderer.pyrequirements.txt- Your Space will automatically build and deploy!
The app will be available at https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
Local Development
# Install dependencies
pip install -r requirements.txt
# Install Node.js and mermaid-cli
npm install -g @mermaid-js/mermaid-cli
# Run the app
python app.pyDependencies
- Python: Gradio for the web interface
- Node.js: Required for @mermaid-js/mermaid-cli
- mermaid-cli: Handles the actual diagram rendering
Note: Hugging Face Spaces handles Node.js and mermaid-cli installation automatically.
Local Testing
To test this project locally before deploying or pushing to Hugging Face Spaces, follow these steps:
- Create and activate a Python virtual environment
On macOS/Linux:
python3 -m venv venv
source venv/bin/activateOn Windows:
python -m venv venv
venv\Scripts\activate- Upgrade pip (recommended)
pip install --upgrade pip- Install Python dependencies
pip install -r requirements.txt- Ensure Node.js is installed
node --versionIf not installed, download from nodejs.org.
- Ensure @mermaid-js/mermaid-cli is installed globally
npm install -g @mermaid-js/mermaid-cli@9.0.0- Run the Gradio app
python app.pyGradio will print a local URL (e.g., http://127.0.0.1:7860/) in the terminal.
- Open the app in your browser Visit the local URL to interact with and test the interface.
When finished, you can deactivate the virtual environment with:
deactivateNote: If you accidentally added the venv folder to git, remove it from tracking with:
git rm -r --cached venv
git commit -m "Stop tracking venv directory"