Skip to content

Commit

Permalink
Merge pull request #7 from Kalkuli/101_unir_back_e_front
Browse files Browse the repository at this point in the history
Make return json compatible with interpret service.
  • Loading branch information
MarianaPicolo authored Sep 30, 2018
2 parents 7a1be50 + ad158f4 commit 32a4835
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions project/api/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER


def view(error):
if error == -1:
raise NotFound()
Expand All @@ -21,20 +22,24 @@ def view(error):
elif error == -3:
raise NotAcceptable()


def extract_pdf(convert):
text_obj = {}
text_obj['text'] = []
text_obj['raw_text'] = ""
for page in convert:
text_obj['text'].append(pytesseract.image_to_string(page, lang='por'))
text_obj['raw_text'] += pytesseract.image_to_string(page, lang='por')
return text_obj


def convert_pdf(file):
return convert_from_bytes(file.read())


def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS


@app.route('/extract', methods=['POST'])
def central():
if request.method == 'POST':
Expand All @@ -61,6 +66,4 @@ def central():
filename = secure_filename(file.filename)
convert = convert_pdf(file)
json_text = extract_pdf(convert)
return jsonify({
'raw_text': json_text
})
return jsonify(json_text)

0 comments on commit 32a4835

Please sign in to comment.