Skip to content

Instantly share code, notes, and snippets.

@f9n
Created June 8, 2022 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save f9n/c170e8ecac6556ccebaf694262ceb66b to your computer and use it in GitHub Desktop.
Save f9n/c170e8ecac6556ccebaf694262ceb66b to your computer and use it in GitHub Desktop.
Pytesseract Rest Api
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