Upload 4 files
Browse files- app.py +41 -0
- labels.txt +30 -0
- lite_model.h5 +3 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# LOAD MODEL (.h5) ✅
|
| 7 |
+
model = tf.keras.models.load_model("lite_model.h5", compile=False)
|
| 8 |
+
|
| 9 |
+
# LABELS
|
| 10 |
+
class_names = [
|
| 11 |
+
"Didgeridoo", "Tambourine", "Xylophone", "acordian", "alphorn",
|
| 12 |
+
"bagpipes", "banjo", "bongo drum", "casaba", "castanets",
|
| 13 |
+
"clarinet", "clavichord", "concertina", "drums", "dulcimer",
|
| 14 |
+
"flute", "guiro", "guitar", "harmonica", "harp",
|
| 15 |
+
"marakas", "ocarina", "piano", "saxaphone", "sitar",
|
| 16 |
+
"steel drum", "trombone", "trumpet", "tuba", "violin"
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
IMG_SIZE = (224, 224)
|
| 20 |
+
|
| 21 |
+
def preprocess_image(image):
|
| 22 |
+
image = image.convert("RGB")
|
| 23 |
+
image = image.resize(IMG_SIZE)
|
| 24 |
+
image = np.array(image) / 255.0
|
| 25 |
+
image = np.expand_dims(image, axis=0)
|
| 26 |
+
return image
|
| 27 |
+
|
| 28 |
+
def predict(image):
|
| 29 |
+
img = preprocess_image(image)
|
| 30 |
+
preds = model.predict(img)[0]
|
| 31 |
+
return {class_names[i]: float(preds[i]) for i in range(len(class_names))}
|
| 32 |
+
|
| 33 |
+
interface = gr.Interface(
|
| 34 |
+
fn=predict,
|
| 35 |
+
inputs=gr.Image(type="pil"),
|
| 36 |
+
outputs=gr.Label(num_top_classes=3),
|
| 37 |
+
title="🎵 Musical Instrument Classifier",
|
| 38 |
+
description="Upload an image to predict the instrument",
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
interface.launch()
|
labels.txt
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Didgeridoo
|
| 2 |
+
Tambourine
|
| 3 |
+
Xylophone
|
| 4 |
+
acordian
|
| 5 |
+
alphorn
|
| 6 |
+
bagpipes
|
| 7 |
+
banjo
|
| 8 |
+
bongo drum
|
| 9 |
+
casaba
|
| 10 |
+
castanets
|
| 11 |
+
clarinet
|
| 12 |
+
clavichord
|
| 13 |
+
concertina
|
| 14 |
+
drums
|
| 15 |
+
dulcimer
|
| 16 |
+
flute
|
| 17 |
+
guiro
|
| 18 |
+
guitar
|
| 19 |
+
harmonica
|
| 20 |
+
harp
|
| 21 |
+
marakas
|
| 22 |
+
ocarina
|
| 23 |
+
piano
|
| 24 |
+
saxaphone
|
| 25 |
+
sitar
|
| 26 |
+
steel drum
|
| 27 |
+
trombone
|
| 28 |
+
trumpet
|
| 29 |
+
tuba
|
| 30 |
+
violin
|
lite_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a0289284e1aebe443c99970f0595da798db889931384222fca2e2d11825be90d
|
| 3 |
+
size 105276552
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
gradio
|
| 3 |
+
numpy
|
| 4 |
+
Pillow
|