Update main.py
Browse files
main.py
CHANGED
@@ -7,7 +7,7 @@ import joblib
|
|
7 |
import os
|
8 |
import sys
|
9 |
import pickle
|
10 |
-
|
11 |
# librosa is a Python library for analyzing audio and music. It can be used to extract the data from the audio files we will see it later.
|
12 |
import librosa
|
13 |
import librosa.display
|
@@ -103,11 +103,14 @@ def prediction(path1):
|
|
103 |
app = FastAPI()
|
104 |
|
105 |
|
|
|
|
|
106 |
@app.post("/")
|
107 |
async def read_root( file: UploadFile = File(...)):
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
113 |
return {"filename": file.filename, "filepath": f"/app/{file.filename}","prediction()":x}
|
|
|
7 |
import os
|
8 |
import sys
|
9 |
import pickle
|
10 |
+
import shutil
|
11 |
# librosa is a Python library for analyzing audio and music. It can be used to extract the data from the audio files we will see it later.
|
12 |
import librosa
|
13 |
import librosa.display
|
|
|
103 |
app = FastAPI()
|
104 |
|
105 |
|
106 |
+
|
107 |
+
|
108 |
@app.post("/")
|
109 |
async def read_root( file: UploadFile = File(...)):
|
110 |
+
file_extension = os.path.splitext(file.filename)[1]
|
111 |
+
with open("tmp"+file_extension, "wb") as buffer:
|
112 |
+
shutil.copyfileobj(file.file, buffer)
|
113 |
+
|
114 |
+
|
115 |
+
x = prediction("tmp"+file_extension)
|
116 |
return {"filename": file.filename, "filepath": f"/app/{file.filename}","prediction()":x}
|