from flask import Flask, request, Response, send_file from doctr.io import DocumentFile from doctr.models import ocr_predictor app = Flask(__name__) model = ocr_predictor(pretrained=True) @app.route("/", methods=["GET"]) def hello(): return {"hello": "world"} @app.route("/ocr", methods=["POST"]) def ocr(): if request.method == "POST": if 'image' not in request.files: print('hello') return Response("Image Not Attached!", status=400) img = request.files['image'] doc = DocumentFile.from_images(img.read()) result = model(doc) return result.render() if __name__ == "__main__": app.run(debug=True)