Mohamed41 commited on
Commit
12ac423
·
1 Parent(s): 8e8f4e3

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -6
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
- # try:
109
- # json_data = await request.json()
110
- # except error:
111
- # print (error)
112
- x = prediction(os.path.join("/app", file.filename))
 
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}