File size: 682 Bytes
d41eab8
 
 
 
23466eb
83b25da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image

# Load model
model = tf.keras.models.load_model("Mobilenet_model.h5")

# Define class labels
class_names = ["Organic", "Recyclable", "Hazardous"]

def classify_image(image):
    image = image.resize((128, 128))  # Resize to match input size
    img_array = np.array(image) / 255.0
    img_array = np.expand_dims(img_array, axis=0)
    predictions = model.predict(img_array)
    class_index = np.argmax(predictions[0])
    return class_names[class_index]

gr.Interface(
    fn=classify_image,
    inputs=gr.Image(type="pil"),
    outputs="text",
    title="Waste Classification Model",
).launch()