Update inference.py
Browse files- inference.py +0 -7
inference.py
CHANGED
|
@@ -3,14 +3,12 @@ import numpy as np
|
|
| 3 |
import re
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
# Pitch class mapping
|
| 7 |
NAME_TO_PC = {
|
| 8 |
"C":0,"C#":1,"Db":1,"D":2,"D#":3,"Eb":3,"E":4,"F":5,"F#":6,"Gb":6,
|
| 9 |
"G":7,"G#":8,"Ab":8,"A":9,"A#":10,"Bb":10,"B":11
|
| 10 |
}
|
| 11 |
NOTE_TOKEN_RE = re.compile(r"[A-Ga-g](?:#|b)?")
|
| 12 |
|
| 13 |
-
# Load model
|
| 14 |
MODEL_PATH = os.path.join(os.path.dirname(__file__), "chord_classifier.pkl")
|
| 15 |
clf = joblib.load(MODEL_PATH)
|
| 16 |
|
|
@@ -23,12 +21,7 @@ def notes_to_vector(notes_str: str):
|
|
| 23 |
vec[p] = 1
|
| 24 |
return vec
|
| 25 |
|
| 26 |
-
# 👇 Hugging Face Inference API entrypoint
|
| 27 |
def predict(inputs: str):
|
| 28 |
-
"""
|
| 29 |
-
Hugging Face will call this with {"inputs": "C E G"}.
|
| 30 |
-
Must return JSON-serializable output.
|
| 31 |
-
"""
|
| 32 |
vec = notes_to_vector(inputs)
|
| 33 |
if np.sum(vec) < 2:
|
| 34 |
return {"label": "Invalid input (need 2+ notes)"}
|
|
|
|
| 3 |
import re
|
| 4 |
import os
|
| 5 |
|
|
|
|
| 6 |
NAME_TO_PC = {
|
| 7 |
"C":0,"C#":1,"Db":1,"D":2,"D#":3,"Eb":3,"E":4,"F":5,"F#":6,"Gb":6,
|
| 8 |
"G":7,"G#":8,"Ab":8,"A":9,"A#":10,"Bb":10,"B":11
|
| 9 |
}
|
| 10 |
NOTE_TOKEN_RE = re.compile(r"[A-Ga-g](?:#|b)?")
|
| 11 |
|
|
|
|
| 12 |
MODEL_PATH = os.path.join(os.path.dirname(__file__), "chord_classifier.pkl")
|
| 13 |
clf = joblib.load(MODEL_PATH)
|
| 14 |
|
|
|
|
| 21 |
vec[p] = 1
|
| 22 |
return vec
|
| 23 |
|
|
|
|
| 24 |
def predict(inputs: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
vec = notes_to_vector(inputs)
|
| 26 |
if np.sum(vec) < 2:
|
| 27 |
return {"label": "Invalid input (need 2+ notes)"}
|