-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
58 lines (48 loc) · 1.57 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
from flask import Flask, render_template, flash, request, redirect, session
import os
from werkzeug.utils import secure_filename
import shutil
import bw2color
import numpy as np
import cv2 as cv
app = Flask(__name__)
shutil.rmtree('./static/images')
os.mkdir('./static/images')
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'csv'])
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/',methods=['GET', 'POST'])
def index():
if request.method == 'POST':
print("post success")
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit an empty part without filename
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
UPLOAD_FOLDER = './static/images/'
file.save(os.path.join(UPLOAD_FOLDER, filename))
print(filename)
global imagename
imagename = filename
# data = pd.read_csv("./static/"+str(filename))
return render_template('index.html')
@app.route('/showheader', methods=['GET', 'POST'])
def show_dataframe():
if request.method == 'POST':
showed = True
path = bw2color.colorify(imagename)
return render_template('home.html', path = path)
def delete_file():
shutil.rmtree('./static/images')
if __name__=='__main__':
app.secret_key = 'super secret key'
app.run(debug=True)