AkashKumarave commited on
Commit
ab2459d
·
verified ·
1 Parent(s): 3f63654

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -8
app.py CHANGED
@@ -12,10 +12,8 @@ def convert_to_vector(image, params):
12
  input_path = "temp_input.jpg"
13
  output_svg_path = "temp_output.svg"
14
 
15
- # Save the input image to a temporary file
16
  image.save(input_path)
17
 
18
- # Convert the image to SVG using VTracer with provided parameters
19
  vtracer.convert_image_to_svg_py(
20
  input_path,
21
  output_svg_path,
@@ -32,11 +30,9 @@ def convert_to_vector(image, params):
32
  path_precision=int(params.get("path_precision", 3))
33
  )
34
 
35
- # Read the SVG output
36
  with open(output_svg_path, "rb") as f:
37
  svg_content = f.read()
38
 
39
- # Clean up temporary files
40
  os.remove(input_path)
41
  os.remove(output_svg_path)
42
 
@@ -45,7 +41,6 @@ def convert_to_vector(image, params):
45
  @app.route('/convert-to-vector', methods=['POST'])
46
  def convert_to_vector_endpoint():
47
  try:
48
- # Handle image data
49
  if request.data and not request.is_json:
50
  image = Image.open(io.BytesIO(request.data)).convert('RGB')
51
  elif 'image' in request.files:
@@ -54,7 +49,6 @@ def convert_to_vector_endpoint():
54
  else:
55
  return jsonify({'error': 'No image data provided'}), 400
56
 
57
- # Get parameters from JSON payload or query parameters
58
  if request.is_json:
59
  params = request.get_json()
60
  else:
@@ -72,10 +66,8 @@ def convert_to_vector_endpoint():
72
  "path_precision": request.args.get("path_precision", 3)
73
  }
74
 
75
- # Process the image
76
  svg_content = convert_to_vector(image, params)
77
 
78
- # Return the SVG as a response
79
  return send_file(
80
  io.BytesIO(svg_content),
81
  mimetype='image/svg+xml',
 
12
  input_path = "temp_input.jpg"
13
  output_svg_path = "temp_output.svg"
14
 
 
15
  image.save(input_path)
16
 
 
17
  vtracer.convert_image_to_svg_py(
18
  input_path,
19
  output_svg_path,
 
30
  path_precision=int(params.get("path_precision", 3))
31
  )
32
 
 
33
  with open(output_svg_path, "rb") as f:
34
  svg_content = f.read()
35
 
 
36
  os.remove(input_path)
37
  os.remove(output_svg_path)
38
 
 
41
  @app.route('/convert-to-vector', methods=['POST'])
42
  def convert_to_vector_endpoint():
43
  try:
 
44
  if request.data and not request.is_json:
45
  image = Image.open(io.BytesIO(request.data)).convert('RGB')
46
  elif 'image' in request.files:
 
49
  else:
50
  return jsonify({'error': 'No image data provided'}), 400
51
 
 
52
  if request.is_json:
53
  params = request.get_json()
54
  else:
 
66
  "path_precision": request.args.get("path_precision", 3)
67
  }
68
 
 
69
  svg_content = convert_to_vector(image, params)
70
 
 
71
  return send_file(
72
  io.BytesIO(svg_content),
73
  mimetype='image/svg+xml',