Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,10 +28,16 @@ def upload_to_aws(local_file, s3_file):
|
|
| 28 |
return None
|
| 29 |
|
| 30 |
def convert_image(image_url, color_mode, hierarchical, mode, filter_speckle,
|
| 31 |
-
|
| 32 |
-
|
| 33 |
"""Converts an image from a URL to SVG using vtracer with customizable parameters."""
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
try:
|
| 36 |
# Fetch the image from the URL
|
| 37 |
response = requests.get(image_url)
|
|
@@ -64,7 +70,6 @@ def convert_image(image_url, color_mode, hierarchical, mode, filter_speckle,
|
|
| 64 |
path_precision=int(path_precision)
|
| 65 |
)
|
| 66 |
except Exception as e:
|
| 67 |
-
# logging.error(f"Error during image processing or SVG conversion: {e}")
|
| 68 |
return gr.HTML(f'<p style="color: red;">Error during image processing or SVG conversion: {str(e)}</p>'), None, None
|
| 69 |
|
| 70 |
# Save the SVG string to a temporary file
|
|
@@ -77,7 +82,6 @@ def convert_image(image_url, color_mode, hierarchical, mode, filter_speckle,
|
|
| 77 |
s3_file_name = temp_file_path.split('/')[-1] # Use the temp file name as the S3 file name
|
| 78 |
file_url = upload_to_aws(temp_file_path, s3_file_name)
|
| 79 |
except Exception as e:
|
| 80 |
-
# logging.error(f"Error uploading to AWS: {e}")
|
| 81 |
return gr.HTML(f'<p style="color: red;">Error uploading to AWS: {str(e)}</p>'), None, None
|
| 82 |
|
| 83 |
# Clean up the temporary file
|
|
@@ -86,7 +90,6 @@ def convert_image(image_url, color_mode, hierarchical, mode, filter_speckle,
|
|
| 86 |
# Return the SVG wrapped in HTML and the file URL
|
| 87 |
return gr.HTML(f'<svg viewBox="0 0 {image.width} {image.height}">{svg_str}</svg>'), file_url, svg_str
|
| 88 |
|
| 89 |
-
|
| 90 |
|
| 91 |
# Gradio interface
|
| 92 |
iface = gr.Blocks()
|
|
|
|
| 28 |
return None
|
| 29 |
|
| 30 |
def convert_image(image_url, color_mode, hierarchical, mode, filter_speckle,
|
| 31 |
+
color_precision, layer_difference, corner_threshold,
|
| 32 |
+
length_threshold, max_iterations, splice_threshold, path_precision):
|
| 33 |
"""Converts an image from a URL to SVG using vtracer with customizable parameters."""
|
| 34 |
+
|
| 35 |
+
# Debugging: Print the received image_url and its type
|
| 36 |
+
print(f"Received image_url: {image_url}, type: {type(image_url)}")
|
| 37 |
+
|
| 38 |
+
if not isinstance(image_url, str):
|
| 39 |
+
return gr.HTML(f'<p style="color: red;">Error: Expected a string URL, got {type(image_url)}</p>'), None, None
|
| 40 |
+
|
| 41 |
try:
|
| 42 |
# Fetch the image from the URL
|
| 43 |
response = requests.get(image_url)
|
|
|
|
| 70 |
path_precision=int(path_precision)
|
| 71 |
)
|
| 72 |
except Exception as e:
|
|
|
|
| 73 |
return gr.HTML(f'<p style="color: red;">Error during image processing or SVG conversion: {str(e)}</p>'), None, None
|
| 74 |
|
| 75 |
# Save the SVG string to a temporary file
|
|
|
|
| 82 |
s3_file_name = temp_file_path.split('/')[-1] # Use the temp file name as the S3 file name
|
| 83 |
file_url = upload_to_aws(temp_file_path, s3_file_name)
|
| 84 |
except Exception as e:
|
|
|
|
| 85 |
return gr.HTML(f'<p style="color: red;">Error uploading to AWS: {str(e)}</p>'), None, None
|
| 86 |
|
| 87 |
# Clean up the temporary file
|
|
|
|
| 90 |
# Return the SVG wrapped in HTML and the file URL
|
| 91 |
return gr.HTML(f'<svg viewBox="0 0 {image.width} {image.height}">{svg_str}</svg>'), file_url, svg_str
|
| 92 |
|
|
|
|
| 93 |
|
| 94 |
# Gradio interface
|
| 95 |
iface = gr.Blocks()
|