Spaces:
Runtime error
Runtime error
kurianbenoy
commited on
Commit
•
c165076
1
Parent(s):
68efc4a
Create app.py file
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio
|
2 |
+
import torchaudio
|
3 |
+
from fastai.vision.all import *
|
4 |
+
from fastai.learner import load_learner
|
5 |
+
from torchvision.utils import save_image
|
6 |
+
from huggingface_hub import hf_hub_download
|
7 |
+
|
8 |
+
|
9 |
+
model = load_learner(
|
10 |
+
hf_hub_download("kurianbenoy/music_genre_classification_baseline", "model.pkl")
|
11 |
+
)
|
12 |
+
|
13 |
+
EXAMPLES_PATH = Path("./examples")
|
14 |
+
labels = model.dls.vocab
|
15 |
+
|
16 |
+
interface_options = {
|
17 |
+
"title": "Music Genre Classification",
|
18 |
+
"description": "A simple baseline model for classifying music genres with fast.ai on [Kaggle competition data](https://www.kaggle.com/competitions/kaggle-pog-series-s01e02/data)",
|
19 |
+
"examples": [f"{EXAMPLES_PATH}/{f.name}" for f in EXAMPLES_PATH.iterdir()],
|
20 |
+
"interpretation": "default",
|
21 |
+
"layout": "horizontal",
|
22 |
+
"theme": "default",
|
23 |
+
}
|
24 |
+
|
25 |
+
|
26 |
+
def predict(img):
|
27 |
+
img = PILImage.create(img)
|
28 |
+
_pred, _pred_w_idx, probs = model.predict(img)
|
29 |
+
labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
|
30 |
+
return labels_probs
|
31 |
+
|
32 |
+
|
33 |
+
demo = gradio.Interface(
|
34 |
+
fn=predict,
|
35 |
+
inputs=gradio.inputs.Image(shape=(512, 512)),
|
36 |
+
outputs=gradio.outputs.Label(num_top_classes=5),
|
37 |
+
)
|
38 |
+
|
39 |
+
launch_options = {
|
40 |
+
"enable_queue": True,
|
41 |
+
"share": False,
|
42 |
+
}
|
43 |
+
|
44 |
+
demo.launch(**launch_options)
|