AkashKumarave commited on
Commit
1ecfe0e
·
verified ·
1 Parent(s): e545804

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -16
app.py CHANGED
@@ -25,10 +25,8 @@ def convert_to_vector(
25
  input_path = "temp_input.jpg"
26
  output_path = "temp_output.svg"
27
 
28
- # Save the input image to a temporary file
29
  image.save(input_path)
30
 
31
- # Convert the image to SVG using vtracer
32
  vtracer.convert_image_to_svg_py(
33
  input_path,
34
  output_path,
@@ -45,11 +43,9 @@ def convert_to_vector(
45
  path_precision=int(path_precision)
46
  )
47
 
48
- # Read the SVG content
49
  with open(output_path, "rb") as f:
50
  svg_content = f.read()
51
 
52
- # Clean up temporary files
53
  os.remove(input_path)
54
  os.remove(output_path)
55
 
@@ -58,20 +54,16 @@ def convert_to_vector(
58
  @app.route('/vectorize', methods=['POST'])
59
  def vectorize_endpoint():
60
  try:
61
- # Handle raw image data in the request body
62
  if request.data:
63
  image = Image.open(io.BytesIO(request.data)).convert('RGB')
64
- # Fallback for multipart/form-data
65
  elif 'image' in request.files:
66
  file = request.files['image']
67
  image = Image.open(file).convert('RGB')
68
  else:
69
  return jsonify({'error': 'No image data provided'}), 400
70
 
71
- # Process the image to SVG with default settings
72
  svg_content = convert_to_vector(image)
73
 
74
- # Return the SVG as a response
75
  return send_file(
76
  io.BytesIO(svg_content),
77
  mimetype='image/svg+xml',
@@ -79,11 +71,4 @@ def vectorize_endpoint():
79
  download_name='vectorized.svg'
80
  )
81
  except Exception as e:
82
- return jsonify({'error': str(e)}), 500
83
-
84
- @app.route('/')
85
- def index():
86
- return jsonify({'status': 'Image Vectorization API is running'})
87
-
88
- if __name__ == '__main__':
89
- app.run(host='0.0.0.0', port=7860)
 
25
  input_path = "temp_input.jpg"
26
  output_path = "temp_output.svg"
27
 
 
28
  image.save(input_path)
29
 
 
30
  vtracer.convert_image_to_svg_py(
31
  input_path,
32
  output_path,
 
43
  path_precision=int(path_precision)
44
  )
45
 
 
46
  with open(output_path, "rb") as f:
47
  svg_content = f.read()
48
 
 
49
  os.remove(input_path)
50
  os.remove(output_path)
51
 
 
54
  @app.route('/vectorize', methods=['POST'])
55
  def vectorize_endpoint():
56
  try:
 
57
  if request.data:
58
  image = Image.open(io.BytesIO(request.data)).convert('RGB')
 
59
  elif 'image' in request.files:
60
  file = request.files['image']
61
  image = Image.open(file).convert('RGB')
62
  else:
63
  return jsonify({'error': 'No image data provided'}), 400
64
 
 
65
  svg_content = convert_to_vector(image)
66
 
 
67
  return send_file(
68
  io.BytesIO(svg_content),
69
  mimetype='image/svg+xml',
 
71
  download_name='vectorized.svg'
72
  )
73
  except Exception as e:
74
+ return jsonify({'error': str