File size: 4,268 Bytes
ede737f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42c4ab2
ede737f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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(
    """
    <style>
        body {
            background-color:rgb(27, 54, 77);
        }
        .stApp {
            background: linear-gradient(to right,rgb(123, 166, 247),rgb(1, 103, 236));
        }
        .stTitle {
            color:rgb(169, 209, 240); 
        }
        .stHeader {
            color:rgb(155, 213, 247); 
        }
        .stMarkdown {
            color:rgb(170, 215, 240); 
        }
        .stSidebar {
            background-color:rgb(88, 143, 226);
        }
        .stButton > button {
            background-color: #0288d1;
            color: white;
            border: none;
            border-radius: 5px;
        }
        .stButton > button:hover {
            background-color: #01579b;
        }
    </style>
    <footer>
        &copy; 2024 By: Ikram Recioui. All Rights Reserved.
    </footer>
    """,
    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()