-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathapp.py
More file actions
58 lines (48 loc) · 1.42 KB
/
app.py
File metadata and controls
58 lines (48 loc) · 1.42 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
from flask import Flask, render_template, request, json, jsonify
import os
import json
import numpy as np
import io
from PIL import Image
app = Flask(__name__)
app.config.from_object(__name__)
port = int(os.getenv('PORT', 8080))
@app.route("/", methods=['GET'])
def hello():
error=None
return render_template('index.html', error=error)
@app.route("/iot", methods=['GET'])
def result():
print(request)
# Implemente sua lógica aqui e insira as respostas na variável 'resposta'
resposta = {
"iotData": "data",
"itu": "data",
"volumeAgua": "data",
"fahrenheit": "data"
}
response = app.response_class(
response=json.dumps(resposta),
status=200,
mimetype='application/json'
)
return response
def prepare_image(image):
image = image.resize(size=(96,96))
image = np.array(image, dtype="float") / 255.0
image = np.expand_dims(image,axis=0)
image = image.tolist()
return image
@app.route('/predict', methods=['POST'])
def predict():
print(request)
image = request.files["image"].read()
image = Image.open(io.BytesIO(image))
image = prepare_image(image)
# Faça uma requisição para o serviço Watson Machine Learning aqui e retorne a classe detectada na variável 'resposta'
resposta = {
"class": "data"
}
return resposta
if __name__ == '__main__':
app.run(host='0.0.0.0', port=port)