mgonnzz commited on
Commit
1deb702
·
1 Parent(s): b5e5922

Add application file

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ import streamlit as st
4
+ import cv2
5
+ from PIL import Image, ImageOps
6
+ import numpy as np
7
+
8
+
9
+ @st.cache(allow_output_mutation=True)
10
+
11
+ def load_model():
12
+ model=tf.keras.models.load_model('/Users/muhammadhugo/Documents/Skripsi/Project-porto/MachineLearning-ClearVis-main-2/Saved_model/cnnsvm_retinoblastoma_model.h5')
13
+ return model
14
+
15
+ def predict(image_data, model):
16
+
17
+ size = (224,224)
18
+ image = ImageOps.fit(image_data, size, Image.ANTIALIAS)
19
+ image = np.asarray(image)
20
+ img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
21
+ #img_resize = (cv2.resize(img, dsize=(75, 75), interpolation=cv2.INTER_CUBIC))/255.
22
+
23
+ img_reshape = img[np.newaxis,...]
24
+
25
+ prediction = model.predict(img_reshape)
26
+
27
+ return prediction
28
+
29
+
30
+ with st.spinner('Model is being loaded..'):
31
+ model=load_model()
32
+
33
+ st.write("""
34
+ # Retinoblastoma Classification App
35
+ """
36
+ )
37
+
38
+ file = st.file_uploader("Please upload a cropped eye image file", type=["jpg", "png", "jpeg"])
39
+
40
+ st.set_option('deprecation.showfileUploaderEncoding', False)
41
+
42
+ if file is None:
43
+ st.text("Please upload an image file")
44
+
45
+ else:
46
+ image = Image.open(file)
47
+ st.image(image, use_column_width=True)
48
+ predictions = predict(image, model)
49
+
50
+ if round(float(predictions[0][0])) == 1:
51
+ results = 'normal'
52
+ print("user's eyes is normal")
53
+ print(predictions)
54
+ st.write("user's eyes is normal")
55
+ elif round(float(predictions[0][1])) == 1:
56
+ results = 'retinoblastoma'
57
+ print("user's eyes is retinoblastoma")
58
+ print(predictions)
59
+ st.write("user's eyes is suspected with retinoblastoma")