-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
59 lines (46 loc) · 1.59 KB
/
server.py
File metadata and controls
59 lines (46 loc) · 1.59 KB
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
from flask import Flask, request, redirect, render_template
import tensorflow
from tensorflow.keras.models import load_model
import numpy as np
from PIL import Image
import base64
from io import BytesIO
#
#
app = Flask(__name__)
app.secret_key = "counter=0"
# a route where we will display a welcome message via an HTML template
message = "Home"
@app.route("/")
def index():
return render_template('index.html', message="Home")
app.config["TEMPLATES_AUTO_RELOAD"] = True
ALLOWED_EXTENSIONS = (".jpg", ".jpeg", ".png")
#model = load_model("static/model.hdf5")
@app.route('/predict', methods=['GET', 'POST'])
def predict():
files = request.files.getlist('uploadFile')
labels = {0: 'desert', 1: 'plant', 2: 'water'}
pred = {}
# if there is more than 10 uploaded images don't continue and return with this message ,.... مش وكالة من غير بواب هي
if len(files) > 10:
return redirect('/')
for file in files:
if not file.filename.endswith(ALLOWED_EXTENSIONS):
continue
img = Image.open(file)
img = img.resize((256, 256))
buffered = BytesIO()
img.save(buffered, format="PNG")
pim = base64.b64encode(buffered.getvalue())
img = np.asarray(img, dtype=np.float32)
img = img / 255
img = img[..., :3]
img = img.reshape(-1, 256, 256, 3)
predict = 'desert'
# predict = model.predict(img)
# predict = labels[np.argmax(predict)]
pred[pim] = predict
return render_template('index.html', message=pred)
if __name__ == '__main__':
app.run(debug=True)