-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweb.py
36 lines (31 loc) · 917 Bytes
/
web.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
import os
import time
from flask import Flask, request, redirect, url_for
from classifier import Classifier
UPLOAD_FOLDER = 'uploads/'
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
cf = Classifier()
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
file = request.files['file']
filepath = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
file.save(filepath)
print(filepath)
res = cf.classify(filepath)
print(res)
if res is not None:
return res
else:
return 'nope'
return '''
<!doctype html>
<title>Upload</title>
<h1>Upload image</h1>
<form method=post enctype=multipart/form-data>
<p><input type=file name=file>
<input type=submit value=Upload>
</form>
'''
app.run(host= '0.0.0.0', port=5353, threaded=False)