Spaces:
Sleeping
Sleeping
Download app.py from Taidat/Image_Classification: direct link, hf CLI and curl.
- Browser
- Download file 788 Bytes
-
https://huggingface.co/spaces/Taidat/Image_Classification/resolve/ef96aab6cd081ecac7d3f7bf5c6b4f46bb53a93d/app.py
- Command line
-
hf download hf://spaces/Taidat/Image_Classification@ef96aab6cd081ecac7d3f7bf5c6b4f46bb53a93d/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Taidat/Image_Classification/resolve/ef96aab6cd081ecac7d3f7bf5c6b4f46bb53a93d/app.py
788 Bytes
| import gradio as gr | |
| import tensorflow as tf | |
| import numpy as np | |
| # Load model with correct name | |
| model = tf.keras.models.load_model("model.h5") | |
| IMG_SIZE = (224, 224) | |
| # Class labels | |
| index_to_label = { | |
| 0: "paper", 1: "e-waste", 2: "metal", 3: "light blubs", | |
| 4: "organic", 5: "plastic", 6: "clothes", 7: "glass", 8: "batteries" | |
| } | |
| def classify_image(img): | |
| img = tf.image.resize(img, IMG_SIZE) | |
| img = tf.expand_dims(img, axis=0) | |
| img = tf.cast(img, tf.float32) / 255.0 | |
| pred = model.predict(img)[0] | |
| return {index_to_label[i]: float(pred[i]) for i in range(len(pred))} | |
| demo = gr.Interface( | |
| fn=classify_image, | |
| inputs=gr.Image(type="numpy", label="Upload Waste Image"), | |
| outputs=gr.Label(num_top_classes=3), | |
| title="Smart Waste Classifier" | |
| ) | |
| demo.launch() |