Basak Tamer commited on
Commit
991e952
·
verified ·
1 Parent(s): 2a8c8b2

Upload malariacnn_app.py

Browse files
Files changed (1) hide show
  1. src/malariacnn_app.py +33 -0
src/malariacnn_app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # --- Load Custom CNN ---
7
+ @st.cache_resource
8
+ def load_cnn():
9
+ return tf.keras.models.load_model('malaria_cnnmodel.keras')
10
+
11
+ model = load_cnn()
12
+
13
+ st.title("🔬 Malaria Detector: Custom CNN")
14
+ st.write("Validation Accuracy: **94.83%**")
15
+
16
+ file = st.file_uploader("Upload Cell Image", type=["jpg", "png"])
17
+
18
+ if file:
19
+ img = Image.open(file).convert('RGB')
20
+ st.image(img, width=300)
21
+
22
+ # Preprocessing
23
+ img_resized = img.resize((64, 64))
24
+ img_array = np.array(img_resized) / 255.0
25
+ img_array = np.expand_dims(img_array, axis=0)
26
+
27
+ if st.button("Predict with CNN"):
28
+ pred = model.predict(img_array)[0][0]
29
+ # Label logic: < 0.5 = Parasitized (0), > 0.5 = Uninfected (1)
30
+ if pred < 0.5:
31
+ st.error(f"PARASITIZED (Confidence: {(1-pred)*100:.2f}%)")
32
+ else:
33
+ st.success(f"UNINFECTED (Confidence: {pred*100:.2f}%)")