Automatic diagram generation with GenAI
Mac/Linux:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pipWindows (PowerShell):
py -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pippip install -r requirements.txtMac/Linux:
export OPENAI_API_KEY="sk-..." # Required for OpenAI
export GEMINI_API_KEY="..." # Optional: set if using GeminiWindows (PowerShell):
$env:OPENAI_API_KEY = "sk-..."
$env:GEMINI_API_KEY = "..."The code uses these environment variables when calling providers (see src/core.py).
streamlit run src/app.pyIn the app:
- Provide your API keys in the sidebar (or set
OPENAI_API_KEY/GEMINI_API_KEYenvironment variables beforehand). - Enter a prompt describing the system or network flow.
- Optionally upload supporting files (text/code/images) to ground the model.
- Click “Generate Diagram” to produce editable Mermaid text.
Tabs:
- Preview: renders latest generated Mermaid diagram.
- Editor: adjust the Mermaid diagram source directly.
- Export:
- mermaid.live - open editor in mermaid.live.
- draw.io - view import steps to draw.io (diagrams.net).
- SVG - download as .svg file.
docker build -t auto-diagram .
docker run --rm \
-p 8501:8501 \
-e OPENAI_API_KEY=sk-... \
-e GEMINI_API_KEY=... \
-v path/to/local/dir:/data/auto-diagram \
auto-diagram- Replace the example API keys with your real credentials. Add or remove
-eflags depending on the providers you use. - The volume mapping to
/data/auto-diagrammakes chat state persistent across container restarts; omit it if you prefer ephemeral sessions. - Open http://localhost:8501 in your browser to use the containerized app.
You can run the CLI script directly. The --supporting-files option points to a directory whose files are added to context. An example context is provided under examples/NSCacheFlush/context.
# From the repo root
python src/cli.py create \
"Generate a Mermaid diagram explaining the NSCacheFlush network flow" \
--supporting-files examples/NSCacheFlush/context \
--output output/diagram.mmdThe diagram text (Mermaid) is saved to output/diagram.mmd.