File size: 1,037 Bytes
ad0bce8
fbfac5c
ad0bce8
 
 
966ff33
299d524
 
ad0bce8
 
 
 
 
 
 
 
966ff33
ad0bce8
 
 
 
 
 
 
 
 
 
 
 
 
 
966ff33
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
import gradio as gr
import tensorflow as tf
from tensorflow.keras.preprocessing import image
import numpy as np

# Use TFSMLayer to load the SavedModel
model = tf.keras.models.load_model("waste_sort_model.keras")

class_names = ["Non-Recyclable", "Recyclable"]

def classify_image(img):
    """Classify uploaded image as recyclable or non-recyclable."""
    img = img.resize((150, 150))  # Resize to match model input size
    img_array = np.array(img) / 255.0  # Normalize pixel values
    img_array = np.expand_dims(img_array, axis=0)  # Add batch dimension

    predictions = model(img_array)
    predicted_class = class_names[np.argmax(predictions)]
    return f"Prediction: {predicted_class}"

# Define Gradio Interface
interface = gr.Interface(
    fn=classify_image,
    inputs=gr.Image(type="pil"),
    outputs="text",
    title="Waste Classification",
    description="Upload an image of waste to classify as Recyclable or Non-Recyclable.",
)

# Launch the Gradio app
if __name__ == "__main__":
    interface.launch(share=True)