Rishav-ctrl's picture
Update app.py
fbfac5c verified
raw
history blame
1.07 kB
import gradio as gr
import tensorflow as tf
from tensorflow.keras.preprocessing import image
import numpy as np
# Load your trained model (SavedModel format)
model = tf.keras.models.load_model("waste_sort_model") # Loading from SavedModel directory
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.predict(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()