-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
71 lines (58 loc) · 2.02 KB
/
app.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
from flask import Flask, render_template, request,jsonify
from werkzeug import secure_filename
import datetime
import nltk
import cv2
import numpy as np
# nltk.download('punkt')
from nltk.tokenize import sent_tokenize
from nltk.tokenize import WordPunctTokenizer
app = Flask(__name__)
def bgr_img(filename_type,filename,typo):
image = cv2.imread(filename_type)
r=image.shape[0]
c=image.shape[1]
B=np.zeros((r,c,3),dtype=int)
G=np.zeros((r,c,3),dtype=int)
R=np.zeros((r,c,3),dtype=int)
B[:,:,0]=image[:,:,0]
G[:,:,1]=image[:,:,1]
R[:,:,2]=image[:,:,2]
# cv2_imshow(B)
# cv2.waitKey(0)
# cv2_imshow(G)
# cv2.waitKey(0)
# cv2_imshow(R)
# cv2.waitKey(0)
cv2.imwrite('./templates/'+filename+'_b.'+typo,B)
cv2.imwrite('./templates/'+filename+'_g.'+typo,G)
cv2.imwrite('./templates/'+filename+'_r.'+typo,R)
cv2.destroyAllWindows()
def textfunc():
pass
@app.route('/result',methods=['POST','GET'])
def display():
fl=request.files['file_type']
filetype=fl.filename.split('.')[-1]
filtypes=['txt','csv','xlsv','gif','png','jpg','mp4']
if filetype in filtypes:
fl.save(fl.filename)
if filetype=='txt':
with open(fl.filename, 'r') as content_file:
content = content_file.read()
tokenizer=WordPunctTokenizer()
return str(tokenizer.tokenize(content))
elif filetype=='png':
onlyfn=str(fl.filename[0:len(fl.filename)-4])
bgr_img(fl.filename,onlyfn,'png')
return render_template('image.html',filename_b=onlyfn +'_b.png',filename_g=onlyfn+'_g.png',filename_r=onlyfn+'_r.png')
elif filetype=='jpg':
onlyfn=fl.filename[0:len(fl.filename)-4]
bgr_img(fl.filename,onlyfn,'jpg')
return render_template('image.html',filename_b=onlyfn+'_b.jpg',filename_g=onlyfn+'_g.jpg',filename_r=onlyfn+'_r.jpg')
return filetype
@app.route('/', methods=['POST','GET'])
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)