Spaces:
Sleeping
Sleeping
Update app/main.py
Browse files- app/main.py +0 -5
app/main.py
CHANGED
|
@@ -20,11 +20,9 @@ app.add_middleware(
|
|
| 20 |
)
|
| 21 |
|
| 22 |
tasks = {}
|
| 23 |
-
# --- KEY CHANGE: Use the /tmp directory which is always writable ---
|
| 24 |
TEMP_DIR = Path("/tmp/temp_audio")
|
| 25 |
TEMP_DIR.mkdir(exist_ok=True)
|
| 26 |
|
| 27 |
-
# Define allowed file extensions and max size (200MB)
|
| 28 |
ALLOWED_EXTENSIONS = {".wav", ".mp3", ".m4a", ".ogg", ".flac"}
|
| 29 |
MAX_FILE_SIZE = 200 * 1024 * 1024
|
| 30 |
|
|
@@ -34,7 +32,6 @@ async def upload_audio_file(background_tasks: BackgroundTasks, file: UploadFile
|
|
| 34 |
Receives an audio file, saves it temporarily to disk, and starts the
|
| 35 |
processing pipeline in the background. Includes validation for file type and size.
|
| 36 |
"""
|
| 37 |
-
# Validation: File Extension
|
| 38 |
file_ext = Path(file.filename).suffix.lower()
|
| 39 |
if file_ext not in ALLOWED_EXTENSIONS:
|
| 40 |
raise HTTPException(
|
|
@@ -42,12 +39,10 @@ async def upload_audio_file(background_tasks: BackgroundTasks, file: UploadFile
|
|
| 42 |
detail=f"Invalid audio format. Allowed formats: {', '.join(ALLOWED_EXTENSIONS)}"
|
| 43 |
)
|
| 44 |
|
| 45 |
-
# Validation: File Size
|
| 46 |
file_content = await file.read()
|
| 47 |
if len(file_content) > MAX_FILE_SIZE:
|
| 48 |
raise HTTPException(status_code=413, detail="File too large. Limit is 200MB.")
|
| 49 |
|
| 50 |
-
# Reset file pointer before saving
|
| 51 |
await file.seek(0)
|
| 52 |
|
| 53 |
task_id = str(uuid.uuid4())
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
tasks = {}
|
|
|
|
| 23 |
TEMP_DIR = Path("/tmp/temp_audio")
|
| 24 |
TEMP_DIR.mkdir(exist_ok=True)
|
| 25 |
|
|
|
|
| 26 |
ALLOWED_EXTENSIONS = {".wav", ".mp3", ".m4a", ".ogg", ".flac"}
|
| 27 |
MAX_FILE_SIZE = 200 * 1024 * 1024
|
| 28 |
|
|
|
|
| 32 |
Receives an audio file, saves it temporarily to disk, and starts the
|
| 33 |
processing pipeline in the background. Includes validation for file type and size.
|
| 34 |
"""
|
|
|
|
| 35 |
file_ext = Path(file.filename).suffix.lower()
|
| 36 |
if file_ext not in ALLOWED_EXTENSIONS:
|
| 37 |
raise HTTPException(
|
|
|
|
| 39 |
detail=f"Invalid audio format. Allowed formats: {', '.join(ALLOWED_EXTENSIONS)}"
|
| 40 |
)
|
| 41 |
|
|
|
|
| 42 |
file_content = await file.read()
|
| 43 |
if len(file_content) > MAX_FILE_SIZE:
|
| 44 |
raise HTTPException(status_code=413, detail="File too large. Limit is 200MB.")
|
| 45 |
|
|
|
|
| 46 |
await file.seek(0)
|
| 47 |
|
| 48 |
task_id = str(uuid.uuid4())
|