-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfl.py
115 lines (94 loc) · 2.79 KB
/
fl.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#Imports
from flask import Flask, render_template, request, session, g, redirect
from ML.OCR import get_text
from ML.ptt import get_pdf
from models.savedtext import (
insert_text,
get_text,
text_tbl
)
from models.users import (
checkpassword,
make_user,
getemail,
getname,
insert,
)
from models.summ import (
getq, summary_tbl
)
app = Flask(__name__)
app.secret_key = 'somekey'
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
make_user()
text_tbl("app.db")
summary_tbl("app.db")
# transformer = wrapper.customwrapper()
@app.before_request
def security():
g.user = None
for i in session:
print(session[i])
if 'user_email' in session:
emails = getemail()
try:
useremail = [email for email in emails if email[0] == session['user_email']][0]
g.user = useremail
except Exception as e:
print("failed")
#LOGIN
@app.route("/", methods=["GET", 'POST'])
def login():
session.pop("user_email", None)
if request.method == "POST":
email = request.form["email"]
try:
name = request.form['name']
except Exception as e:
name = None
password = request.form['password']
if name != None:
insert("user", values=(email, name, password))
session['user_email'] = email
return redirect('upload')
if name == None:
if checkpassword(password, email):
session['user_email'] = email # session makes a cookie
return redirect('upload')
return redirect("/")
return render_template("login.html")
#Checks type of file and returns the extension type
def checkext(name):
ext = name.split('.')[1]
return ext
@app.route("/upload", methods = ["POST", "GET"])
def upload():
if g.user != None:
if request.method=="POST":
img = request.files["image"]
#If pdf then run pdf function
if checkext(img.filename) == 'pdf':
text = get_pdf(img.filename)
#For images
else:
text = get_text(img.filename)
text = ' '.join(text)
insert_text('Text', g.user[0], text, path='app.db')
return render_template("upload.html")
return redirect("/")
#DASHBOARD
@app.route('/dashboard', methods=['GET', 'POST'])
def dash():
if g.user != None:
name = getname(g.user)
return render_template("temp.html", name=name, email=g.user[0])
return redirect('/')
#DISPLAY
@app.route('/display', methods=['GET', 'POST'])
def disp():
if g.user != None:
summ = getq(g.user[0])[0]
return render_template("display.html", name=getname(g.user), text=summ)
return redirect('/')
if __name__ == "__main__":
app.run(debug=True, port=5000)