sachin commited on
Commit
863d782
·
1 Parent(s): 7c45c2d
Files changed (1) hide show
  1. src/server/main.py +7 -8
src/server/main.py CHANGED
@@ -616,18 +616,17 @@ async def visual_query(
616
  logger.error(f"Invalid JSON response: {str(e)}")
617
  raise HTTPException(status_code=500, detail="Invalid response format from visual query service")
618
 
619
-
620
- # Add this import at the top with other imports
621
  from fastapi.responses import StreamingResponse
 
622
 
623
  # Define supported languages for validation
624
- from enum import Enum
625
  class SupportedLanguage(str, Enum):
626
  kannada = "kannada"
627
  hindi = "hindi"
628
  tamil = "tamil"
629
 
630
- # Add the new endpoint
631
  @app.post("/v1/speech_to_speech",
632
  summary="Speech-to-Speech Conversion",
633
  description="Convert input speech to processed speech by calling an external speech-to-speech API. Rate limited to 5 requests per minute per user. Requires authentication.",
@@ -650,7 +649,7 @@ async def speech_to_speech(
650
  user_id = await get_current_user(credentials)
651
  logger.info("Processing speech-to-speech request", extra={
652
  "endpoint": "/v1/speech_to_speech",
653
- "filename": file.filename,
654
  "language": language,
655
  "client_ip": get_remote_address(request),
656
  "user_id": user_id
@@ -683,12 +682,12 @@ async def speech_to_speech(
683
  )
684
 
685
  except requests.Timeout:
686
- logger.error("External speech-to-speech API timed out")
687
  raise HTTPException(status_code=504, detail="External API timeout")
688
  except requests.RequestException as e:
689
- logger.error(f"External speech-to-speech API error: {str(e)}")
690
  raise HTTPException(status_code=500, detail=f"External API error: {str(e)}")
691
-
692
  if __name__ == "__main__":
693
  parser = argparse.ArgumentParser(description="Run the FastAPI server.")
694
  parser.add_argument("--port", type=int, default=settings.port, help="Port to run the server on.")
 
616
  logger.error(f"Invalid JSON response: {str(e)}")
617
  raise HTTPException(status_code=500, detail="Invalid response format from visual query service")
618
 
619
+ # Ensure these imports are at the top with other imports
 
620
  from fastapi.responses import StreamingResponse
621
+ from enum import Enum
622
 
623
  # Define supported languages for validation
 
624
  class SupportedLanguage(str, Enum):
625
  kannada = "kannada"
626
  hindi = "hindi"
627
  tamil = "tamil"
628
 
629
+ # Add the speech-to-speech endpoint
630
  @app.post("/v1/speech_to_speech",
631
  summary="Speech-to-Speech Conversion",
632
  description="Convert input speech to processed speech by calling an external speech-to-speech API. Rate limited to 5 requests per minute per user. Requires authentication.",
 
649
  user_id = await get_current_user(credentials)
650
  logger.info("Processing speech-to-speech request", extra={
651
  "endpoint": "/v1/speech_to_speech",
652
+ "audio_filename": file.filename, # Changed from 'filename' to avoid KeyError
653
  "language": language,
654
  "client_ip": get_remote_address(request),
655
  "user_id": user_id
 
682
  )
683
 
684
  except requests.Timeout:
685
+ logger.error("External speech-to-speech API timed out", extra={"user_id": user_id})
686
  raise HTTPException(status_code=504, detail="External API timeout")
687
  except requests.RequestException as e:
688
+ logger.error(f"External speech-to-speech API error: {str(e)}", extra={"user_id": user_id})
689
  raise HTTPException(status_code=500, detail=f"External API error: {str(e)}")
690
+
691
  if __name__ == "__main__":
692
  parser = argparse.ArgumentParser(description="Run the FastAPI server.")
693
  parser.add_argument("--port", type=int, default=settings.port, help="Port to run the server on.")