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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
import os
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import cairosvg
|
| 6 |
+
import io
|
| 7 |
+
import tempfile
|
| 8 |
+
import argparse
|
| 9 |
+
import gc
|
| 10 |
+
import yaml
|
| 11 |
+
import glob
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
from decoder import SketchDecoder
|
| 15 |
+
from transformers import AutoTokenizer, AutoProcessor
|
| 16 |
+
from qwen_vl_utils import process_vision_info
|
| 17 |
+
from tokenizer import SVGTokenizer
|
| 18 |
+
|
| 19 |
+
with open('https://huggingface.co/OmniSVG/OmniSVG/resolve/main/config.yaml', 'r') as f:
|
| 20 |
+
config = yaml.safe_load(f)
|
| 21 |
+
|
| 22 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 23 |
+
|
| 24 |
+
tokenizer = None
|
| 25 |
+
processor = None
|
| 26 |
+
sketch_decoder = None
|
| 27 |
+
svg_tokenizer = None
|
| 28 |
+
|
| 29 |
+
# System prompt
|
| 30 |
+
SYSTEM_PROMPT = "You are a multimodal SVG generation assistant capable of generating SVG code from both text descriptions and images."
|
| 31 |
+
SUPPORTED_FORMATS = ['.png', '.jpg', '.jpeg', '.webp', '.bmp', '.gif']
|
| 32 |
+
|
| 33 |
+
def parse_args():
|
| 34 |
+
"""Parse command line arguments"""
|
| 35 |
+
parser = argparse.ArgumentParser(description='SVG Generator Service')
|
| 36 |
+
parser.add_argument('--listen', type=str, default='0.0.0.0',
|
| 37 |
+
help='Listen address (default: 0.0.0.0)')
|
| 38 |
+
parser.add_argument('--port', type=int, default=7860,
|
| 39 |
+
help='Port number (default: 7860)')
|
| 40 |
+
parser.add_argument('--share', action='store_true',
|
| 41 |
+
help='Enable gradio share link')
|
| 42 |
+
parser.add_argument('--debug', action='store_true',
|
| 43 |
+
help='Enable debug mode')
|
| 44 |
+
return parser.parse_args()
|
| 45 |
+
|
| 46 |
+
def load_models():
|
| 47 |
+
"""Load models"""
|
| 48 |
+
global tokenizer, processor, sketch_decoder, svg_tokenizer
|
| 49 |
+
|
| 50 |
+
if tokenizer is None:
|
| 51 |
+
tokenizer = AutoTokenizer.from_pretrained("/mnt/jfs-test/Qwen2.5-VL-3B-Instruct", padding_side="left")
|
| 52 |
+
processor = AutoProcessor.from_pretrained("/mnt/jfs-test/Qwen2.5-VL-3B-Instruct", padding_side="left")
|
| 53 |
+
|
| 54 |
+
sketch_decoder = SketchDecoder()
|
| 55 |
+
|
| 56 |
+
sketch_weight_path = "https://huggingface.co/OmniSVG/OmniSVG/resolve/main/OmniSVG-3B.bin"
|
| 57 |
+
sketch_decoder.load_state_dict(torch.load(sketch_weight_path))
|
| 58 |
+
sketch_decoder = sketch_decoder.to(device).eval()
|
| 59 |
+
|
| 60 |
+
svg_tokenizer = SVGTokenizer('https://huggingface.co/OmniSVG/OmniSVG/resolve/main/config.yaml')
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def process_and_resize_image(image_input, target_size=(200, 200)):
|
| 64 |
+
"""Process and resize image to target size"""
|
| 65 |
+
if isinstance(image_input, str):
|
| 66 |
+
image = Image.open(image_input)
|
| 67 |
+
elif isinstance(image_input, Image.Image):
|
| 68 |
+
image = image_input
|
| 69 |
+
else:
|
| 70 |
+
image = Image.fromarray(image_input)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
image = image.resize(target_size, Image.Resampling.LANCZOS)
|
| 74 |
+
|
| 75 |
+
return image
|
| 76 |
+
|
| 77 |
+
def get_example_images():
|
| 78 |
+
"""Get example images from the examples directory"""
|
| 79 |
+
example_dir = "./examples"
|
| 80 |
+
example_images = []
|
| 81 |
+
|
| 82 |
+
if os.path.exists(example_dir):
|
| 83 |
+
for ext in SUPPORTED_FORMATS:
|
| 84 |
+
pattern = os.path.join(example_dir, f"*{ext}")
|
| 85 |
+
example_images.extend(glob.glob(pattern))
|
| 86 |
+
|
| 87 |
+
example_images.sort()
|
| 88 |
+
|
| 89 |
+
return example_images
|
| 90 |
+
|
| 91 |
+
def process_text_to_svg(text_description):
|
| 92 |
+
"""Process text-to-svg task"""
|
| 93 |
+
load_models()
|
| 94 |
+
|
| 95 |
+
messages = [{
|
| 96 |
+
"role": "system",
|
| 97 |
+
"content": SYSTEM_PROMPT
|
| 98 |
+
}, {
|
| 99 |
+
"role": "user",
|
| 100 |
+
"content": [
|
| 101 |
+
{"type": "text", "text": f"Task: text-to-svg\nDescription: {text_description}\nGenerate SVG code based on the above description."}
|
| 102 |
+
]
|
| 103 |
+
}]
|
| 104 |
+
|
| 105 |
+
text_input = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 106 |
+
inputs = processor(
|
| 107 |
+
text=[text_input],
|
| 108 |
+
truncation=True,
|
| 109 |
+
return_tensors="pt"
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
input_ids = inputs['input_ids'].to(device)
|
| 113 |
+
attention_mask = inputs['attention_mask'].to(device)
|
| 114 |
+
pixel_values = None
|
| 115 |
+
image_grid_thw = None
|
| 116 |
+
|
| 117 |
+
return input_ids, attention_mask, pixel_values, image_grid_thw
|
| 118 |
+
|
| 119 |
+
def process_image_to_svg(image_path):
|
| 120 |
+
"""Process image-to-svg task"""
|
| 121 |
+
load_models()
|
| 122 |
+
|
| 123 |
+
messages = [{
|
| 124 |
+
"role": "system",
|
| 125 |
+
"content": SYSTEM_PROMPT
|
| 126 |
+
}, {
|
| 127 |
+
"role": "user",
|
| 128 |
+
"content": [
|
| 129 |
+
{"type": "text", "text": f"Task: image-to-svg\nGenerate SVG code that accurately represents the following image."},
|
| 130 |
+
{"type": "image", "image": image_path},
|
| 131 |
+
]
|
| 132 |
+
}]
|
| 133 |
+
|
| 134 |
+
text_input = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 135 |
+
image_inputs, _ = process_vision_info(messages)
|
| 136 |
+
|
| 137 |
+
inputs = processor(
|
| 138 |
+
text=[text_input],
|
| 139 |
+
images=image_inputs,
|
| 140 |
+
truncation=True,
|
| 141 |
+
return_tensors="pt"
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
input_ids = inputs['input_ids'].to(device)
|
| 145 |
+
attention_mask = inputs['attention_mask'].to(device)
|
| 146 |
+
pixel_values = inputs['pixel_values'].to(device) if 'pixel_values' in inputs else None
|
| 147 |
+
image_grid_thw = inputs['image_grid_thw'].to(device) if 'image_grid_thw' in inputs else None
|
| 148 |
+
|
| 149 |
+
return input_ids, attention_mask, pixel_values, image_grid_thw
|
| 150 |
+
|
| 151 |
+
def generate_svg(input_ids, attention_mask, pixel_values=None, image_grid_thw=None, task_type="image-to-svg"):
|
| 152 |
+
"""Generate SVG"""
|
| 153 |
+
try:
|
| 154 |
+
# Clean memory before generation
|
| 155 |
+
gc.collect()
|
| 156 |
+
torch.cuda.empty_cache() if torch.cuda.is_available() else None
|
| 157 |
+
|
| 158 |
+
print(f"Generating SVG for {task_type}...")
|
| 159 |
+
|
| 160 |
+
# Generation configuration, just adjust for better results.
|
| 161 |
+
if task_type == "image-to-svg":
|
| 162 |
+
#Image-to-SVG configuration
|
| 163 |
+
gen_config = dict(
|
| 164 |
+
do_sample=True,
|
| 165 |
+
temperature=0.1,
|
| 166 |
+
top_p=0.001,
|
| 167 |
+
top_k=1,
|
| 168 |
+
num_beams=5,
|
| 169 |
+
repetition_penalty=1.05,
|
| 170 |
+
)
|
| 171 |
+
else:
|
| 172 |
+
#Text-to-SVG configuration
|
| 173 |
+
gen_config = dict(
|
| 174 |
+
do_sample=True,
|
| 175 |
+
temperature=0.1,
|
| 176 |
+
top_p=0.001,
|
| 177 |
+
top_k=1,
|
| 178 |
+
repetition_penalty=1.05,
|
| 179 |
+
early_stopping=True,
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
if torch.cuda.is_available():
|
| 183 |
+
torch.cuda.synchronize()
|
| 184 |
+
|
| 185 |
+
# Generate SVG
|
| 186 |
+
model_config = config['model']
|
| 187 |
+
max_length = model_config['max_length']
|
| 188 |
+
output_ids = torch.ones(1, max_length).long().to(device) * model_config['eos_token_id']
|
| 189 |
+
|
| 190 |
+
with torch.no_grad():
|
| 191 |
+
results = sketch_decoder.transformer.generate(
|
| 192 |
+
input_ids=input_ids,
|
| 193 |
+
attention_mask=attention_mask,
|
| 194 |
+
pixel_values=pixel_values,
|
| 195 |
+
image_grid_thw=image_grid_thw,
|
| 196 |
+
max_new_tokens=max_length-1,
|
| 197 |
+
num_return_sequences=1,
|
| 198 |
+
bos_token_id=model_config['bos_token_id'],
|
| 199 |
+
eos_token_id=model_config['eos_token_id'],
|
| 200 |
+
pad_token_id=model_config['pad_token_id'],
|
| 201 |
+
use_cache=True,
|
| 202 |
+
**gen_config
|
| 203 |
+
)
|
| 204 |
+
results = results[:, :max_length-1]
|
| 205 |
+
output_ids[:, :results.shape[1]] = results
|
| 206 |
+
|
| 207 |
+
generated_xy, generated_colors = svg_tokenizer.process_generated_tokens(output_ids)
|
| 208 |
+
|
| 209 |
+
svg_tensors = svg_tokenizer.raster_svg(generated_xy)
|
| 210 |
+
if not svg_tensors or not svg_tensors[0]:
|
| 211 |
+
return "Error: No valid SVG paths generated", None
|
| 212 |
+
|
| 213 |
+
print('Creating SVG...')
|
| 214 |
+
|
| 215 |
+
svg = svg_tokenizer.apply_colors_to_svg(svg_tensors[0], generated_colors)
|
| 216 |
+
|
| 217 |
+
svg_str = svg.to_str()
|
| 218 |
+
|
| 219 |
+
# Convert to PNG for visualization
|
| 220 |
+
png_data = cairosvg.svg2png(bytestring=svg_str.encode('utf-8'))
|
| 221 |
+
png_image = Image.open(io.BytesIO(png_data))
|
| 222 |
+
|
| 223 |
+
return svg_str, png_image
|
| 224 |
+
|
| 225 |
+
except Exception as e:
|
| 226 |
+
print(f"Generation error: {e}")
|
| 227 |
+
import traceback
|
| 228 |
+
traceback.print_exc()
|
| 229 |
+
return f"Error: {e}", None
|
| 230 |
+
|
| 231 |
+
def gradio_image_to_svg(image):
|
| 232 |
+
"""Gradio interface function - image-to-svg"""
|
| 233 |
+
if image is None:
|
| 234 |
+
return "Please upload an image", None
|
| 235 |
+
processed_image = process_and_resize_image(image)
|
| 236 |
+
|
| 237 |
+
# Save temporary image file
|
| 238 |
+
with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp_file:
|
| 239 |
+
processed_image.save(tmp_file.name, format='PNG')
|
| 240 |
+
tmp_path = tmp_file.name
|
| 241 |
+
|
| 242 |
+
try:
|
| 243 |
+
input_ids, attention_mask, pixel_values, image_grid_thw = process_image_to_svg(tmp_path)
|
| 244 |
+
svg_code, png_image = generate_svg(input_ids, attention_mask, pixel_values, image_grid_thw, "image-to-svg")
|
| 245 |
+
return svg_code, png_image
|
| 246 |
+
finally:
|
| 247 |
+
# Clean up temporary file
|
| 248 |
+
if os.path.exists(tmp_path):
|
| 249 |
+
os.unlink(tmp_path)
|
| 250 |
+
|
| 251 |
+
def gradio_text_to_svg(text_description):
|
| 252 |
+
"""Gradio interface function - text-to-svg"""
|
| 253 |
+
if not text_description or text_description.strip() == "":
|
| 254 |
+
return "Please enter a description", None
|
| 255 |
+
|
| 256 |
+
input_ids, attention_mask, pixel_values, image_grid_thw = process_text_to_svg(text_description)
|
| 257 |
+
svg_code, png_image = generate_svg(input_ids, attention_mask, pixel_values, image_grid_thw, "text-to-svg")
|
| 258 |
+
return svg_code, png_image
|
| 259 |
+
|
| 260 |
+
def create_interface():
|
| 261 |
+
# Example texts
|
| 262 |
+
example_texts = [
|
| 263 |
+
"A red heart shape with rounded corners.",
|
| 264 |
+
"A yellow star with five points.",
|
| 265 |
+
"Cloud icon with an upward arrow symbolizes uploading or cloud storage.",
|
| 266 |
+
"A brown chocolate bar is depicted in four square segments with a shiny glossy finish.",
|
| 267 |
+
"A colorful moving truck icon with a red and orange cargo container.",
|
| 268 |
+
"A gray padlock icon symbolizes security and protection.",
|
| 269 |
+
"A light blue T-shirt icon is outlined with a bold blue border.",
|
| 270 |
+
"A person in a blue shirt and dark pants stands with one hand in a pocket gesturing outward.",
|
| 271 |
+
]
|
| 272 |
+
example_images = get_example_images()
|
| 273 |
+
|
| 274 |
+
with gr.Blocks(title="OmniSVG Demo Page", theme=gr.themes.Soft()) as demo:
|
| 275 |
+
gr.Markdown("# OmniSVG Demo Page")
|
| 276 |
+
gr.Markdown("Generate SVG code from images or text descriptions")
|
| 277 |
+
|
| 278 |
+
with gr.Tabs():
|
| 279 |
+
# Image-to-SVG tab
|
| 280 |
+
with gr.TabItem("Image-to-SVG"):
|
| 281 |
+
with gr.Row():
|
| 282 |
+
with gr.Column():
|
| 283 |
+
image_input = gr.Image(
|
| 284 |
+
label="Input Image",
|
| 285 |
+
type="pil",
|
| 286 |
+
image_mode="RGBA"
|
| 287 |
+
)
|
| 288 |
+
if example_images:
|
| 289 |
+
gr.Examples(
|
| 290 |
+
examples=example_images,
|
| 291 |
+
inputs=[image_input],
|
| 292 |
+
label="Example Images (click to use)",
|
| 293 |
+
examples_per_page=10
|
| 294 |
+
)
|
| 295 |
+
image_generate_btn = gr.Button("Generate SVG", variant="primary")
|
| 296 |
+
|
| 297 |
+
with gr.Column():
|
| 298 |
+
image_svg_output = gr.Textbox(
|
| 299 |
+
label="Generated SVG Code",
|
| 300 |
+
lines=10,
|
| 301 |
+
max_lines=20,
|
| 302 |
+
show_copy_button=True
|
| 303 |
+
)
|
| 304 |
+
image_png_preview = gr.Image(label="SVG Preview", type="pil")
|
| 305 |
+
|
| 306 |
+
image_generate_btn.click(
|
| 307 |
+
fn=gradio_image_to_svg,
|
| 308 |
+
inputs=[image_input],
|
| 309 |
+
outputs=[image_svg_output, image_png_preview],
|
| 310 |
+
queue=True
|
| 311 |
+
)
|
| 312 |
+
|
| 313 |
+
# Text-to-SVG tab
|
| 314 |
+
with gr.TabItem("Text-to-SVG"):
|
| 315 |
+
with gr.Row():
|
| 316 |
+
with gr.Column():
|
| 317 |
+
text_input = gr.Textbox(
|
| 318 |
+
label="Description",
|
| 319 |
+
placeholder="Enter SVG description, e.g.: a red circle with a blue square inside",
|
| 320 |
+
lines=3
|
| 321 |
+
)
|
| 322 |
+
|
| 323 |
+
# Add example texts
|
| 324 |
+
gr.Examples(
|
| 325 |
+
examples=[[text] for text in example_texts],
|
| 326 |
+
inputs=[text_input],
|
| 327 |
+
label="Example Descriptions (click to use)",
|
| 328 |
+
examples_per_page=10
|
| 329 |
+
)
|
| 330 |
+
|
| 331 |
+
text_generate_btn = gr.Button("Generate SVG", variant="primary")
|
| 332 |
+
|
| 333 |
+
with gr.Column():
|
| 334 |
+
text_svg_output = gr.Textbox(
|
| 335 |
+
label="Generated SVG Code",
|
| 336 |
+
lines=10,
|
| 337 |
+
max_lines=20,
|
| 338 |
+
show_copy_button=True
|
| 339 |
+
)
|
| 340 |
+
text_png_preview = gr.Image(label="SVG Preview", type="pil")
|
| 341 |
+
|
| 342 |
+
text_generate_btn.click(
|
| 343 |
+
fn=gradio_text_to_svg,
|
| 344 |
+
inputs=[text_input],
|
| 345 |
+
outputs=[text_svg_output, text_png_preview],
|
| 346 |
+
queue=True
|
| 347 |
+
)
|
| 348 |
+
|
| 349 |
+
# Add usage instructions
|
| 350 |
+
gr.Markdown("""
|
| 351 |
+
## Usage Instructions
|
| 352 |
+
- **Image-to-SVG**: Upload a PNG image and click "Generate SVG"
|
| 353 |
+
- **Text-to-SVG**: Enter a text description or click an example, then click "Generate SVG"
|
| 354 |
+
|
| 355 |
+
""")
|
| 356 |
+
|
| 357 |
+
return demo
|
| 358 |
+
|
| 359 |
+
if __name__ == "__main__":
|
| 360 |
+
# Set environment variable to avoid tokenizer parallelization warning
|
| 361 |
+
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
| 362 |
+
|
| 363 |
+
args = parse_args()
|
| 364 |
+
|
| 365 |
+
# Load models before starting
|
| 366 |
+
print("Loading models...")
|
| 367 |
+
load_models()
|
| 368 |
+
print("Models loaded successfully!")
|
| 369 |
+
|
| 370 |
+
# Create and launch interface
|
| 371 |
+
demo = create_interface()
|
| 372 |
+
demo.launch(
|
| 373 |
+
server_name=args.listen,
|
| 374 |
+
server_port=args.port,
|
| 375 |
+
share=args.share,
|
| 376 |
+
debug=args.debug
|
| 377 |
+
)
|