Upload 7 files
Browse files- .gitattributes +1 -0
- README.md +5 -5
- app.py +79 -0
- config.json +9 -0
- keras_model.h5 +3 -0
- model (1).keras +3 -0
- model_weights.h5 +3 -0
- requirements.txt +6 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
model[[:space:]](1).keras filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.49.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: NeuRecAI
|
| 3 |
+
emoji: 🚀
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.49.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
short_description: Image classification model
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import hf_hub_download
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image, ImageOps
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
# -----------------------
|
| 8 |
+
# CONFIG
|
| 9 |
+
# -----------------------
|
| 10 |
+
MODEL_REPO_ID = "BunkerMinecraft/neurecaiv2" # <-- change this
|
| 11 |
+
MODEL_FILENAME = "keras_model.h5"
|
| 12 |
+
LABELS_FILENAME = "labels.txt"
|
| 13 |
+
IMAGE_SIZE = (224, 224) # TM fixed size
|
| 14 |
+
|
| 15 |
+
# -----------------------
|
| 16 |
+
# DOWNLOAD MODEL + LABELS
|
| 17 |
+
# -----------------------
|
| 18 |
+
model_path = hf_hub_download(
|
| 19 |
+
repo_id=MODEL_REPO_ID,
|
| 20 |
+
filename=MODEL_FILENAME,
|
| 21 |
+
repo_type="model"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
labels_path = hf_hub_download(
|
| 25 |
+
repo_id=MODEL_REPO_ID,
|
| 26 |
+
filename=LABELS_FILENAME,
|
| 27 |
+
repo_type="model"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# Load the Teachable Machine Keras .h5 model
|
| 31 |
+
model = tf.keras.models.load_model(model_path, compile=False)
|
| 32 |
+
print(f"Loaded model: {model_path}")
|
| 33 |
+
|
| 34 |
+
# Load labels
|
| 35 |
+
with open(labels_path, "r") as f:
|
| 36 |
+
class_names = [line.strip() for line in f.readlines()]
|
| 37 |
+
print("Loaded labels:", class_names)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# -----------------------
|
| 41 |
+
# PREPROCESS FUNCTION (matches TM)
|
| 42 |
+
# -----------------------
|
| 43 |
+
def preprocess(img: Image.Image):
|
| 44 |
+
img = img.convert("RGB")
|
| 45 |
+
img = ImageOps.fit(img, IMAGE_SIZE, Image.Resampling.LANCZOS)
|
| 46 |
+
|
| 47 |
+
image_array = np.asarray(img).astype(np.float32)
|
| 48 |
+
# TM normalization:
|
| 49 |
+
normalized = (image_array / 127.5) - 1.0
|
| 50 |
+
|
| 51 |
+
return np.expand_dims(normalized, axis=0)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
# -----------------------
|
| 55 |
+
# PREDICT FUNCTION
|
| 56 |
+
# -----------------------
|
| 57 |
+
def predict(image: Image.Image):
|
| 58 |
+
x = preprocess(image)
|
| 59 |
+
preds = model.predict(x, verbose=0)[0]
|
| 60 |
+
|
| 61 |
+
idx = int(np.argmax(preds))
|
| 62 |
+
conf = float(preds[idx])
|
| 63 |
+
|
| 64 |
+
return class_names[idx], conf
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
# -----------------------
|
| 68 |
+
# UI (Gradio)
|
| 69 |
+
# -----------------------
|
| 70 |
+
interface = gr.Interface(
|
| 71 |
+
fn=predict,
|
| 72 |
+
inputs=gr.Image(type="pil", label="Upload an image"),
|
| 73 |
+
outputs=[gr.Label(label="Predicted class"), gr.Number(label="Confidence")],
|
| 74 |
+
title="Teachable Machine Classifier",
|
| 75 |
+
description="Upload an image to classify using your keras_Model.h5 Teachable Machine model."
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
if __name__ == "__main__":
|
| 79 |
+
interface.launch()
|
config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_name": "NeuRecAI",
|
| 3 |
+
"framework": "tensorflow",
|
| 4 |
+
"architecture": "EfficientNetB7",
|
| 5 |
+
"num_classes": 6,
|
| 6 |
+
"class_names": ["battery", "glass", "metal", "organic", "paper", "plastic"],
|
| 7 |
+
"input_size": [224, 224],
|
| 8 |
+
"description": "A Keras-based EfficientNetB7 model for classifying recyclable materials such as battery, glass, metal, organic, paper, and plastic."
|
| 9 |
+
}
|
keras_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8a1752d04f68ab1e8dcfcbd176f1af51b34050ba92fe37551edf81d3920f826b
|
| 3 |
+
size 2457008
|
model (1).keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:67df7f3c758938b37ab7aaee3fdc64b415607363d59888f036d14e7ce34cbfd0
|
| 3 |
+
size 261974088
|
model_weights.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:108bdbb008342b2921a89899327002a66d4e281b1cadab9b5e29fa92953b84b8
|
| 3 |
+
size 266726412
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
gradio
|
| 3 |
+
pillow
|
| 4 |
+
numpy
|
| 5 |
+
efficientnet
|
| 6 |
+
huggingface_hub >= 0.25.0
|