Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,13 +8,14 @@ def convert_image(image, color_mode, hierarchical, mode, filter_speckle,
|
|
| 8 |
color_precision, layer_difference, corner_threshold,
|
| 9 |
length_threshold, max_iterations, splice_threshold, path_precision):
|
| 10 |
"""Converts an image to SVG using vtracer with customizable parameters."""
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
colormode=color_mode.lower(),
|
| 19 |
hierarchical=hierarchical.lower(),
|
| 20 |
mode=mode.lower(),
|
|
@@ -28,6 +29,7 @@ def convert_image(image, color_mode, hierarchical, mode, filter_speckle,
|
|
| 28 |
path_precision=int(path_precision)
|
| 29 |
)
|
| 30 |
|
|
|
|
| 31 |
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.svg')
|
| 32 |
temp_file.write(svg_str.encode('utf-8'))
|
| 33 |
temp_file.close()
|
|
@@ -42,9 +44,9 @@ with iface:
|
|
| 42 |
fn=convert_image,
|
| 43 |
inputs=[
|
| 44 |
gr.Image(type="pil", label="Upload Image"),
|
| 45 |
-
gr.Radio(choices=["
|
| 46 |
-
gr.Radio(choices=["
|
| 47 |
-
gr.Radio(choices=["
|
| 48 |
gr.Slider(minimum=1, maximum=10, value=4, step=1, label="Filter Speckle"),
|
| 49 |
gr.Slider(minimum=1, maximum=8, value=6, step=1, label="Color Precision"),
|
| 50 |
gr.Slider(minimum=1, maximum=32, value=16, step=1, label="Layer Difference"),
|
|
|
|
| 8 |
color_precision, layer_difference, corner_threshold,
|
| 9 |
length_threshold, max_iterations, splice_threshold, path_precision):
|
| 10 |
"""Converts an image to SVG using vtracer with customizable parameters."""
|
| 11 |
+
# Save image to temporary file, as vtracer 0.6.11 requires a file path
|
| 12 |
+
with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as temp_img:
|
| 13 |
+
image.save(temp_img, format='PNG')
|
| 14 |
+
temp_img_path = temp_img.name
|
| 15 |
|
| 16 |
+
# Convert image to SVG using vtracer
|
| 17 |
+
svg_str = vtracer.convert_image_to_svg(
|
| 18 |
+
image_path=temp_img_path,
|
| 19 |
colormode=color_mode.lower(),
|
| 20 |
hierarchical=hierarchical.lower(),
|
| 21 |
mode=mode.lower(),
|
|
|
|
| 29 |
path_precision=int(path_precision)
|
| 30 |
)
|
| 31 |
|
| 32 |
+
# Save SVG to temporary file for download
|
| 33 |
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.svg')
|
| 34 |
temp_file.write(svg_str.encode('utf-8'))
|
| 35 |
temp_file.close()
|
|
|
|
| 44 |
fn=convert_image,
|
| 45 |
inputs=[
|
| 46 |
gr.Image(type="pil", label="Upload Image"),
|
| 47 |
+
gr.Radio(choices=["color", "binary"], value="color", label="Color Mode"),
|
| 48 |
+
gr.Radio(choices=["stacked", "cutout"], value="stacked", label="Hierarchical"),
|
| 49 |
+
gr.Radio(choices=["spline", "polygon", "none"], value="spline", label="Mode"),
|
| 50 |
gr.Slider(minimum=1, maximum=10, value=4, step=1, label="Filter Speckle"),
|
| 51 |
gr.Slider(minimum=1, maximum=8, value=6, step=1, label="Color Precision"),
|
| 52 |
gr.Slider(minimum=1, maximum=32, value=16, step=1, label="Layer Difference"),
|