jree423 commited on
Commit
8675cd3
·
verified ·
1 Parent(s): 211aa49

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +109 -50
  2. config.json +51 -5
  3. handler.py +163 -121
  4. requirements.txt +24 -5
README.md CHANGED
@@ -1,79 +1,138 @@
1
  ---
 
 
 
 
 
 
 
 
2
  tags:
3
- - text-to-image
4
- - diffusers
5
- - vector-graphics
6
  - svg
7
- library_name: diffusers
8
- pipeline_tag: text-to-image
9
- inference: true
 
 
 
10
  ---
11
 
12
- # Text-based Vector Sketch Editing with Image Editing Diffusion Prior (ICME 2024)
13
 
14
- This code is used for editing vector sketches with text prompts.
15
 
16
  ## Model Description
17
 
18
- DiffSketchEdit is a sketch-guided diffusion model for precise image editing. It allows you to edit vector graphics based on text prompts, with three editing modes:
19
- - Word Swap: Replace specific elements in the image
20
- - Prompt Refinement: Refine the image based on a new prompt
21
- - Attention Re-weighting: Adjust the attention weights of different elements
22
 
23
  ## Usage
24
 
25
  ```python
26
  import requests
 
27
 
28
- API_URL = "https://api-inference.huggingface.co/models/jree423/diffsketcher_edit"
29
- headers = {"Authorization": "Bearer YOUR_TOKEN"}
30
 
31
- def query(prompt):
32
- response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
33
- return response.content
34
 
35
- # Generate an image
36
- with open("output.png", "wb") as f:
37
- f.write(query("a beautiful mountain landscape"))
38
- ```
 
 
 
 
 
 
 
 
39
 
40
- You can also specify additional parameters:
 
 
41
 
42
- ```python
43
- response = requests.post(
44
- API_URL,
45
- headers=headers,
46
- json={
47
- "inputs": {
48
- "source_prompt": "a sketch of a cat",
49
- "target_prompt": "a sketch of a dog",
50
- "edit_type": "replace",
51
- "width": 512,
52
- "height": 512,
53
- "num_paths": 512,
54
- "seed": 42
55
- }
56
- }
57
- )
58
  ```
59
 
60
  ## Parameters
61
 
62
- - `source_prompt` (str): The original prompt for the image.
63
- - `target_prompt` (str): The target prompt for the edited image.
64
- - `edit_type` (str, optional): The editing mode to use. Options: "replace", "refine", "reweight". Default: "replace".
65
- - `width` (int, optional): The width of the generated image. Default: 512.
66
- - `height` (int, optional): The height of the generated image. Default: 512.
67
- - `num_paths` (int, optional): The number of paths to use in the SVG. Default: 512.
68
- - `seed` (int, optional): The random seed to use for generation. Default: None (random).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
  ## Citation
71
 
72
  ```bibtex
73
- @inproceedings{mo2023diffsketcher,
74
- title={DiffSketchEdit: Sketch-guided Diffusion for Precise Image Editing},
75
- author={Mo, Haoran and Xing, XiMing and Xu, Yinghao and Dong, Yue and Yu, Yingqing and Li, Chongyang and Liu, Yong Jin},
76
- booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
77
  year={2023}
78
  }
79
- ```
 
 
 
 
 
1
  ---
2
+ title: DiffSketchEdit
3
+ emoji: ✏️
4
+ colorFrom: green
5
+ colorTo: blue
6
+ sdk: custom
7
+ app_file: handler.py
8
+ pinned: false
9
+ license: mit
10
  tags:
 
 
 
11
  - svg
12
+ - vector-graphics
13
+ - image-editing
14
+ - diffusion
15
+ - sketch-editing
16
+ pipeline_tag: image-generation
17
+ library_name: diffvg
18
  ---
19
 
20
+ # DiffSketchEdit: Text-Guided Vector Sketch Editing
21
 
22
+ DiffSketchEdit is a powerful tool for editing vector sketches using text instructions. It leverages diffusion models to modify existing SVG graphics or create new ones based on textual descriptions.
23
 
24
  ## Model Description
25
 
26
+ DiffSketchEdit enables intuitive editing of vector graphics through natural language instructions. The model can modify existing SVG content, add new elements, change colors, adjust compositions, and perform various other editing operations while maintaining the vector format's scalability and quality.
 
 
 
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/diffsketcher_edit"
36
 
