Skip to content

Commit

Permalink
eliminated intermediate disk usage
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhantkushwaha committed Aug 26, 2019
1 parent b0bf1b6 commit 4ff4b2d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
**.idea
**__pycache__
uploads
static
**__pycache__
20 changes: 11 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
from flask import Flask, request, redirect, render_template
from markupsafe import Markup
from werkzeug.utils import secure_filename

from main import run
import numpy as np
import cv2 as cv
from main import main

UPLOAD_FOLDER = 'uploads'
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'}
Expand All @@ -12,6 +12,12 @@
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER


def bytes_to_image(bytes):
np_arr = np.frombuffer(bytes, np.uint8)
arr = cv.imdecode(np_arr, cv.IMREAD_COLOR)
return arr


def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
Expand All @@ -28,15 +34,11 @@ def upload_file():
return redirect(request.url)

if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
path = os.path.join(app.config['UPLOAD_FOLDER'], filename)

file.save(path)
image = bytes_to_image(file.read())

tables = {}
for i, table in enumerate(run(path), 0):
for i, table in enumerate(main(image), 0):
tables[i] = Markup(table.to_html(index=False))
print(tables[i])

return render_template('main.html', tables=tables)

Expand Down
11 changes: 5 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ def main(image):
yield df


def run(path='data/example1.jpg'):
if __name__ == '__main__':
path = 'data/example1.jpg'
image = cv.imread(path)
yield from main(image)


if __name__ == '__main__':
for t in run():
print(t)
tables = extract(image)
for table in tables:
print(table)

0 comments on commit 4ff4b2d

Please sign in to comment.