Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
-
from flask import Flask, request, jsonify
|
| 2 |
from flask_cors import CORS
|
| 3 |
import vtracer
|
| 4 |
from PIL import Image
|
| 5 |
import io
|
| 6 |
import os
|
| 7 |
import logging
|
|
|
|
| 8 |
|
| 9 |
# Set up logging
|
| 10 |
logging.basicConfig(level=logging.INFO)
|
|
@@ -76,24 +77,30 @@ def convert_to_vector(
|
|
| 76 |
@app.route('/convert', methods=['POST'])
|
| 77 |
def convert_image():
|
| 78 |
try:
|
| 79 |
-
# Handle
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
# Get parameters (with defaults)
|
| 86 |
-
colormode =
|
| 87 |
-
hierarchical =
|
| 88 |
-
mode =
|
| 89 |
-
filter_speckle = int(
|
| 90 |
-
color_precision = int(
|
| 91 |
-
layer_difference = int(
|
| 92 |
-
corner_threshold = int(
|
| 93 |
-
length_threshold = float(
|
| 94 |
-
max_iterations = int(
|
| 95 |
-
splice_threshold = int(
|
| 96 |
-
path_precision = int(
|
| 97 |
|
| 98 |
logger.info("Received request to /convert")
|
| 99 |
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
from flask_cors import CORS
|
| 3 |
import vtracer
|
| 4 |
from PIL import Image
|
| 5 |
import io
|
| 6 |
import os
|
| 7 |
import logging
|
| 8 |
+
import base64
|
| 9 |
|
| 10 |
# Set up logging
|
| 11 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 77 |
@app.route('/convert', methods=['POST'])
|
| 78 |
def convert_image():
|
| 79 |
try:
|
| 80 |
+
# Handle JSON payload
|
| 81 |
+
data = request.get_json()
|
| 82 |
+
if not data or 'file' not in data:
|
| 83 |
+
return jsonify({'error': 'No image data provided'}), 400
|
| 84 |
+
|
| 85 |
+
# Decode base64 image
|
| 86 |
+
base64_string = data['file']
|
| 87 |
+
if base64_string.startswith('data:image'):
|
| 88 |
+
base64_string = base64_string.split(',')[1]
|
| 89 |
+
image_data = base64.b64decode(base64_string)
|
| 90 |
+
image = Image.open(io.BytesIO(image_data)).convert('RGB')
|
| 91 |
|
| 92 |
# Get parameters (with defaults)
|
| 93 |
+
colormode = data.get('colormode', 'color')
|
| 94 |
+
hierarchical = data.get('hierarchical', 'stacked')
|
| 95 |
+
mode = data.get('mode', 'spline')
|
| 96 |
+
filter_speckle = int(data.get('filter_speckle', 4))
|
| 97 |
+
color_precision = int(data.get('color_precision', 6))
|
| 98 |
+
layer_difference = int(data.get('layer_difference', 16))
|
| 99 |
+
corner_threshold = int(data.get('corner_threshold', 60))
|
| 100 |
+
length_threshold = float(data.get('length_threshold', 4.0))
|
| 101 |
+
max_iterations = int(data.get('max_iterations', 10))
|
| 102 |
+
splice_threshold = int(data.get('splice_threshold', 45))
|
| 103 |
+
path_precision = int(data.get('path_precision', 3))
|
| 104 |
|
| 105 |
logger.info("Received request to /convert")
|
| 106 |
|