import streamlit as st import tensorflow as tf from tensorflow.keras.models import load_model from PIL import Image, ImageOps import numpy as np # Set the page title and layout st.set_page_config( page_title="Microorganism Classification 🦠", layout="wide", initial_sidebar_state="expanded" ) # Add custom blue-themed CSS st.markdown( """ """, unsafe_allow_html=True, ) # Load the pre-trained model @st.cache_resource def load_trained_model(): return load_model(r"Micro_organisme_3_model.h5", compile=False) model = load_trained_model() # Define class labels class_labels = [ "Bacteria", "Lactobacillus", "Micrococcus", "Virus" ] # Home page content def home(): st.title("Welcome to the Microorganism Classification App 🦠🔬") st.markdown("This application helps classify microorganism images into four distinct categories using AI. 🦠🤖") # Section: About Microorganisms st.subheader("What are Microorganisms? 🤔") st.markdown(""" Microorganisms are microscopic organisms, such as bacteria, viruses, and fungi, that are invisible to the naked eye. They play significant roles in ecosystems, health, and industries. This app assists researchers and professionals by automating the classification of microorganism images into four categories: Bacteria, Lactobacillus, Micrococcus, and Virus. 🤖⚙️ """) # Video st.subheader("Learn More About Microorganisms 📘💡") st.video("https://www.youtube.com/watch?v=6OQVP8jacek") # Additional description st.markdown(""" ### Features of this App ✨🔍: - Upload your microorganism images. - View AI predictions for 4 different categories: 1. **Bacteria**: A diverse group of prokaryotic microorganisms. 2. **Lactobacillus**: A genus of bacteria known for its role in fermentation. 3. **Micrococcus**: A genus of spherical, Gram-positive bacteria. 4. **Virus**: Submicroscopic infectious agents that replicate only inside living cells. """) # Prediction page content def upload_and_predict(): st.title("Upload and Predict 📤") # File uploader for image upload uploaded_file = st.file_uploader("Choose an image of a microorganism... 🖼️", type=["jpg", "jpeg", "png"]) if uploaded_file is not None: # Display the uploaded image st.image(uploaded_file, caption="Uploaded Image") # Load the image for prediction image = Image.open(uploaded_file) image = ImageOps.fit(image, (224, 224), Image.Resampling.LANCZOS) image_array = np.asarray(image) / 255.0 # Normalize the image image_array = np.expand_dims(image_array, axis=0) # Add batch dimension # Make prediction predictions = model.predict(image_array) predicted_class = class_labels[np.argmax(predictions)] confidence = np.max(predictions) * 100 # Display the prediction st.subheader("Prediction Result 📊:") st.markdown(f"**Predicted Class:** {predicted_class}") st.markdown(f"**Confidence:** {confidence:.2f}%") # Main function to control navigation if __name__ == "__main__": st.sidebar.title("Navigation") page = st.sidebar.radio("Go to", ["Home", "Upload and Predict"]) if page == "Home": home() elif page == "Upload and Predict": upload_and_predict()