ranar110 commited on
Commit
2fdce4b
·
1 Parent(s): aee4240

Fix: Update all paths to be absolute and robust

Browse files
Files changed (1) hide show
  1. main.py +4 -3
main.py CHANGED
@@ -38,7 +38,9 @@ async def detect_voice(
38
  audio_url: str = Form(None),
39
  x_api_key: str = Depends(verify_api_key)
40
  ):
41
- UPLOAD_DIR = "uploads" # Ensure this is defined or imported, doing it locally for safety if imports fail context
 
 
42
 
43
  # Check if we received a JSON body (request is not None)
44
  if request:
@@ -52,9 +54,8 @@ async def detect_voice(
52
 
53
  decoded_data = base64.b64decode(b64_data)
54
  # Create a temporary file
55
- import os # ensuring os is available
56
  filename = f"upload_{uuid.uuid4()}.{request.audio_format or 'mp3'}"
57
- file_location = f"{UPLOAD_DIR}/{filename}"
58
  with open(file_location, "wb") as f:
59
  f.write(decoded_data)
60
 
 
38
  audio_url: str = Form(None),
39
  x_api_key: str = Depends(verify_api_key)
40
  ):
41
+ import os
42
+ UPLOAD_DIR = os.path.join(os.getcwd(), "uploads")
43
+ os.makedirs(UPLOAD_DIR, exist_ok=True)
44
 
45
  # Check if we received a JSON body (request is not None)
46
  if request:
 
54
 
55
  decoded_data = base64.b64decode(b64_data)
56
  # Create a temporary file
 
57
  filename = f"upload_{uuid.uuid4()}.{request.audio_format or 'mp3'}"
58
+ file_location = os.path.join(UPLOAD_DIR, filename)
59
  with open(file_location, "wb") as f:
60
  f.write(decoded_data)
61