-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
67 lines (48 loc) · 1.77 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# from win32com.client import Dispatch
from keras.models import load_model
import cv2
import os
from PIL import Image, ImageEnhance
import numpy as np
import streamlit as st
import warnings
warnings.filterwarnings('ignore')
import tensorflow
model = tensorflow.keras.models.load_model("malaria_prediction.h5")
def preprocessing(img):
try:
img = img.astype('uint8')
img = img/255
return img
except Exception as e:
img = img.astype('uint8')
# img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
# img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# img = cv2.equalizeHist(img)
img = img/255
return img
def main():
st.title("malaria Prediction using CNN")
st.set_option('deprecation.showfileUploaderEncoding', False)
nav = st.sidebar.radio("Navigation", ["Home"])
if nav == "Home":
st.subheader("Kindly upload file below")
img_file = st.file_uploader("Upload File", type=['png', 'jpg', 'jpeg'])
if img_file is not None:
up_img = Image.open(img_file)
st.image(up_img)
if st.button("Predict Now"):
try:
img = np.asarray(up_img)
img = cv2.resize(img, (130,130))
img = preprocessing(img)
img = img.reshape(1, 130, 130, 3)
prediction = model.predict(img)
if prediction > 0.5:
st.write("The cell is not infected!")
else:
st.write("The cell has been parasitized!")
except Exception as e:
st.error("Connection Error")
if __name__ == '__main__':
main()