Taidat's picture
Update app.py
ef96aab verified
Raw History Blame
788 Bytes
import gradio as gr
import tensorflow as tf
import numpy as np
# Load model with correct name
model = tf.keras.models.load_model("model.h5")
IMG_SIZE = (224, 224)
# Class labels
index_to_label = {
0: "paper", 1: "e-waste", 2: "metal", 3: "light blubs",
4: "organic", 5: "plastic", 6: "clothes", 7: "glass", 8: "batteries"
}
def classify_image(img):
img = tf.image.resize(img, IMG_SIZE)
img = tf.expand_dims(img, axis=0)
img = tf.cast(img, tf.float32) / 255.0
pred = model.predict(img)[0]
return {index_to_label[i]: float(pred[i]) for i in range(len(pred))}
demo = gr.Interface(
fn=classify_image,
inputs=gr.Image(type="numpy", label="Upload Waste Image"),
outputs=gr.Label(num_top_classes=3),
title="Smart Waste Classifier"
)
demo.launch()