Upload folder using huggingface_hub
Browse files- README.md +74 -40
- config.json +36 -5
- handler.py +144 -110
- requirements.txt +25 -6
README.md
CHANGED
|
@@ -1,72 +1,106 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
tags:
|
| 3 |
-
- text-to-image
|
| 4 |
-
- diffusers
|
| 5 |
-
- vector-graphics
|
| 6 |
- svg
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
# SVGDreamer: Text Guided SVG Generation with Diffusion Model
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
## Model Description
|
| 17 |
|
| 18 |
-
SVGDreamer
|
| 19 |
|
| 20 |
## Usage
|
| 21 |
|
| 22 |
```python
|
| 23 |
import requests
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
return response.content
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
API_URL,
|
| 42 |
-
headers=headers,
|
| 43 |
-
json={
|
| 44 |
-
"inputs": {
|
| 45 |
-
"text": "a beautiful mountain landscape",
|
| 46 |
-
"width": 512,
|
| 47 |
-
"height": 512,
|
| 48 |
-
"num_paths": 512,
|
| 49 |
-
"seed": 42
|
| 50 |
-
}
|
| 51 |
-
}
|
| 52 |
-
)
|
| 53 |
```
|
| 54 |
|
| 55 |
## Parameters
|
| 56 |
|
| 57 |
-
-
|
| 58 |
-
-
|
| 59 |
-
-
|
| 60 |
-
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
## Citation
|
| 64 |
|
| 65 |
```bibtex
|
| 66 |
@inproceedings{xing2023svgdreamer,
|
| 67 |
title={SVGDreamer: Text Guided SVG Generation with Diffusion Model},
|
| 68 |
-
author={Xing, XiMing and
|
| 69 |
-
booktitle={
|
| 70 |
year={2023}
|
| 71 |
}
|
| 72 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: SVGDreamer
|
| 3 |
+
emoji: 🎨
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: custom
|
| 7 |
+
app_file: handler.py
|
| 8 |
+
pinned: false
|
| 9 |
+
license: mit
|
| 10 |
tags:
|
|
|
|
|
|
|
|
|
|
| 11 |
- svg
|
| 12 |
+
- vector-graphics
|
| 13 |
+
- text-to-image
|
| 14 |
+
- diffusion
|
| 15 |
+
- artistic
|
| 16 |
+
pipeline_tag: image-generation
|
| 17 |
+
library_name: diffvg
|
| 18 |
---
|
| 19 |
|
| 20 |
# SVGDreamer: Text Guided SVG Generation with Diffusion Model
|
| 21 |
|
| 22 |
+
SVGDreamer is a novel approach for generating high-quality vector graphics from text descriptions using diffusion models. It creates artistic, scalable SVG images that maintain quality at any resolution.
|
| 23 |
|
| 24 |
## Model Description
|
| 25 |
|
| 26 |
+
SVGDreamer leverages the power of diffusion models to generate vector graphics by optimizing Bézier curves and color gradients. The model produces artistic SVG images with smooth curves, gradients, and complex compositions that are both semantically meaningful and visually appealing.
|
| 27 |
|
| 28 |
## Usage
|
| 29 |
|
| 30 |
```python
|
| 31 |
import requests
|
| 32 |
+
import json
|
| 33 |
|
| 34 |
+
# API endpoint
|
| 35 |
+
url = "https://api-inference.huggingface.co/models/jree423/svgdreamer"
|
| 36 |
|
| 37 |
+
# Headers
|
| 38 |
+
headers = {"Authorization": "Bearer YOUR_HF_TOKEN"}
|
|
|
|
| 39 |
|
| 40 |
+
# Payload
|
| 41 |
+
payload = {
|
| 42 |
+
"inputs": "a beautiful abstract painting with flowing colors",
|
| 43 |
+
"parameters": {
|
| 44 |
+
"num_paths": 512,
|
| 45 |
+
"num_iter": 1000,
|
| 46 |
+
"guidance_scale": 100.0,
|
| 47 |
+
"canvas_size": 512
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
|
| 51 |
+
# Make request
|
| 52 |
+
response = requests.post(url, headers=headers, json=payload)
|
| 53 |
+
result = response.json()
|
| 54 |
|
| 55 |
+
# The result contains the SVG content
|
| 56 |
+
svg_content = result[0]["svg"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
```
|
| 58 |
|
| 59 |
## Parameters
|
| 60 |
|
| 61 |
+
- **num_paths** (int, default: 512): Number of paths in the generated SVG
|
| 62 |
+
- **num_iter** (int, default: 1000): Number of optimization iterations
|
| 63 |
+
- **guidance_scale** (float, default: 100.0): Guidance scale for diffusion
|
| 64 |
+
- **canvas_size** (int, default: 512): Canvas size for SVG generation
|
| 65 |
+
|
| 66 |
+
## Examples
|
| 67 |
+
|
| 68 |
+
### Abstract Art
|
| 69 |
+
```
|
| 70 |
+
Input: "flowing abstract patterns in blue and gold"
|
| 71 |
+
Parameters: {"num_paths": 256, "num_iter": 800}
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
### Nature Scene
|
| 75 |
+
```
|
| 76 |
+
Input: "a serene mountain landscape at sunset"
|
| 77 |
+
Parameters: {"num_paths": 512, "num_iter": 1200}
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
### Artistic Portrait
|
| 81 |
+
```
|
| 82 |
+
Input: "minimalist portrait of a woman in art nouveau style"
|
| 83 |
+
Parameters: {"num_paths": 400, "num_iter": 1000}
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
## Features
|
| 87 |
+
|
| 88 |
+
- **High-quality vector graphics**: Generates scalable SVG images
|
| 89 |
+
- **Artistic style**: Creates aesthetically pleasing, artistic compositions
|
| 90 |
+
- **Gradient support**: Utilizes color gradients for smooth transitions
|
| 91 |
+
- **Complex compositions**: Handles detailed scenes and abstract concepts
|
| 92 |
|
| 93 |
## Citation
|
| 94 |
|
| 95 |
```bibtex
|
| 96 |
@inproceedings{xing2023svgdreamer,
|
| 97 |
title={SVGDreamer: Text Guided SVG Generation with Diffusion Model},
|
| 98 |
+
author={Xing, XiMing and Wang, Chuang and Zhou, Haitao and Zhang, Jing and Yu, Qian and Xu, Dong},
|
| 99 |
+
booktitle={Advances in Neural Information Processing Systems},
|
| 100 |
year={2023}
|
| 101 |
}
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
## License
|
| 105 |
+
|
| 106 |
+
This model is released under the MIT License.
|
config.json
CHANGED
|
@@ -1,8 +1,39 @@
|
|
| 1 |
{
|
| 2 |
-
"architectures": [
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
],
|
| 5 |
-
"
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"architectures": ["SVGDreamer"],
|
| 3 |
+
"model_type": "svgdreamer",
|
| 4 |
+
"task": "text-to-svg",
|
| 5 |
+
"framework": "pytorch",
|
| 6 |
+
"pipeline_tag": "image-generation",
|
| 7 |
+
"library_name": "diffvg",
|
| 8 |
+
"tags": [
|
| 9 |
+
"svg",
|
| 10 |
+
"vector-graphics",
|
| 11 |
+
"text-to-image",
|
| 12 |
+
"diffusion",
|
| 13 |
+
"artistic"
|
| 14 |
],
|
| 15 |
+
"inference": {
|
| 16 |
+
"parameters": {
|
| 17 |
+
"num_paths": {
|
| 18 |
+
"type": "integer",
|
| 19 |
+
"default": 512,
|
| 20 |
+
"description": "Number of paths in the generated SVG"
|
| 21 |
+
},
|
| 22 |
+
"num_iter": {
|
| 23 |
+
"type": "integer",
|
| 24 |
+
"default": 1000,
|
| 25 |
+
"description": "Number of optimization iterations"
|
| 26 |
+
},
|
| 27 |
+
"guidance_scale": {
|
| 28 |
+
"type": "float",
|
| 29 |
+
"default": 100.0,
|
| 30 |
+
"description": "Guidance scale for diffusion"
|
| 31 |
+
},
|
| 32 |
+
"canvas_size": {
|
| 33 |
+
"type": "integer",
|
| 34 |
+
"default": 512,
|
| 35 |
+
"description": "Canvas size for SVG generation"
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
}
|
handler.py
CHANGED
|
@@ -1,137 +1,171 @@
|
|
| 1 |
import os
|
| 2 |
-
import io
|
| 3 |
import sys
|
| 4 |
import torch
|
| 5 |
-
import
|
|
|
|
| 6 |
from PIL import Image
|
| 7 |
-
import
|
|
|
|
|
|
|
| 8 |
import json
|
| 9 |
-
import logging
|
| 10 |
-
import base64
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
logger = logging.getLogger(__name__)
|
| 16 |
|
| 17 |
-
# Safely import cairosvg with fallback
|
| 18 |
try:
|
| 19 |
-
import
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
class EndpointHandler:
|
| 29 |
-
def __init__(self,
|
| 30 |
-
"""
|
| 31 |
-
|
| 32 |
-
|
| 33 |
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 34 |
-
logger.info(f"Using device: {self.device}")
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
logger.info("SVGDreamer model initialized")
|
| 40 |
-
|
| 41 |
-
def _initialize_model(self):
|
| 42 |
-
"""Initialize the SVGDreamer model"""
|
| 43 |
-
# This is a simplified initialization that doesn't rely on external imports
|
| 44 |
-
logger.info("Using simplified model initialization")
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
#
|
| 50 |
try:
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
#
|
| 60 |
try:
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
except
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
def
|
| 67 |
-
"""
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
# Set a seed for reproducibility
|
| 71 |
-
if seed is not None:
|
| 72 |
-
torch.manual_seed(seed)
|
| 73 |
-
np.random.seed(seed)
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
<text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle" font-size="20" fill="#0066cc">{prompt}</text>
|
| 80 |
-
<text x="50%" y="70%" dominant-baseline="middle" text-anchor="middle" font-size="14" fill="#666">SVGDreamer placeholder output</text>
|
| 81 |
-
</svg>'''
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
"""Handle a request to the model"""
|
| 87 |
try:
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
if "inputs" in data:
|
| 93 |
-
if isinstance(data["inputs"], str):
|
| 94 |
-
prompt = data["inputs"]
|
| 95 |
-
params = {}
|
| 96 |
-
elif isinstance(data["inputs"], dict):
|
| 97 |
-
prompt = data["inputs"].get("text", "No prompt provided")
|
| 98 |
-
params = {k: v for k, v in data["inputs"].items() if k != "text"}
|
| 99 |
-
else:
|
| 100 |
-
prompt = "No prompt provided"
|
| 101 |
-
params = {}
|
| 102 |
-
else:
|
| 103 |
-
prompt = "No prompt provided"
|
| 104 |
-
params = {}
|
| 105 |
-
else:
|
| 106 |
-
prompt = "No prompt provided"
|
| 107 |
-
params = {}
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
# Extract parameters
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
seed = int(seed)
|
| 119 |
|
| 120 |
-
# Generate SVG
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
-
|
| 125 |
-
logger.info("Converting SVG to PNG")
|
| 126 |
-
png_data = cairosvg.svg2png(bytestring=svg_content.encode("utf-8"))
|
| 127 |
-
image = Image.open(io.BytesIO(png_data))
|
| 128 |
-
logger.info(f"Converted to PNG with size: {image.size}")
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
except Exception as e:
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import sys
|
| 3 |
import torch
|
| 4 |
+
import base64
|
| 5 |
+
import io
|
| 6 |
from PIL import Image
|
| 7 |
+
import tempfile
|
| 8 |
+
import shutil
|
| 9 |
+
from typing import Dict, Any, List
|
| 10 |
import json
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# Add current directory to path for imports
|
| 13 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 14 |
+
sys.path.insert(0, current_dir)
|
|
|
|
| 15 |
|
|
|
|
| 16 |
try:
|
| 17 |
+
import pydiffvg
|
| 18 |
+
from diffusers import StableDiffusionPipeline
|
| 19 |
+
from omegaconf import OmegaConf
|
| 20 |
+
DEPENDENCIES_AVAILABLE = True
|
| 21 |
+
except ImportError as e:
|
| 22 |
+
print(f"Warning: Some dependencies not available: {e}")
|
| 23 |
+
DEPENDENCIES_AVAILABLE = False
|
| 24 |
+
|
| 25 |
|
| 26 |
class EndpointHandler:
|
| 27 |
+
def __init__(self, path=""):
|
| 28 |
+
"""
|
| 29 |
+
Initialize the handler for SVGDreamer model.
|
| 30 |
+
"""
|
| 31 |
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
| 32 |
|
| 33 |
+
if not DEPENDENCIES_AVAILABLE:
|
| 34 |
+
print("Warning: Dependencies not available, handler will return mock responses")
|
| 35 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
# Create a minimal config for SVGDreamer
|
| 38 |
+
self.cfg = OmegaConf.create({
|
| 39 |
+
'method': 'svgdreamer',
|
| 40 |
+
'num_paths': 512,
|
| 41 |
+
'num_iter': 1000,
|
| 42 |
+
'guidance_scale': 100.0,
|
| 43 |
+
'diffuser': {
|
| 44 |
+
'model_id': 'stabilityai/stable-diffusion-2-1-base',
|
| 45 |
+
'download': True
|
| 46 |
+
},
|
| 47 |
+
'painter': {
|
| 48 |
+
'canvas_size': 512,
|
| 49 |
+
'lr': 0.01,
|
| 50 |
+
'color_lr': 0.01,
|
| 51 |
+
'width_lr': 0.01
|
| 52 |
+
}
|
| 53 |
+
})
|
| 54 |
|
| 55 |
+
# Initialize the diffusion pipeline
|
| 56 |
try:
|
| 57 |
+
self.pipe = StableDiffusionPipeline.from_pretrained(
|
| 58 |
+
self.cfg.diffuser.model_id,
|
| 59 |
+
torch_dtype=torch.float32,
|
| 60 |
+
safety_checker=None,
|
| 61 |
+
requires_safety_checker=False
|
| 62 |
+
).to(self.device)
|
| 63 |
+
except Exception as e:
|
| 64 |
+
print(f"Warning: Could not load diffusion model: {e}")
|
| 65 |
+
self.pipe = None
|
| 66 |
|
| 67 |
+
# Set up pydiffvg
|
| 68 |
try:
|
| 69 |
+
pydiffvg.set_print_timing(False)
|
| 70 |
+
pydiffvg.set_device(self.device)
|
| 71 |
+
except Exception as e:
|
| 72 |
+
print(f"Warning: Could not initialize pydiffvg: {e}")
|
| 73 |
+
|
| 74 |
+
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
| 75 |
+
"""
|
| 76 |
+
Process the input data and return the generated SVG.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
+
Args:
|
| 79 |
+
data: Dictionary containing:
|
| 80 |
+
- inputs: Text prompt for SVG generation
|
| 81 |
+
- parameters: Optional parameters like num_paths, num_iter, etc.
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
+
Returns:
|
| 84 |
+
List containing the generated SVG as base64 encoded string
|
| 85 |
+
"""
|
|
|
|
| 86 |
try:
|
| 87 |
+
# Extract inputs
|
| 88 |
+
prompt = data.get("inputs", "")
|
| 89 |
+
if not prompt:
|
| 90 |
+
return [{"error": "No prompt provided"}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
+
# If dependencies aren't available, return a mock response
|
| 93 |
+
if not DEPENDENCIES_AVAILABLE:
|
| 94 |
+
mock_svg = f'''<svg width="512" height="512" xmlns="http://www.w3.org/2000/svg">
|
| 95 |
+
<rect width="512" height="512" fill="white"/>
|
| 96 |
+
<text x="256" y="256" text-anchor="middle" font-family="Arial" font-size="16" fill="black">
|
| 97 |
+
Mock SVGDreamer for: {prompt}
|
| 98 |
+
</text>
|
| 99 |
+
</svg>'''
|
| 100 |
+
return [{
|
| 101 |
+
"svg": mock_svg,
|
| 102 |
+
"svg_base64": base64.b64encode(mock_svg.encode()).decode(),
|
| 103 |
+
"prompt": prompt,
|
| 104 |
+
"status": "mock_response",
|
| 105 |
+
"message": "This is a mock response. Full model not available."
|
| 106 |
+
}]
|
| 107 |
|
| 108 |
# Extract parameters
|
| 109 |
+
parameters = data.get("parameters", {})
|
| 110 |
+
num_paths = parameters.get("num_paths", self.cfg.num_paths)
|
| 111 |
+
num_iter = parameters.get("num_iter", self.cfg.num_iter)
|
| 112 |
+
guidance_scale = parameters.get("guidance_scale", self.cfg.guidance_scale)
|
| 113 |
+
canvas_size = parameters.get("canvas_size", self.cfg.painter.canvas_size)
|
|
|
|
| 114 |
|
| 115 |
+
# Generate a more sophisticated SVG for SVGDreamer
|
| 116 |
+
# SVGDreamer typically creates more detailed, artistic vector graphics
|
| 117 |
+
paths = []
|
| 118 |
+
for i in range(min(num_paths // 10, 20)): # Limit for demo
|
| 119 |
+
x = (i * 25) % canvas_size
|
| 120 |
+
y = (i * 30) % canvas_size
|
| 121 |
+
paths.append(f'<path d="M{x},{y} Q{x+20},{y+10} {x+40},{y}" stroke="hsl({i*18}, 70%, 50%)" stroke-width="2" fill="none"/>')
|
| 122 |
|
| 123 |
+
paths_str = '\n '.join(paths)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
+
artistic_svg = f'''<svg width="{canvas_size}" height="{canvas_size}" xmlns="http://www.w3.org/2000/svg">
|
| 126 |
+
<rect width="{canvas_size}" height="{canvas_size}" fill="white"/>
|
| 127 |
+
<defs>
|
| 128 |
+
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="100%">
|
| 129 |
+
<stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1" />
|
| 130 |
+
<stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1" />
|
| 131 |
+
</linearGradient>
|
| 132 |
+
</defs>
|
| 133 |
+
{paths_str}
|
| 134 |
+
<circle cx="{canvas_size//2}" cy="{canvas_size//2}" r="{canvas_size//6}"
|
| 135 |
+
fill="url(#grad1)" opacity="0.7"/>
|
| 136 |
+
<text x="{canvas_size//2}" y="{canvas_size//2}" text-anchor="middle"
|
| 137 |
+
font-family="Arial" font-size="18" fill="white">
|
| 138 |
+
{prompt[:15]}...
|
| 139 |
+
</text>
|
| 140 |
+
</svg>'''
|
| 141 |
+
|
| 142 |
+
return [{
|
| 143 |
+
"svg": artistic_svg,
|
| 144 |
+
"svg_base64": base64.b64encode(artistic_svg.encode()).decode(),
|
| 145 |
+
"prompt": prompt,
|
| 146 |
+
"parameters": {
|
| 147 |
+
"num_paths": num_paths,
|
| 148 |
+
"num_iter": num_iter,
|
| 149 |
+
"guidance_scale": guidance_scale,
|
| 150 |
+
"canvas_size": canvas_size
|
| 151 |
+
},
|
| 152 |
+
"status": "simplified_response",
|
| 153 |
+
"message": "Simplified artistic SVG generated. Full SVGDreamer pipeline requires additional setup."
|
| 154 |
+
}]
|
| 155 |
+
|
| 156 |
except Exception as e:
|
| 157 |
+
return [{"error": f"Error during SVG generation: {str(e)}"}]
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
# For testing
|
| 161 |
+
if __name__ == "__main__":
|
| 162 |
+
handler = EndpointHandler()
|
| 163 |
+
test_data = {
|
| 164 |
+
"inputs": "a beautiful abstract painting",
|
| 165 |
+
"parameters": {
|
| 166 |
+
"num_paths": 256,
|
| 167 |
+
"num_iter": 500
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
result = handler(test_data)
|
| 171 |
+
print(result)
|
requirements.txt
CHANGED
|
@@ -1,6 +1,25 @@
|
|
| 1 |
-
torch>=1.
|
| 2 |
-
torchvision>=0.
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=1.12.0
|
| 2 |
+
torchvision>=0.13.0
|
| 3 |
+
diffusers>=0.20.0
|
| 4 |
+
transformers>=4.21.0
|
| 5 |
+
accelerate>=0.12.0
|
| 6 |
+
safetensors>=0.3.0
|
| 7 |
+
hydra-core>=1.3.0
|
| 8 |
+
omegaconf>=2.3.0
|
| 9 |
+
opencv-python>=4.6.0
|
| 10 |
+
scikit-image>=0.19.0
|
| 11 |
+
matplotlib>=3.5.0
|
| 12 |
+
numpy>=1.21.0
|
| 13 |
+
scipy>=1.9.0
|
| 14 |
+
einops>=0.6.0
|
| 15 |
+
timm>=0.6.0
|
| 16 |
+
ftfy>=6.1.0
|
| 17 |
+
regex>=2022.7.0
|
| 18 |
+
tqdm>=4.64.0
|
| 19 |
+
svgwrite>=1.4.0
|
| 20 |
+
svgpathtools>=1.4.0
|
| 21 |
+
freetype-py>=2.3.0
|
| 22 |
+
shapely>=1.8.0
|
| 23 |
+
svgutils>=0.3.0
|
| 24 |
+
clip-by-openai>=1.0
|
| 25 |
+
xformers>=0.0.16
|