-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_run.py
124 lines (106 loc) · 4.01 KB
/
service_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
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
116
117
118
119
120
121
122
123
124
import os
import sys
import datetime
from flask import Flask, render_template, url_for, request, redirect
#from flask_sqlalchemy import SQLAlchemy
from flask import jsonify
import json
from flask_cors import CORS
from werkzeug.utils import secure_filename
sys.path.append('lib/')
import import_excel
app = Flask(__name__)
# Flask-Cors
cors = CORS(app, resources={r"/*": {"origins": ["http://localhost*","http://thuyloibentre.com*"]}})
#######################################
#Function
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
###################################
UPLOAD_FOLDER = 'D:/sync/websvr/python/py_import_excel/upload/'
ALLOWED_EXTENSIONS = set(['xlsx', 'xls'])
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
#default
@app.route('/', methods = ['POST','GET'])
def blank():
return ('hahahaa')
@app.route('/import/cctl_giatri_mucnuoc', methods=['GET', 'POST'])
def upload_cctl_giatri_mucnuoc():
if request.method == 'POST':
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
nowdatetime = datetime.datetime.now()
filename='file'+nowdatetime.strftime("%d-%m-%Y_%Hh%Mm%S")+'-'+filename
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
full_dir=UPLOAD_FOLDER+filename
file_path='upload/'+filename
errs=import_excel.check_cctl_giatri_mucnuoc(file_path)
if(errs==[]):
errs.append({
'type':'success',
'info':'File hợp lệ.'
})
return json.dumps(errs)
return '''
<!doctype html>
<title>Test upload excel</title>
<h1>Test upload excel</h1>
<form method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>
'''
@app.route('/flower_detection', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
kq_temp=''
kq_temp+='<table width="600px">'
kq_temp+='<tr>'
kq_temp+='<td width="300px" style="padding:20px;">'
kq_temp+='<img src="{}" width="300px">'
kq_temp+='</td>'
kq_temp+='<td>'
kq_temp+='<h2>Thông tin nhận dạng</h2>'
kq_temp+='<p>{}</p>'
kq_temp+='<br>'
kq_temp+='<hr>'
kq_temp+='<br>'
kq_temp+='<a href="http://rose.dothanhlong.org:999/flower_detection">Nhận diện bông hoa (Deep learning testing)</a>'
kq_temp+='</td>'
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
#detect=detect_bonghoa("static/h1.jpg")
#return detect_bonghoa("upload/h1.jpg")
imgurl=url_for('static',filename=filename)
detect=detect_bonghoa("static/"+filename)
return kq_temp.format(imgurl,detect)
return '''
<!doctype html>
<title>Nhận diện bông - soiqualang chentreu</title>
<h1>Upload hình bông hoa</h1>
<form method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>
'''
if __name__ == "__main__":
app.run(debug=True)
# app.run(host='10.10.10.4', port=5000, debug=False)
##http://127.0.0.1:5000/select?kind=stations&ingestion=20160101
##