Spaces:
Sleeping
Sleeping
Commit ·
da01960
1
Parent(s): 89ea46f
app change
Browse files
app.py
CHANGED
|
@@ -1,49 +1,53 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
|
|
|
|
|
|
| 4 |
|
| 5 |
from datasets import load_dataset
|
| 6 |
from huggingface_hub import hf_hub_download
|
| 7 |
import tensorflow as tf
|
| 8 |
from tensorflow.keras.applications.resnet50 import preprocess_input
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
ds = load_dataset("dvk65/TrashTypes")
|
| 13 |
-
class_names = ds["train"].features["label"].names
|
| 14 |
|
| 15 |
|
| 16 |
-
# --- LOAD MODEL ---
|
| 17 |
-
REPO_ID = "dvk65/trash-classifier-resnet50"
|
| 18 |
-
FILENAME = "trashclassify_13.keras"
|
| 19 |
|
| 20 |
-
model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
|
| 21 |
|
| 22 |
-
model = tf.keras.models.load_model(
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
)
|
| 26 |
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
return image
|
| 35 |
|
| 36 |
def predict(img):
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
| 40 |
|
| 41 |
|
| 42 |
demo = gr.Interface(
|
| 43 |
fn=predict,
|
| 44 |
inputs=gr.Image(type="pil"),
|
| 45 |
outputs=gr.Label(num_top_classes=3),
|
| 46 |
-
title="
|
| 47 |
)
|
| 48 |
-
|
| 49 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
|
| 7 |
from datasets import load_dataset
|
| 8 |
from huggingface_hub import hf_hub_download
|
| 9 |
import tensorflow as tf
|
| 10 |
from tensorflow.keras.applications.resnet50 import preprocess_input
|
| 11 |
|
| 12 |
+
# # --- LOAD CLASS LABELS FROM DATASET ---
|
| 13 |
+
# ds = load_dataset("dvk65/TrashTypes")
|
| 14 |
+
# class_names = ds["train"].features["label"].names
|
| 15 |
|
| 16 |
+
classifier = pipeline("image-classification", model="yangy50/garbage-classification")
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
+
# # --- LOAD MODEL ---
|
| 20 |
+
# REPO_ID = "dvk65/trash-classifier-resnet50"
|
| 21 |
+
# FILENAME = "trashclassify_13.keras"
|
| 22 |
|
| 23 |
+
# model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
|
| 24 |
|
| 25 |
+
# model = tf.keras.models.load_model(
|
| 26 |
+
# model_path,
|
| 27 |
+
# custom_objects={"preprocess_input": preprocess_input}
|
| 28 |
+
# )
|
| 29 |
|
| 30 |
|
| 31 |
+
# def preprocess(image):
|
| 32 |
+
# image = image.resize((224, 224))
|
| 33 |
+
# image = np.array(image)
|
| 34 |
+
# image = preprocess_input(image)
|
| 35 |
+
# image = np.expand_dims(image, axis=0)
|
| 36 |
+
# return image
|
|
|
|
| 37 |
|
| 38 |
def predict(img):
|
| 39 |
+
predictions = classifier(image)
|
| 40 |
+
return {p["label"]: p["score"] for p in predictions}
|
| 41 |
+
# img = preprocess(img)
|
| 42 |
+
# preds = model.predict(img)[0]
|
| 43 |
+
# return {class_names[i]: float(preds[i]) for i in range(len(preds))}
|
| 44 |
|
| 45 |
|
| 46 |
demo = gr.Interface(
|
| 47 |
fn=predict,
|
| 48 |
inputs=gr.Image(type="pil"),
|
| 49 |
outputs=gr.Label(num_top_classes=3),
|
| 50 |
+
title="AI Waste Classifier",
|
| 51 |
)
|
| 52 |
+
|
| 53 |
demo.launch()
|