Created
June 8, 2022 12:16
-
-
Save f9n/c170e8ecac6556ccebaf694262ceb66b to your computer and use it in GitHub Desktop.
Pytesseract Rest Api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from flask import Flask, request | |
from werkzeug.utils import secure_filename | |
import pytesseract | |
app = Flask(__name__) | |
@app.route('/ocr', methods=['POST']) | |
def run_ocr(): | |
f = request.files['file'] | |
file_name = 'tmp/' + secure_filename(f.filename) | |
f.save(file_name) | |
content = pytesseract.image_to_string(file_name, timeout=10) | |
return json.dumps({"content": content}) | |
def handler(event, context): | |
print(event) | |
return { | |
"statusCode": 200, | |
"body": json.dumps(event), | |
} | |
if __name__ == '__main__': | |
app.run(host="0.0.0.0", port=5005, debug=True) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment