-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
63 lines (48 loc) · 1.85 KB
/
server.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
#!/usr/bin/env python
# -*- coding: UTF-8 -*- #
import os , datetime , logging
from flask import Flask, render_template, request, redirect, url_for, send_from_directory
from werkzeug import secure_filename
from libs.same_link import ocr_default
# Initialize the Flask application
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'storage/files/'
app.config['ALLOWED_EXTENSIONS'] = set([ 'png', 'jpg', 'jpeg','PNG','JPG','JPEG' ])
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS']
#]]
@app.route('/')
def index():
return render_template('index.html')
@app.route('/images', methods=['POST'])
def upload():
file = request.files['file']
if file and allowed_file(file.filename):
timez = datetime.datetime.now()
itsnow = timez.strftime('%I.%M.%S.%p_%d.%b.%Y')
filename = itsnow+'_'+file.filename # remove unsupported chars
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
files = app.config['UPLOAD_FOLDER']+'/'+filename
#text = ocr_default(files,"thresh").encode('utf-8')
text = ocr_default(files,"thresh")
imgo = {
'src': 'images/'+filename,
'text': text,
'type': 'Image'
}
return render_template('index.html',img=imgo)
@app.route('/images/<filename>')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'],
filename)
timez = datetime.datetime.now()
logfile = timez.strftime('%d.%b.%Y')
logging.basicConfig(filename='logs/'+logfile+'.log', filemode='w', level=logging.DEBUG)
if __name__ == '__main__':
app.run(
host="0.0.0.0",
port=int("50001"),
debug=True,
threaded=True
)