-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
36 lines (27 loc) · 1.16 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
import os
import cv2
from flask import Flask, flash, request, redirect, url_for, Response
from classifier.eval import evaluate
from werkzeug.utils import secure_filename
import numpy as np
import matplotlib.pyplot as plt
from classifier.model import TransferModel
skin_classifier = TransferModel(model_cls, len(test_dataset.classes))
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'}
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
if 'file' not in request.files:
return redirect(request.url)
file = request.files['file']
if True in [file.filename.endswith(extension) for extension in ALLOWED_EXTENSIONS]:
filestr = file.read()
data = np.frombuffer(filestr, np.uint8)
img = cv2.imdecode(data, cv2.IMREAD_COLOR)
reshaped_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
resp = evaluate(np.array(reshaped_img))
return Response({'type': resp}, status=200, mimetype="application/json")
return Response([], status=200, mimetype="application/json")
if (__name__ == '__main__'):
app.run('0.0.0.0', port=3000)