Spaces:
Runtime error
Runtime error
Tan Le
commited on
Commit
•
dc06e63
1
Parent(s):
90a03c4
Add initial application with sample images
Browse files- app.py +49 -0
- images/beverage_cans 17.jpeg +0 -0
- images/construction_scrap_69.jpeg +0 -0
- images/metal_containers_19.jpeg +0 -0
- images/metal_objects_12.jpeg +0 -0
- images/spray_cans_47.jpeg +0 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import tensorflow as tf
|
3 |
+
import gradio as gr
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
model_path = hf_hub_download(
|
8 |
+
repo_id="tancnle/smart-recycling",
|
9 |
+
filename="model_baseline.h5",
|
10 |
+
use_auth_token="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",
|
11 |
+
)
|
12 |
+
|
13 |
+
dim = (299, 299)
|
14 |
+
|
15 |
+
|
16 |
+
def read_image(image):
|
17 |
+
image = Image.open(image)
|
18 |
+
image_np = np.array(image)
|
19 |
+
image_np = tf.expand_dims(tf.cast(np.resize(image, dim), tf.float32) / 255.0, -1)
|
20 |
+
image_np = tf.image.grayscale_to_rgb(image_np)
|
21 |
+
return image
|
22 |
+
|
23 |
+
|
24 |
+
def infer(model, image_tensor):
|
25 |
+
predictions = model.predict(tf.expand_dims(image_tensor, axis=0))
|
26 |
+
return predictions
|
27 |
+
|
28 |
+
|
29 |
+
def classify(input_image):
|
30 |
+
image_tensor = read_image(input_image)
|
31 |
+
predictions = infer(image_tensor)
|
32 |
+
return predictions
|
33 |
+
|
34 |
+
|
35 |
+
examples = [["cardboard116.jpg"]]
|
36 |
+
title = "Classify Trash"
|
37 |
+
description = "Upload an image or select from examples to classify trash."
|
38 |
+
article = "<div style='text-align: center;'>Space by Tan Le</div>"
|
39 |
+
|
40 |
+
demo = gr.Interface(
|
41 |
+
classify,
|
42 |
+
inputs="image",
|
43 |
+
outputs="label",
|
44 |
+
examples=examples,
|
45 |
+
title=title,
|
46 |
+
description=description,
|
47 |
+
article=article,
|
48 |
+
)
|
49 |
+
demo.launch()
|
images/beverage_cans 17.jpeg
ADDED
images/construction_scrap_69.jpeg
ADDED
images/metal_containers_19.jpeg
ADDED
images/metal_objects_12.jpeg
ADDED
images/spray_cans_47.jpeg
ADDED
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
numpy
|
2 |
+
pillow
|
3 |
+
tensorflow
|