Spaces:
Running
Running
| import gradio as gr | |
| from tensorflow.keras.models import load_model | |
| import numpy as np | |
| import os | |
| # Load the model (ensure it's in the same directory as app.py) | |
| model_path = os.path.join(os.path.dirname(__file__), 'waste_classifier_mobilenetv2.h5') | |
| model = load_model(model_path) | |
| # Prediction function | |
| def classify_image(image): | |
| if image is None: | |
| return "No image provided." | |
| image = np.array(image) | |
| if image.shape != (224, 224, 3): | |
| image = np.resize(image, (224, 224, 3)) | |
| image = image / 255.0 | |
| image = np.expand_dims(image, axis=0) | |
| prediction = model.predict(image) | |
| class_label = 'Reyclabble' if prediction[0][0] > 0.5 else 'Organic' | |
| return class_label | |
| # Create Gradio interface | |
| interface = gr.Interface(fn=classify_image, inputs=gr.Image(type="numpy"), outputs="text") | |
| interface.launch(share=True) | |