Cara mengirim gambar yang dikirim dengan permintaan pos ke model untuk prediksi
@app.route('/', methods = ['POST'])
def predict():
if request.method == 'POST':
base64img = request.get_json()['img'].encode('utf-8')
img = base64.b64decode(base64img)
with open('imgtemp.png', 'wb') as f:
f.write(img)
img = cv2.imread('imgtemp.png', 1)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
payload = {
'instances': [{'input_image': img.tolist()}]
}
r = requests.post(url, json = payload)
pred = json.loads(r.content.decode('utf-8'))
return pred
SAMER SAEID