Spaces:
Runtime error
Runtime error
gdTharusha
commited on
Commit
•
8a2db3e
1
Parent(s):
f377100
Update app.py
Browse files
app.py
CHANGED
@@ -61,7 +61,7 @@ def preprocess_image(image, blur_radius, sharpen_radius, noise_reduction, detail
|
|
61 |
if enhance_with_ai:
|
62 |
image_np = np.array(image)
|
63 |
# AI-based enhancement for smoothing edges without background removal
|
64 |
-
|
65 |
if remove_bg:
|
66 |
image_np = remove(image_np)
|
67 |
image = Image.fromarray(image_np)
|
@@ -78,20 +78,20 @@ def convert_image(image, blur_radius, sharpen_radius, noise_reduction, detail_le
|
|
78 |
enhance_with_ai, remove_bg, upscale_factor):
|
79 |
"""Convert an image to SVG using vtracer with customizable and advanced parameters."""
|
80 |
|
81 |
-
|
82 |
-
|
|
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
|
94 |
-
try:
|
95 |
# Perform the conversion
|
96 |
svg_str = vtracer.convert_raw_image_to_svg(
|
97 |
img_bytes,
|
@@ -169,8 +169,8 @@ with iface:
|
|
169 |
fn=convert_image,
|
170 |
inputs=[
|
171 |
image_input, blur_radius_input, sharpen_radius_input, noise_reduction_input, detail_level_input, edge_method_input, color_quantization_input,
|
172 |
-
color_mode_input, hierarchical_input, mode_input, filter_speckle_input,
|
173 |
-
|
174 |
splice_threshold_input, path_precision_input, enhance_with_ai_input, remove_bg_input, upscale_factor_input
|
175 |
],
|
176 |
outputs=[svg_output, download_output]
|
|
|
61 |
if enhance_with_ai:
|
62 |
image_np = np.array(image)
|
63 |
# AI-based enhancement for smoothing edges without background removal
|
64 |
+
image_np = cv2.detailEnhance(image_np, sigma_s=10, sigma_r=0.15)
|
65 |
if remove_bg:
|
66 |
image_np = remove(image_np)
|
67 |
image = Image.fromarray(image_np)
|
|
|
78 |
enhance_with_ai, remove_bg, upscale_factor):
|
79 |
"""Convert an image to SVG using vtracer with customizable and advanced parameters."""
|
80 |
|
81 |
+
try:
|
82 |
+
# Preprocess the image with additional detail level settings
|
83 |
+
image = preprocess_image(image, blur_radius, sharpen_radius, noise_reduction, detail_level, edge_method, color_quantization, enhance_with_ai, remove_bg)
|
84 |
|
85 |
+
# Upscale the image if needed
|
86 |
+
if upscale_factor > 1:
|
87 |
+
new_size = (int(image.width * upscale_factor), int(image.height * upscale_factor))
|
88 |
+
image = image.resize(new_size, Image.LANCZOS)
|
89 |
|
90 |
+
# Convert Gradio image to bytes for vtracer compatibility
|
91 |
+
img_byte_array = io.BytesIO()
|
92 |
+
image.save(img_byte_array, format='PNG')
|
93 |
+
img_bytes = img_byte_array.getvalue()
|
94 |
|
|
|
95 |
# Perform the conversion
|
96 |
svg_str = vtracer.convert_raw_image_to_svg(
|
97 |
img_bytes,
|
|
|
169 |
fn=convert_image,
|
170 |
inputs=[
|
171 |
image_input, blur_radius_input, sharpen_radius_input, noise_reduction_input, detail_level_input, edge_method_input, color_quantization_input,
|
172 |
+
color_mode_input, hierarchical_input, mode_input, filter_speckle_input, color_precision_input,
|
173 |
+
layer_difference_input, corner_threshold_input, length_threshold_input, max_iterations_input,
|
174 |
splice_threshold_input, path_precision_input, enhance_with_ai_input, remove_bg_input, upscale_factor_input
|
175 |
],
|
176 |
outputs=[svg_output, download_output]
|