VideoGenerator / api.py
Devticks's picture
Upload api.py
77d0b69 verified
raw
history blame
738 Bytes
from flask import Flask, request, jsonify
from handler import EndpointHandler
app = Flask(__name__)
handler = EndpointHandler()
@app.route('/process_image', methods=['POST'])
def process_image():
data = request.json
if data is None:
return jsonify({'error': 'No JSON data received'}), 400
try:
result_image = handler(data)
except Exception as e:
return jsonify({'error': str(e)}), 500
# Convert PIL image to base64 string
buffered = BytesIO()
result_image.save(buffered, format="JPEG")
result_image_str = base64.b64encode(buffered.getvalue()).decode()
return jsonify({'result_image': result_image_str})
if __name__ == '__main__':
app.run(debug=True,port=8000)