Spaces:
Paused
Paused
feat: add tempfile
Browse files
main.py
CHANGED
@@ -13,6 +13,7 @@ import uvicorn
|
|
13 |
import numpy as np
|
14 |
import librosa
|
15 |
import io
|
|
|
16 |
|
17 |
from core import WhisperLiveKit
|
18 |
from audio_processor import AudioProcessor
|
@@ -59,14 +60,11 @@ async def health_check():
|
|
59 |
@app.post("/detect-language")
|
60 |
async def detect_language(file: UploadFile = File(...)):
|
61 |
try:
|
62 |
-
#
|
63 |
-
|
64 |
-
|
65 |
-
# Save the uploaded file
|
66 |
-
file_path = os.path.join("uploads", file.filename)
|
67 |
-
with open(file_path, "wb") as buffer:
|
68 |
contents = await file.read()
|
69 |
-
|
70 |
|
71 |
# Use the language detector with the saved file
|
72 |
if language_detector:
|
|
|
13 |
import numpy as np
|
14 |
import librosa
|
15 |
import io
|
16 |
+
import tempfile
|
17 |
|
18 |
from core import WhisperLiveKit
|
19 |
from audio_processor import AudioProcessor
|
|
|
60 |
@app.post("/detect-language")
|
61 |
async def detect_language(file: UploadFile = File(...)):
|
62 |
try:
|
63 |
+
# Use a temporary directory for saving the uploaded file
|
64 |
+
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
65 |
+
file_path = temp_file.name
|
|
|
|
|
|
|
66 |
contents = await file.read()
|
67 |
+
temp_file.write(contents)
|
68 |
|
69 |
# Use the language detector with the saved file
|
70 |
if language_detector:
|