Spaces:
Running
Running
deveix
commited on
Commit
·
c114093
1
Parent(s):
60d22a8
fix dataframe
Browse files- app/main.py +10 -4
app/main.py
CHANGED
@@ -222,19 +222,25 @@ def extract_features(file_path):
|
|
222 |
|
223 |
# Combine all features into a single Series
|
224 |
features = pd.concat([mfccs_mean, spectral_centroids, spectral_rolloff, spectral_flux, spectral_contrast, pitch_mean, zero_crossings])
|
225 |
-
|
|
|
226 |
|
227 |
|
228 |
@app.post("/mlp")
|
229 |
async def handle_audio(file: UploadFile = File(...)):
|
230 |
try:
|
231 |
# Ensure that we are handling an MP3 file
|
232 |
-
if file.content_type
|
233 |
-
|
|
|
|
|
|
|
|
|
234 |
|
235 |
# Read the file's content
|
236 |
contents = await file.read()
|
237 |
-
temp_filename = f"app/{uuid4().hex}
|
|
|
238 |
|
239 |
# Save file to a temporary file if needed or process directly from memory
|
240 |
with open(temp_filename, "wb") as f:
|
|
|
222 |
|
223 |
# Combine all features into a single Series
|
224 |
features = pd.concat([mfccs_mean, spectral_centroids, spectral_rolloff, spectral_flux, spectral_contrast, pitch_mean, zero_crossings])
|
225 |
+
|
226 |
+
return pd.DataFrame([features])
|
227 |
|
228 |
|
229 |
@app.post("/mlp")
|
230 |
async def handle_audio(file: UploadFile = File(...)):
|
231 |
try:
|
232 |
# Ensure that we are handling an MP3 file
|
233 |
+
if file.content_type == "audio/mpeg" or file.content_type == "audio/mp3":
|
234 |
+
file_extension = ".mp3"
|
235 |
+
elif file.content_type == "audio/wav":
|
236 |
+
file_extension = ".wav"
|
237 |
+
else:
|
238 |
+
raise HTTPException(status_code=400, detail="Invalid file type. Supported types: MP3, WAV.")
|
239 |
|
240 |
# Read the file's content
|
241 |
contents = await file.read()
|
242 |
+
temp_filename = f"app/{uuid4().hex}{file_extension}"
|
243 |
+
|
244 |
|
245 |
# Save file to a temporary file if needed or process directly from memory
|
246 |
with open(temp_filename, "wb") as f:
|