-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
49 lines (38 loc) · 1.22 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
37
38
39
40
41
42
43
44
45
46
47
48
49
from flask import Flask, render_template,request, jsonify, send_file
import numpy as np
import cv2
import base64
import joblib
mlp = joblib.load('mlp_model.pkl')
app = Flask(__name__)
@app.route('/')
def Stone_model():
return render_template('index.html')
@app.route('/upload', methods=['POST'])
def upload():
data_url1 = request.json['image_data']
global img
pic = []
img = cv2.imdecode(decodefromjs(data_url1), cv2.IMREAD_GRAYSCALE)
img = cv2.resize(img, (128,128))
# if img.shape[2] ==1:
# img = np.dstack([img, img, img])
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img=np.array(img)
img = img/255
pic.append(img)
pic_np = np.array(pic) # Convert the list pic to a NumPy array
pic1_2d = pic_np.reshape(pic_np.shape[0], -1)
global a
a=mlp.predict(pic1_2d)
print(a)
return jsonify({'prediction': a.tolist()})
def decodefromjs(data_url):
image_data = data_url.split(',')[1]
# Decode the image data from base64
decoded_data = base64.b64decode(image_data)
# Convert the decoded data to a NumPy array
np_data = np.frombuffer(decoded_data, np.uint8)
return np_data
if __name__ == '__main__':
app.run(debug=True)