Devticks commited on
Commit
77d0b69
·
verified ·
1 Parent(s): 07f0442

Upload api.py

Browse files
Files changed (1) hide show
  1. api.py +26 -0
api.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from handler import EndpointHandler
3
+
4
+ app = Flask(__name__)
5
+ handler = EndpointHandler()
6
+
7
+ @app.route('/process_image', methods=['POST'])
8
+ def process_image():
9
+ data = request.json
10
+ if data is None:
11
+ return jsonify({'error': 'No JSON data received'}), 400
12
+
13
+ try:
14
+ result_image = handler(data)
15
+ except Exception as e:
16
+ return jsonify({'error': str(e)}), 500
17
+
18
+ # Convert PIL image to base64 string
19
+ buffered = BytesIO()
20
+ result_image.save(buffered, format="JPEG")
21
+ result_image_str = base64.b64encode(buffered.getvalue()).decode()
22
+
23
+ return jsonify({'result_image': result_image_str})
24
+
25
+ if __name__ == '__main__':
26
+ app.run(debug=True,port=8000)