File size: 4,207 Bytes
58bd1b2
48cddcb
baf7aa0
28ea4d4
35e7ead
5867cce
cefb660
59da87a
4af4765
418cf06
bc530f2
 
 
846e726
bc530f2
 
6efd78a
 
bc530f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
846e726
bc530f2
 
 
 
 
 
 
7adff6d
 
 
bc530f2
 
 
3760c0b
6efd78a
58bd1b2
bc530f2
 
 
dfa03a1
f2681cd
 
23ecd0c
f2681cd
 
23ecd0c
90433fe
 
9bb3988
90433fe
 
23ecd0c
f2681cd
 
 
23ecd0c
2c1be08
 
 
f2681cd
 
 
 
 
 
bc530f2
f2681cd
 
 
 
90433fe
 
f2681cd
90433fe
1a2b0c1
610c7ce
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
133
134
135
import numpy as np
import streamlit as st
from PIL import Image
import tensorflow as tf
from utils import preprocess_image

# Initialize labels and model
labels = ['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash']
model = tf.keras.models.load_model('classify_model.h5')

# Customized Streamlit layout
st.set_page_config(
    page_title="EcoIdentify by EcoClim Solutions",
    page_icon="https://ecoclimsolutions.files.wordpress.com/2024/01/rmcai-removebg.png?resize=48%2C48",
    layout="wide",
    initial_sidebar_state="expanded",
)

# Customized Streamlit styles
st.markdown(
    """
    <style>
        body {
            color: #333333;
            background-color: #f9f9f9;
            font-family: 'Helvetica', sans-serif;
        }
        .st-bb {
            padding: 0rem;
        }
        .st-ec {
            color: #666666;
        }
        .st-ef {
            color: #666666;
        }
        .st-ei {
            color: #333333;
        }
        .st-dh {
            font-size: 36px;
            font-weight: bold;
            color: #4CAF50;
            text-align: center;
            margin-bottom: 20px;
        }
        .st-gf {
            background-color: #4CAF50;
            color: white;
            padding: 15px 30px;
            font-size: 18px;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .st-gf:hover {
            background-color: #45a049;
        }
        .st-gh {
            text-align: center;
            font-size: 24px;
            font-weight: bold;
            margin-bottom: 20px;
        }
        .st-logo {
            max-width: 100%;
            height: auto;
            margin: 20px auto;
            display: block;
        }
    </style>
    """,
    unsafe_allow_html=True,
)

# Logo
st.image("https://ecoclimsolutions.files.wordpress.com/2024/01/rmcai-removebg.png?resize=48%2C48")

# Page title
st.title("EcoIdentify by EcoClim Solutions")

# Subheader
st.header("Upload a waste image to find its category")

# Note
st.markdown("* Please note that our dataset is trained primarily with images that contain a white background.  Therefore, images with white background would produce maximum accuracy *")

# Image upload section
opt = st.selectbox("How do you want to upload the image for classification?", ("Please Select", "Upload image from device"))

image = None

if opt == 'Upload image from device':
    file = st.file_uploader('Select', type=['jpg', 'png', 'jpeg'])
    if file:
        image = preprocess_image(file)

# Sidebar section
st.sidebar.title("Options")

# Create a radio button widget for training mode
training_mode = st.sidebar.radio("Select training mode", ["None", "Dropout", "Batch Normalization"])

if training_mode == 'None':
    user_choice == 'Predict'
elif training_mode == "Dropout" or "Batch Normalization":
    user_choice == 'Train'


# Display the current training mode and user choice
st.write(f"Training mode: {training_mode}")
st.write(f"User choice: {user_choice}")

try:
    if image is not None:
        st.image(image, width=256, caption='Uploaded Image')
        
        # Execute different code blocks based on user choice
        if user_choice == "Predict":
            # Call the model with the training mode argument
            # Use a dictionary to map the training mode to the corresponding boolean value
            prediction = model.predict_on_batch(image[np.newaxis, ...], training={"None": False, "Dropout": True, "Batch Normalization": True}[training_mode])
            st.success(f'Prediction: {labels[np.argmax(prediction[0], axis=-1)]}')
        elif user_choice == "Train":
            # Generate some dummy target data for demonstration
            # You can replace this with your actual target data
            target = np.random.randint(0, 6, size=(1,))
            # Call the model without the training argument
            loss = model.train_on_batch(image[np.newaxis, ...], target)
            st.success(f'Loss: {loss}')

except Exception as e:
    st.error(f"An error occurred: {e}.  Please contact us EcoClim Solutions at EcoClimSolutions.wordpress.com.")