-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.py
63 lines (44 loc) · 1.57 KB
/
web.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
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 = "./model/model.h5"
model_loader = load_model(fp)
return model_loader
cnn = loading_model()
st.write("""
# Cloud Based Web Application Tuberculosis Detection Using CNN App
""")
temp = st.file_uploader("Please Provide the Snap Shot of your 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.write("This model is built for public use ")
else:
img = image.load_img(temp_file.name, target_size=(
500, 500), color_mode='grayscale')
# Preprocessing the image
pp_img = image.img_to_array(img)
pp_img = pp_img/255
pp_img = np.expand_dims(pp_img, axis=0)
# predict
preds = cnn.predict(pp_img)
if preds >= 0.5:
out = ('I am {:.2%} percent confirmed that this is a Tuberculosis case You may Need to consult a Doctor'.format(
preds[0][0]))
else:
out = ('I am {:.2%} percent confirmed that this is a Normal case'.format(
1-preds[0][0]))
st.success(out)
image = Image.open(temp)
st.image(image, use_column_width=True)