Spaces:
Runtime error
Runtime error
Update app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637import os# Force legacy Keras logicos.environ["TF_USE_LEGACY_KERAS"] = "1"import gradio as grimport numpy as npimport tensorflow as tfimport tf_keras # This is the dedicated legacy library# Load the model using the legacy-specific loadermodel = tf_keras.models.load_model("model.h5", compile=False)# Labels for your waste classificationlabels = ["Cardboard", "Glass", "Metal", "Paper", "Plastic", "Trash"]def classify_waste(image):# Preprocessing: Match the 224x224 input size from your error logimg = image.resize((224, 224))img_array = np.array(img) / 255.0img_array = np.expand_dims(img_array, axis=0)# Run predictionpredictions = model.predict(img_array)[0]# Return top results in Gradio formatreturn {labels[i]: float(predictions[i]) for i in range(len(labels))}# Setup the interfacedemo = gr.Interface(fn=classify_waste,inputs=gr.Image(type="pil"),outputs=gr.Label(num_top_classes=3),title="♻️ AI Waste Classifier",description="Upload an image of waste to see the classification.")demo.launch()12345678910111213141516171819202122232425262728293031import gradio as grimport numpy as npimport tensorflow as tffrom PIL import Image# Standard loading - TF 2.12 will handle your .h5 file correctlymodel = tf.keras.models.load_model("model.h5", compile=False)labels = ["Cardboard", "Glass", "Metal", "Paper", "Plastic", "Trash"]def classify_waste(image):# Resize and normalizeimg = image.resize((224, 224))img_array = np.array(img) / 255.0img_array = np.expand_dims(img_array, axis=0)# Predictpredictions = model.predict(img_array)[0]# Create dictionary for Gradioreturn {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="♻️ AI Waste Classifier",description="Upload an image to identify waste categories.")demo.launch()
app.py+7-13