-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwebapp.py
71 lines (42 loc) · 1.57 KB
/
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
64
65
66
67
68
69
70
71
import streamlit as st
import numpy as np
from PIL import Image
from tensorflow.keras.models import load_model
import tensorflow as tf
from tempfile import NamedTemporaryFile
from tensorflow.keras.preprocessing import image
st.set_option('deprecation.showfileUploaderEncoding', False)
@st.cache(allow_output_mutation=True)
def loading_model():
fp = "cnn_pneu_vamp_model.h5"
model_loader = load_model(fp)
return model_loader
cnn = loading_model()
st.write("""
# X-Ray Classification [Pneumonia/Normal]
by Hardik :)
""")
temp = st.file_uploader("Upload X-Ray Image")
#temp = temp.decode()
buffer = temp
temp_file = NamedTemporaryFile(delete=False)
if buffer:
temp_file.write(buffer.getvalue())
st.write(image.load_img(temp_file.name))
if buffer is None:
st.text("Oops! that doesn't look like an image. Try again.")
else:
hardik_img = image.load_img(temp_file.name, target_size=(500, 500),color_mode='grayscale')
# Preprocessing the image
pp_hardik_img = image.img_to_array(hardik_img)
pp_hardik_img = pp_hardik_img/255
pp_hardik_img = np.expand_dims(pp_hardik_img, axis=0)
#predict
hardik_preds= cnn.predict(pp_hardik_img)
if hardik_preds>= 0.5:
out = ('I am {:.2%} percent confirmed that this is a Pneumonia case'.format(hardik_preds[0][0]))
else:
out = ('I am {:.2%} percent confirmed that this is a Normal case'.format(1-hardik_preds[0][0]))
st.success(out)
image = Image.open(temp)
st.image(image,use_column_width=True)