I have a Python app with Tesseract OCR. I run on my pc. It's work!
However, I need deploy to Heroku. I was setting Aptfile, buildpack, TESSDATA_PREFIX already (ref: How to deploy pytesseract to Heroku). It's done.
Here is my console
Heroku https://image-text-try.herokuapp.com/
Github https://github.com/b-bella/image_text_try
It can run but error after submitting upload image.
Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
Could anyone see my coding on github & heroku and suggest how to fix about deploying to heroku?
from flask import Flask, request, redirect, url_for, render_template
from werkzeug.utils import secure_filename
import shutil
import os
import uuid
import pytesseract
pytesseract.pytesseract.tesseract_cmd = '/app/.apt/usr/bin/tesseract'
#pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
app = Flask(__name__)
app.config['ALLOWED_EXTENSIONS'] = set(['png', 'jpeg', 'jpg','gif'])
APP_ROOT = os.path.dirname(__file__)
UPLOAD_FOLDER = os.path.join(APP_ROOT, 'static').replace('\\','/')
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in app.config['ALLOWED_EXTENSIONS']
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'GET':
return render_template('index.html')
if request.method == 'POST':
if request.files:
file = request.files['file_image']
if allowed_file(file.filename):
filename = secure_filename(file.filename)
temp_file = os.path.join(app.config['UPLOAD_FOLDER'], filename).replace('\\', '/')
file.save(temp_file)
pre_result = pytesseract.image_to_string(temp_file, lang='eng')
return render_template('index.html', result=pre_result, filename=filename)
else:
return render_template('index.html', result='That file extension is not allowed', filename=file.filename)
if __name__ == '__main__':
app.run()