File size: 1,811 Bytes
bb16d68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Any2SVG Architecture

## Overview

Any2SVG is a Gradio 6 application that converts raster images to SVG vector graphics. It's designed to work both as a standalone web application and as an MCP (Model Context Protocol) server for AI agent integration.

## DNA Architecture

The project follows the DNA architecture pattern:

```
any-to-svg/
β”œβ”€β”€ app.py                    # Main Gradio application
β”œβ”€β”€ dna/
β”‚   β”œβ”€β”€ atoms/               # Core utilities
β”‚   β”‚   └── vectorizer.py    # Low-level vtracer wrapper
β”‚   β”œβ”€β”€ molecules/           # Composite components
β”‚   β”‚   └── mcp_handler.py   # MCP request processing
β”‚   └── proteins/            # High-level orchestration
β”œβ”€β”€ knowledge-base/          # Documentation
└── output/                  # Generated SVG files
```

## Components

### Atoms Layer
- `vectorizer.py`: Core vectorization using vtracer library
  - `VectorizerConfig`: Configuration dataclass
  - `image_to_svg_string()`: Convert to SVG string
  - `image_to_svg_file()`: Convert and save to file

### Molecules Layer
- `mcp_handler.py`: MCP integration
  - `process_mcp_request()`: Handle MCP tool calls
  - `get_output_directory()`: Manage output paths

### Application Layer
- `app.py`: Gradio interface and MCP server
  - Web UI with configurable parameters
  - MCP tool endpoint at `/gradio_api/mcp/sse`

## MCP Integration

The application exposes an MCP tool `image_to_svg` that:
1. Accepts image input (URL or base64)
2. Converts to SVG using vtracer
3. Saves to configured output directory
4. Returns file path and SVG content

## Security Considerations

- Input validation on all image uploads
- Sanitized file paths for output
- Environment variable protection for sensitive config
- No arbitrary code execution