-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbackend.py
69 lines (52 loc) · 1.95 KB
/
backend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from flask import Flask, app, render_template, request, flash ,session,send_file
import csv
import os
import pytesseract
import cv2
import numpy as np
import base64
from main import OCR
#import urllib.urlopen
from urllib.request import urlopen
from json import load
import json
import requests
from pprint import pprint
from flask import Flask, flash, request, redirect, url_for
from werkzeug.utils import secure_filename
UPLOAD_FOLDER = './uploads'
app = Flask(__name__)
app.config['SECRET_KEY'] = 'gyuerho834dtrui3yr8ury39ry3yr9p834m'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/')
def index():
return render_template('index.html')
@app.route('/second.html' ,methods=['GET','POST'])
def second():
if request.method == 'POST':
# check if the post request has the file part
pprint(request.files)
# pprint(request.post)
if 'files[]' not in request.files:
flash('No file part')
return redirect(request.url)
files = request.files.getlist("files[]")
img = base64.b64encode(open('output/1.jpg', 'rb').read()).decode()
# img = base64.b64encode(files[0].read()).decode()
img_dict = {}
for i in range(len(files)):
file = files[i]
# If the user does not select a file, the browser submits an
# empty file without a filename.
if file.filename == '':
flash('No selected file')
return redirect(request.url)
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
# open(filename, 'wb+').write( file.read() )
# OCR()
return render_template('second.html', show=img, ext='jpg')
else:
return render_template('second.html')
if __name__=="__main__":
app.run(debug=True)