Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Class labels (same order as training)
|
| 7 |
+
class_names = ['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash']
|
| 8 |
+
|
| 9 |
+
# Load your trained model
|
| 10 |
+
model = tf.keras.models.load_model("garbage_model.h5")
|
| 11 |
+
|
| 12 |
+
# Prediction function
|
| 13 |
+
def predict_image(img):
|
| 14 |
+
img = img.resize((124, 124))
|
| 15 |
+
img_array = tf.keras.preprocessing.image.img_to_array(img)
|
| 16 |
+
img_array = tf.expand_dims(img_array, axis=0)
|
| 17 |
+
|
| 18 |
+
predictions = model.predict(img_array)[0]
|
| 19 |
+
return {class_names[i]: float(predictions[i]) for i in range(len(class_names))}
|
| 20 |
+
|
| 21 |
+
# Gradio interface
|
| 22 |
+
interface = gr.Interface(
|
| 23 |
+
fn=predict_image,
|
| 24 |
+
inputs=gr.Image(type="pil"),
|
| 25 |
+
outputs=gr.Label(num_top_classes=3),
|
| 26 |
+
title="🗑️ Garbage Classifier with EfficientNet",
|
| 27 |
+
description="Upload a garbage image to predict its type: plastic, paper, metal, etc."
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
interface.launch()
|
| 31 |
+
|