-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
44 lines (31 loc) · 1.15 KB
/
run.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
'''
sudo apt install gunicorn3
sudo apt install nginx
'''
import os
from flask import Flask, render_template, request, jsonify
from werkzeug.utils import secure_filename
from src import OCRConversion
app = Flask(__name__)
app.config["UPLOAD_FOLDER"] = "pics/"
@app.route('/')
def upload_file():
return render_template('index.html')
@app.route('/display', methods = ['GET', 'POST'])
def display_file():
if request.method == 'POST':
f = request.files['file']
filename = secure_filename(f.filename)
f.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
content = OCRConversion.actualConversion(app.config['UPLOAD_FOLDER'] + filename)
if(len(content) == 0):
content = "<Response 440 bytes [200 OK]>"
content = content.replace("\n", "<br>")
os.remove(app.config['UPLOAD_FOLDER'] + filename)
return jsonify({"result": content})
return render_template('content.html', content=content)
@app.route('/noLines', methods = ['GET', 'POST'])
def noLines():
return render_template("index.html")
if __name__ == '__main__':
app.run(host="0.0.0.0", port=8080)