Spaces:
Runtime error
Runtime error
File size: 1,026 Bytes
87bded8 648b532 847ea72 87bded8 27e2280 87bded8 847ea72 ffd769a d863d21 27e2280 d863d21 847ea72 b553823 d863d21 847ea72 b553823 847ea72 0901d5c 9a92a89 b553823 9a92a89 b553823 847ea72 0901d5c 9a92a89 | 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 | import os
os.environ["TF_USE_LEGACY_KERAS"] = "1"
os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0"
import gradio as gr
import numpy as np
import tensorflow as tf
from PIL import Image
from huggingface_hub import hf_hub_download
# Download model from your model repo
model_path = hf_hub_download(
repo_id="dk00069/WasteClassifier01",
filename="waste_classifier_final.h5"
)
model = tf.keras.models.load_model(model_path, compile=False)
labels = [
"Cardboard",
"Glass",
"Metal",
"Paper",
"Plastic",
"Trash"
]
def classify_waste(image):
img = image.resize((224, 224))
img_array = np.array(img) / 255.0
img_array = np.expand_dims(img_array, axis=0)
predictions = model.predict(img_array)[0]
return {labels[i]: float(predictions[i]) for i in range(len(labels))}
demo = gr.Interface(
fn=classify_waste,
inputs=gr.Image(type="pil"),
outputs=gr.Label(num_top_classes=3),
title="Waste Classifier",
description="Upload a waste image to classify it."
)
demo.launch() |