-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
36 lines (29 loc) · 927 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pyrebase
from fastapi import FastAPI
from ML_functions import *
from decouple import config
app = FastAPI()
config = {
"apiKey": config("apiKey"),
"authDomain": config("authDomain"),
"databaseURL": config("databaseURL"),
"storageBucket": config("storageBucket"),
}
firebase = pyrebase.initialize_app(config)
@app.get("/")
def root():
return {"Music App": "Welcome to Music App"}
@app.get("/user/get_mood")
def get_mood():
storage = firebase.storage()
storage.child("tracks/recordingAudio.mp3").download("ml_model/data.mp3")
audio_link = "ml_model/data.mp3"
data = prepare_data(audio_link, n=n_mfcc)
mean, std = load_mean_std()
data = (data - mean) / std
model = tf.keras.models.load_model('ml_model/my_model')
probs = model.predict(np.expand_dims(data, axis=0))
return {
"status": "success",
"class ": class_mapping[np.argmax(probs)]
}