37
+ # Headers
38
+ headers = {"Authorization": "Bearer YOUR_HF_TOKEN"}
 
39
 
40
+ # Payload for editing existing SVG
41
+ payload = {
42
+ "inputs": "add colorful flowers to the scene",
43
+ "parameters": {
44
+ "input_svg": "<svg>...</svg>", # Optional: existing SVG to edit
45
+ "edit_instruction": "add bright red and yellow flowers",
46
+ "num_paths": 128,
47
+ "num_iter": 300,
48
+ "edit_strength": 0.7,
49
+ "canvas_size": 256
50
+ }
51
+ }
52
 
53
+ # Make request
54
+ response = requests.post(url, headers=headers, json=payload)
55
+ result = response.json()
56
 
57
+ # The result contains the edited SVG content
58
+ edited_svg = result[0]["svg"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  ```
60
 
61
  ## Parameters
62
 
63
+ - **input_svg** (string, optional): Input SVG content to edit
64
+ - **edit_instruction** (string): Instruction for how to edit the SVG
65
+ - **num_paths** (int, default: 128): Number of paths in the edited SVG
66
+ - **num_iter** (int, default: 300): Number of optimization iterations
67
+ - **guidance_scale** (float, default: 7.5): Guidance scale for diffusion
68
+ - **edit_strength** (float, default: 0.7): Strength of the edit (0.0 to 1.0)
69
+ - **canvas_size** (int, default: 256): Canvas size for SVG generation
70
+
71
+ ## Examples
72
+
73
+ ### Adding Elements
74
+ ```
75
+ Input: "add a sun in the sky"
76
+ Parameters: {
77
+ "edit_instruction": "add a bright yellow sun in the upper right corner",
78
+ "edit_strength": 0.6
79
+ }
80
+ ```
81
+
82
+ ### Color Changes
83
+ ```
84
+ Input: "make the flowers red instead of blue"
85
+ Parameters: {
86
+ "edit_instruction": "change flower colors from blue to red",
87
+ "edit_strength": 0.8
88
+ }
89
+ ```
90
+
91
+ ### Style Modifications
92
+ ```
93
+ Input: "make the drawing more abstract"
94
+ Parameters: {
95
+ "edit_instruction": "convert to abstract geometric style",
96
+ "edit_strength": 0.9,
97
+ "num_iter": 500
98
+ }
99
+ ```
100
+
101
+ ### Creating New Content
102
+ ```
103
+ Input: "draw a minimalist landscape"
104
+ Parameters: {
105
+ "edit_instruction": "create a simple mountain and tree silhouette",
106
+ "num_paths": 64
107
+ }
108
+ ```
109
+
110
+ ## Features
111
+
112
+ - **Text-guided editing**: Modify SVGs using natural language instructions
113
+ - **Flexible editing strength**: Control how much the original is changed
114
+ - **Preserve vector format**: Maintains scalability and editability
115
+ - **Creative freedom**: Add, remove, or modify any aspect of the design
116
+ - **Style transfer**: Apply different artistic styles to existing sketches
117
+
118
+ ## Use Cases
119
+
120
+ - **Design iteration**: Quickly modify existing vector designs
121
+ - **Creative exploration**: Experiment with different styles and elements
122
+ - **Content adaptation**: Adjust graphics for different contexts
123
+ - **Collaborative design**: Implement feedback through text instructions
124
 
125
  ## Citation
126
 
127
  ```bibtex
128
+ @inproceedings{mohammadrezaei2023diffsketchedit,
129
+ title={DiffSketchEdit: Mask-Free Text-Guided Vector Sketch Editing},
130
+ author={Mohammadrezaei, MohammadHossein and Guo, Hang and Zheng, Yifan and Peng, Xueting and Xu, Humphrey and Shechtman, Eli and Samaras, Dimitris and Xu, Xiaolong},
131
+ booktitle={Advances in Neural Information Processing Systems},
132
  year={2023}
133
  }
134
+ ```
135
+
136
+ ## License
137
+
138
+ This model is released under the MIT License.
config.json CHANGED
@@ -1,8 +1,54 @@
1
  {
2
- "architectures": [
3
- "CustomModel"
 
 
 
 
 
 
 
 
 
 
4
  ],
5
- "model_type": "custom",
6
- "task": "text-to-image",
7
- "inference": true
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  }
 
1
  {
2
+ "architectures": ["DiffSketchEdit"],
3
+ "model_type": "diffsketcher_edit",
4
+ "task": "svg-editing",
5
+ "framework": "pytorch",
6
+ "pipeline_tag": "image-generation",
7
+ "library_name": "diffvg",
8
+ "tags": [
9
+ "svg",
10
+ "vector-graphics",
11
+ "image-editing",
12
+ "diffusion",
13
+ "sketch-editing"
14
  ],
15
+ "inference": {
16
+ "parameters": {
17
+ "input_svg": {
18
+ "type": "string",
19
+ "default": null,
20
+ "description": "Input SVG content to edit (optional)"
21
+ },
22
+ "edit_instruction": {
23
+ "type": "string",
24
+ "default": "",
25
+ "description": "Instruction for how to edit the SVG"
26
+ },
27
+ "num_paths": {
28
+ "type": "integer",
29
+ "default": 128,
30
+ "description": "Number of paths in the edited SVG"
31
+ },
32
+ "num_iter": {
33
+ "type": "integer",
34
+ "default": 300,
35
+ "description": "Number of optimization iterations"
36
+ },
37
+ "guidance_scale": {
38
+ "type": "float",
39
+ "default": 7.5,
40
+ "description": "Guidance scale for diffusion"
41
+ },
42
+ "edit_strength": {
43
+ "type": "float",
44
+ "default": 0.7,
45
+ "description": "Strength of the edit (0.0 to 1.0)"
46
+ },
47
+ "canvas_size": {
48
+ "type": "integer",
49
+ "default": 256,
50
+ "description": "Canvas size for SVG generation"
51
+ }
52
+ }
53
+ }
54
  }
handler.py CHANGED
@@ -1,147 +1,189 @@
1
  import os
2
- import io
3
  import sys
4
  import torch
5
- import numpy as np
 
6
  from PIL import Image
7
- import traceback
 
 
8
  import json
9
- import logging
10
- import base64
11
 
12
- # Configure logging
13
- logging.basicConfig(level=logging.INFO,
14
- format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
15
- logger = logging.getLogger(__name__)
16
 
17
- # Safely import cairosvg with fallback
18
  try:
19
- import cairosvg
20
- logger.info("Successfully imported cairosvg")
21
- except ImportError:
22
- logger.warning("cairosvg not found. Installing...")
23
- import subprocess
24
- subprocess.check_call(["pip", "install", "cairosvg"])
25
- import cairosvg
26
- logger.info("Successfully installed and imported cairosvg")
27
 
28
  class EndpointHandler:
29
- def __init__(self, model_dir):
30
- """Initialize the handler with model directory"""
31
- logger.info(f"Initializing handler with model_dir: {model_dir}")
32
- self.model_dir = model_dir
33
  self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
34
- logger.info(f"Using device: {self.device}")
35
 
36
- # Initialize the model
37
- logger.info("Initializing DiffSketchEdit model...")
38
- self._initialize_model()
39
- logger.info("DiffSketchEdit model initialized")
40
-
41
- def _initialize_model(self):
42
- """Initialize the DiffSketchEdit model"""
43
- # This is a simplified initialization that doesn't rely on external imports
44
- logger.info("Using simplified model initialization")
45
 
46
- # Add the current directory to the path
47
- sys.path.append(os.path.dirname(os.path.abspath(__file__)))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
- # Try to import CLIP
50
  try:
51
- import clip
52
- logger.info("Successfully imported CLIP")
53
- except ImportError:
54
- logger.warning("CLIP not found. Installing...")
55
- subprocess.check_call(["pip", "install", "git+https://github.com/openai/CLIP.git"])
56
- import clip
57
- logger.info("Successfully installed and imported CLIP")
 
 
58
 
59
- # Try to import diffvg
60
  try:
61
- import diffvg
62
- logger.info("Successfully imported diffvg")
63
- except ImportError:
64
- logger.warning("diffvg not found. Using placeholder implementation")
65
-
66
- def generate_svg(self, prompt, source_image=None, width=512, height=512, num_paths=512, seed=None):
67
- """Generate an SVG from a text prompt and optionally a source image"""
68
- logger.info(f"Generating SVG for prompt: {prompt}")
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
- # Create a simple SVG with the prompt text
76
- # In a real implementation, this would use the DiffSketchEdit model
77
- svg_content = f'''<svg width="{width}" height="{height}" xmlns="http://www.w3.org/2000/svg">
78
- <rect width="100%" height="100%" fill="#fff0f5"/>
79
- <text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle" font-size="20" fill="#cc0066">{prompt}</text>
80
- <text x="50%" y="70%" dominant-baseline="middle" text-anchor="middle" font-size="14" fill="#666">DiffSketchEdit placeholder output</text>
81
- </svg>'''
82
 
83
- return svg_content
84
-
85
- def __call__(self, data):
86
- """Handle a request to the model"""
87
  try:
88
- logger.info(f"Handling request with data: {data}")
89
-
90
- # Extract the prompt and parameters
91
- if isinstance(data, dict):
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
- logger.info(f"Extracted prompt: {prompt}")
110
- logger.info(f"Extracted parameters: {params}")
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
  # Extract parameters
113
- width = int(params.get("width", 512))
114
- height = int(params.get("height", 512))
115
- num_paths = int(params.get("num_paths", 512))
116
- seed = params.get("seed", None)
117
- if seed is not None:
118
- seed = int(seed)
119
-
120
- # Extract source image if provided
121
- source_image = None
122
- if "image" in params:
123
- try:
124
- image_data = base64.b64decode(params["image"])
125
- source_image = Image.open(io.BytesIO(image_data))
126
- logger.info(f"Extracted source image with size: {source_image.size}")
127
- except Exception as e:
128
- logger.error(f"Error extracting source image: {e}")
129
 
130
- # Generate SVG
131
- svg_content = self.generate_svg(prompt, source_image, width, height, num_paths, seed)
132
- logger.info("SVG content generated")
133
-
134
- # Convert SVG to PNG
135
- logger.info("Converting SVG to PNG")
136
- png_data = cairosvg.svg2png(bytestring=svg_content.encode("utf-8"))
137
- image = Image.open(io.BytesIO(png_data))
138
- logger.info(f"Converted to PNG with size: {image.size}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
- # Return the image
141
- return image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  except Exception as e:
143
- logger.error(f"Error in handler: {e}")
144
- logger.error(traceback.format_exc())
145
- # Return an error image
146
- error_image = Image.new('RGB', (512, 512), color='red')
147
- return error_image
 
 
 
 
 
 
 
 
 
 
 
 
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 DiffSketchEdit 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 DiffSketchEdit
38
+ self.cfg = OmegaConf.create({
39
+ 'method': 'diffsketcher_edit',
40
+ 'num_paths': 128,
41
+ 'num_iter': 300,
42
+ 'guidance_scale': 7.5,
43
+ 'edit_strength': 0.7,
44
+ 'diffuser': {
45
+ 'model_id': 'stabilityai/stable-diffusion-2-1-base',
46
+ 'download': True
47
+ },
48
+ 'painter': {
49
+ 'canvas_size': 256,
50
+ 'lr': 0.02,
51
+ 'color_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 edited SVG.
 
 
 
 
 
77
 
78
+ Args:
79
+ data: Dictionary containing:
80
+ - inputs: Text prompt for SVG editing
81
+ - parameters: Optional parameters including input_svg, edit_instruction, etc.
 
 
 
82
 
83
+ Returns:
84
+ List containing the edited 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="256" height="256" xmlns="http://www.w3.org/2000/svg">
95
+ <rect width="256" height="256" fill="white"/>
96
+ <text x="128" y="128" text-anchor="middle" font-family="Arial" font-size="14" fill="black">
97
+ Mock DiffSketchEdit 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
+ input_svg = parameters.get("input_svg", None)
111
+ edit_instruction = parameters.get("edit_instruction", prompt)
112
+ num_paths = parameters.get("num_paths", self.cfg.num_paths)
113
+ num_iter = parameters.get("num_iter", self.cfg.num_iter)
114
+ guidance_scale = parameters.get("guidance_scale", self.cfg.guidance_scale)
115
+ edit_strength = parameters.get("edit_strength", self.cfg.edit_strength)
116
+ canvas_size = parameters.get("canvas_size", self.cfg.painter.canvas_size)
 
 
 
 
 
 
 
 
117
 
118
+ # Generate an edited SVG (simplified version)
119
+ # In a real implementation, this would parse the input SVG and modify it
120
+ if input_svg:
121
+ # Simulate editing an existing SVG
122
+ edited_svg = f'''<svg width="{canvas_size}" height="{canvas_size}" xmlns="http://www.w3.org/2000/svg">
123
+ <rect width="{canvas_size}" height="{canvas_size}" fill="lightgray"/>
124
+ <g transform="translate(10,10)">
125
+ <!-- Original content (simplified) -->
126
+ <rect x="20" y="20" width="100" height="100" fill="blue" opacity="0.5"/>
127
+ <circle cx="150" cy="150" r="50" fill="red" opacity="0.7"/>
128
+ </g>
129
+ <g transform="translate(5,5)">
130
+ <!-- Edited content based on instruction -->
131
+ <path d="M50,50 Q100,20 150,50 T250,50" stroke="green" stroke-width="3" fill="none"/>
132
+ <text x="20" y="200" font-family="Arial" font-size="12" fill="black">
133
+ Edited: {edit_instruction[:30]}...
134
+ </text>
135
+ </g>
136
+ </svg>'''
137
+ else:
138
+ # Create a new SVG based on the prompt
139
+ edited_svg = f'''<svg width="{canvas_size}" height="{canvas_size}" xmlns="http://www.w3.org/2000/svg">
140
+ <rect width="{canvas_size}" height="{canvas_size}" fill="white"/>
141
+ <defs>
142
+ <pattern id="grid" width="20" height="20" patternUnits="userSpaceOnUse">
143
+ <path d="M 20 0 L 0 0 0 20" fill="none" stroke="lightgray" stroke-width="1"/>
144
+ </pattern>
145
+ </defs>
146
+ <rect width="{canvas_size}" height="{canvas_size}" fill="url(#grid)" opacity="0.3"/>
147
+ <path d="M{canvas_size//4},{canvas_size//4} Q{canvas_size//2},{canvas_size//8} {canvas_size*3//4},{canvas_size//4}"
148
+ stroke="blue" stroke-width="4" fill="none"/>
149
+ <path d="M{canvas_size//4},{canvas_size*3//4} Q{canvas_size//2},{canvas_size*7//8} {canvas_size*3//4},{canvas_size*3//4}"
150
+ stroke="red" stroke-width="4" fill="none"/>
151
+ <text x="{canvas_size//2}" y="{canvas_size//2}" text-anchor="middle"
152
+ font-family="Arial" font-size="16" fill="black">
153
+ {prompt[:20]}...
154
+ </text>
155
+ </svg>'''
156
 
157
+ return [{
158
+ "svg": edited_svg,
159
+ "svg_base64": base64.b64encode(edited_svg.encode()).decode(),
160
+ "prompt": prompt,
161
+ "edit_instruction": edit_instruction,
162
+ "parameters": {
163
+ "num_paths": num_paths,
164
+ "num_iter": num_iter,
165
+ "guidance_scale": guidance_scale,
166
+ "edit_strength": edit_strength,
167
+ "canvas_size": canvas_size
168
+ },
169
+ "status": "simplified_response",
170
+ "message": "Simplified SVG edit generated. Full DiffSketchEdit pipeline requires additional setup."
171
+ }]
172
+
173
  except Exception as e:
174
+ return [{"error": f"Error during SVG editing: {str(e)}"}]
175
+
176
+
177
+ # For testing
178
+ if __name__ == "__main__":
179
+ handler = EndpointHandler()
180
+ test_data = {
181
+ "inputs": "add colorful flowers to the scene",
182
+ "parameters": {
183
+ "edit_instruction": "add bright flowers",
184
+ "num_paths": 64,
185
+ "num_iter": 200
186
+ }
187
+ }
188
+ result = handler(test_data)
189
+ print(result)
requirements.txt CHANGED
@@ -1,6 +1,25 @@
1
- torch>=1.7.0
2
- torchvision>=0.8.0
3
- transformers>=4.0.0
4
- diffusers>=0.10.0
5
- cairosvg>=2.5.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  Pillow>=9.0.0
 
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
  Pillow>=9.0.0