""" Malaria Detection - Streamlit App =================================== AI-powered blood smear analysis. Run with: streamlit run app.py """ import streamlit as st import tensorflow as tf import numpy as np from PIL import Image import time import datetime # ───────────────────────────────────────────── # PAGE CONFIG # ───────────────────────────────────────────── st.set_page_config( page_title="Malaria Detection System", page_icon="🦟", layout="centered" ) # ───────────────────────────────────────────── # CUSTOM CSS # ───────────────────────────────────────────── st.markdown(""" """, unsafe_allow_html=True) # ───────────────────────────────────────────── # SESSION STATE # ───────────────────────────────────────────── if "history" not in st.session_state: st.session_state.history = [] if "total_latency" not in st.session_state: st.session_state.total_latency = 0 # ───────────────────────────────────────────── # LOAD MODEL (cached so it only loads once) # ───────────────────────────────────────────── @st.cache_resource def load_model(): from keras.layers import Dense class PatchedDense(Dense): def __init__(self, *args, **kwargs): kwargs.pop('quantization_config', None) super().__init__(*args, **kwargs) model = tf.keras.models.load_model( 'malaria_model_final.h5', custom_objects={'Dense': PatchedDense}, compile=False ) return model IMG_SIZE = (128, 128) # ───────────────────────────────────────────── # HEADER # ───────────────────────────────────────────── st.markdown("""
No predictions yet. Upload an image to begin.
', unsafe_allow_html=True) else: for entry in st.session_state.history: is_infected = entry["prediction"] == "Parasitized" dot_color = "#f85149" if is_infected else "#2ea043" label = "🦟 Parasitized" if is_infected else "✅ Uninfected" st.markdown(f"""