-
Notifications
You must be signed in to change notification settings - Fork 0
/
x-ray webapp.py
63 lines (44 loc) · 1.43 KB
/
x-ray webapp.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from flask import Flask, redirect, render_template, request,jsonify, url_for
from keras.models import load_model
import cv2
import numpy as np
import base64
from PIL import Image
import io
import re
img_size=100
app = Flask(__name__)
model=load_model('C:\\Users\\computer world\\Desktop\\link webapp to html\\model-015.model')
label_dict={0:'Covid19 Negative', 1:'Covid19 Positive'}
def preprocess(img):
img=np.array(img)
if(img.ndim==3):
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
else:
gray=img
gray=gray/255
resized=cv2.resize(gray,(img_size,img_size))
reshaped=resized.reshape(1,img_size,img_size)
return reshaped
@app.route("/")
def index():
return(render_template("xray index.html"))
@app.route("/predict", methods=["POST"])
def predict():
print('HERE')
message = request.get_json(force=True)
encoded = message['image']
decoded = base64.b64decode(encoded)
dataBytesIO=io.BytesIO(decoded)
dataBytesIO.seek(0)
image = Image.open(dataBytesIO)
test_image=preprocess(image)
prediction = model.predict(test_image)
result=np.argmax(prediction,axis=1)[0]
accuracy=float(np.max(prediction,axis=1)[0])
label=label_dict[result]
print(prediction,result,accuracy)
response = {'prediction': {'result': label,'accuracy': accuracy}}
return jsonify(response)
app.run(debug=False)
#<img src="" id="img" crossorigin="anonymous" width="400" alt="Image preview...">