File size: 942 Bytes
23d3a4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from flask import Flask, request, jsonify
from test_mode import run_inference
from flask_cors import CORS

app = Flask(__name__)
CORS(app)


# Endpoint to handle image upload and return processed text and image tensor shape
@app.route('/process_predict', methods=['POST'])
def process_predict():
    # Check if the post request has the file part
    if 'image' not in request.files:
        return jsonify({"error": "No image file provided"}), 400
    
    # convert to bytes
    image = request.files['image']
    image_bytes = image.read()

    # result
    result = run_inference(image_bytes)

    print(f"Processed result: {result}")

    if "error" in result:
        return jsonify(result), 500
    
    return jsonify({
        "status": "success",
        "message": "Image processed successfully",
        "data": result
    }), 201


if __name__ == '__main__':
    app.run(debug=True, port=5001)