Update tasks/audio.py
Browse files- tasks/audio.py +9 -2
tasks/audio.py
CHANGED
@@ -5,6 +5,7 @@ from sklearn.metrics import accuracy_score
|
|
5 |
import os
|
6 |
import joblib
|
7 |
from pathlib import Path
|
|
|
8 |
|
9 |
from sklearn.preprocessing import StandardScaler
|
10 |
from .utils.fourier import FourierPreprocessor, Fourier
|
@@ -19,7 +20,9 @@ router = APIRouter()
|
|
19 |
|
20 |
DESCRIPTION = "Random Forest"
|
21 |
ROUTE = "/audio"
|
22 |
-
MODEL_PATH = Path(__file__).parent / "audio_models" / "RandomForestClassifier_withScaler.pkl"
|
|
|
|
|
23 |
|
24 |
@router.post(ROUTE, tags=["Audio Task"], description=DESCRIPTION)
|
25 |
async def evaluate_audio(request: AudioEvaluationRequest):
|
@@ -60,7 +63,11 @@ async def evaluate_audio(request: AudioEvaluationRequest):
|
|
60 |
# Extract audio samples from test_dataset
|
61 |
x_test = [sample["audio"]["array"] for sample in test_dataset]
|
62 |
|
63 |
-
clf = joblib.load(MODEL_PATH)
|
|
|
|
|
|
|
|
|
64 |
predictions = clf.predict(x_test)
|
65 |
|
66 |
# --------------------------------------------------------------------------------------------
|
|
|
5 |
import os
|
6 |
import joblib
|
7 |
from pathlib import Path
|
8 |
+
import pickle
|
9 |
|
10 |
from sklearn.preprocessing import StandardScaler
|
11 |
from .utils.fourier import FourierPreprocessor, Fourier
|
|
|
20 |
|
21 |
DESCRIPTION = "Random Forest"
|
22 |
ROUTE = "/audio"
|
23 |
+
# MODEL_PATH = Path(__file__).parent / "audio_models" / "RandomForestClassifier_withScaler.pkl"
|
24 |
+
MODEL_PATH = Path(__file__).parent / "audio_models" / "RandomForestClassifier_withScaler_cloudpickle.pkl"
|
25 |
+
|
26 |
|
27 |
@router.post(ROUTE, tags=["Audio Task"], description=DESCRIPTION)
|
28 |
async def evaluate_audio(request: AudioEvaluationRequest):
|
|
|
63 |
# Extract audio samples from test_dataset
|
64 |
x_test = [sample["audio"]["array"] for sample in test_dataset]
|
65 |
|
66 |
+
# clf = joblib.load(MODEL_PATH)
|
67 |
+
|
68 |
+
with open(MODEL_PATH, 'rb') as f:
|
69 |
+
clf = pickle.load(f)
|
70 |
+
|
71 |
predictions = clf.predict(x_test)
|
72 |
|
73 |
# --------------------------------------------------------------------------------------------
|