Spaces:
Running
Running
deveix
commited on
Commit
·
f013965
1
Parent(s):
4d5d2d1
add new models
Browse files- app/main.py +7 -7
app/main.py
CHANGED
@@ -182,10 +182,10 @@ async def get_answer(item: Item, token: str = Depends(verify_token)):
|
|
182 |
raise HTTPException(status_code=500, detail=str(e))
|
183 |
|
184 |
# naive bayes
|
185 |
-
model = joblib.load('app/
|
186 |
pca = joblib.load('app/pca.pkl')
|
187 |
-
scaler = joblib.load('app/
|
188 |
-
label_encoder = joblib.load('app/
|
189 |
|
190 |
# def preprocess_audio(path, save_dir):
|
191 |
# y, sr = librosa.load(path)
|
@@ -332,23 +332,23 @@ async def handle_audio(file: UploadFile = File(...)):
|
|
332 |
# features = extract_features(temp_filename)
|
333 |
print("Extracted Features:", features)
|
334 |
|
335 |
-
|
336 |
# features = pca.transform(features)
|
337 |
features = np.array(features).reshape(1, -1)
|
338 |
|
339 |
# proceed with an inference
|
340 |
results = model.predict(features)
|
341 |
-
print(results)
|
342 |
# decoded_predictions = [label_encoder.classes_[i] for i in results]
|
343 |
|
344 |
# # Decode the predictions using the label encoder
|
345 |
-
|
|
|
346 |
# .tolist()
|
347 |
# Clean up the temporary file
|
348 |
os.remove(temp_filename)
|
349 |
|
350 |
# Return a successful response with decoded predictions
|
351 |
-
return {"message": "File processed successfully", "prediction":
|
352 |
except Exception as e:
|
353 |
print(e)
|
354 |
# Handle possible exceptions
|
|
|
182 |
raise HTTPException(status_code=500, detail=str(e))
|
183 |
|
184 |
# naive bayes
|
185 |
+
model = joblib.load('app/1713638595.315147_trained_model')
|
186 |
pca = joblib.load('app/pca.pkl')
|
187 |
+
scaler = joblib.load('app/1713638595.3178492_scaler.joblib')
|
188 |
+
label_encoder = joblib.load('app/1713638744.044928_label_encoder.joblib')
|
189 |
|
190 |
# def preprocess_audio(path, save_dir):
|
191 |
# y, sr = librosa.load(path)
|
|
|
332 |
# features = extract_features(temp_filename)
|
333 |
print("Extracted Features:", features)
|
334 |
|
335 |
+
features = scaler.transform(features)
|
336 |
# features = pca.transform(features)
|
337 |
features = np.array(features).reshape(1, -1)
|
338 |
|
339 |
# proceed with an inference
|
340 |
results = model.predict(features)
|
|
|
341 |
# decoded_predictions = [label_encoder.classes_[i] for i in results]
|
342 |
|
343 |
# # Decode the predictions using the label encoder
|
344 |
+
decoded_predictions = label_encoder.inverse_transform(results)
|
345 |
+
print(decoded_predictions)
|
346 |
# .tolist()
|
347 |
# Clean up the temporary file
|
348 |
os.remove(temp_filename)
|
349 |
|
350 |
# Return a successful response with decoded predictions
|
351 |
+
return {"message": "File processed successfully", "prediction": decoded_predictions}
|
352 |
except Exception as e:
|
353 |
print(e)
|
354 |
# Handle possible exceptions
|