kevinwang676 commited on
Commit
deca852
·
verified ·
1 Parent(s): b0e461f

Update api_v2.py

Browse files
Files changed (1) hide show
  1. api_v2.py +12 -6
api_v2.py CHANGED
@@ -445,7 +445,7 @@ async def tts_handle(req:dict):
445
  print(f"Removed temporary file: {temp_file}")
446
  except Exception as e:
447
  print(f"Error removing temporary file {temp_file}: {e}")
448
-
449
  return StreamingResponse(streaming_generator(tts_generator, media_type), media_type=f"audio/{media_type}")
450
  else:
451
  sr, audio_data = next(tts_generator)
@@ -459,7 +459,8 @@ async def tts_handle(req:dict):
459
  print(f"Removed temporary file: {temp_file}")
460
  except Exception as e:
461
  print(f"Error removing temporary file {temp_file}: {e}")
462
-
 
463
  return Response(audio_data, media_type=f"audio/{media_type}")
464
  except Exception as e:
465
  # Clean up temporary files in case of error
@@ -470,7 +471,8 @@ async def tts_handle(req:dict):
470
  print(f"Removed temporary file: {temp_file}")
471
  except Exception as cleanup_error:
472
  print(f"Error removing temporary file {temp_file}: {cleanup_error}")
473
-
 
474
  return JSONResponse(status_code=400, content={"message": f"tts failed", "Exception": str(e)})
475
 
476
 
@@ -612,7 +614,8 @@ async def set_gpt_weights(weights_path: str = None):
612
  if temp_file and os.path.exists(temp_file):
613
  os.remove(temp_file)
614
  print(f"Removed temporary weights file: {temp_file}")
615
-
 
616
  return JSONResponse(status_code=200, content={"message": "success"})
617
  except Exception as e:
618
  # Clean up temp file in case of error
@@ -622,7 +625,8 @@ async def set_gpt_weights(weights_path: str = None):
622
  print(f"Removed temporary weights file: {temp_file}")
623
  except Exception as cleanup_error:
624
  print(f"Error removing temporary file {temp_file}: {cleanup_error}")
625
-
 
626
  return JSONResponse(status_code=400, content={"message": f"change gpt weight failed", "Exception": str(e)})
627
 
628
  @APP.get("/set_sovits_weights")
@@ -646,7 +650,8 @@ async def set_sovits_weights(weights_path: str = None):
646
  if temp_file and os.path.exists(temp_file):
647
  os.remove(temp_file)
648
  print(f"Removed temporary weights file: {temp_file}")
649
-
 
650
  return JSONResponse(status_code=200, content={"message": "success"})
651
  except Exception as e:
652
  # Clean up temp file in case of error
@@ -657,6 +662,7 @@ async def set_sovits_weights(weights_path: str = None):
657
  except Exception as cleanup_error:
658
  print(f"Error removing temporary file {temp_file}: {cleanup_error}")
659
 
 
660
  return JSONResponse(status_code=400, content={"message": f"change sovits weight failed", "Exception": str(e)})
661
 
662
 
 
445
  print(f"Removed temporary file: {temp_file}")
446
  except Exception as e:
447
  print(f"Error removing temporary file {temp_file}: {e}")
448
+ torch.cuda.empty_cache()
449
  return StreamingResponse(streaming_generator(tts_generator, media_type), media_type=f"audio/{media_type}")
450
  else:
451
  sr, audio_data = next(tts_generator)
 
459
  print(f"Removed temporary file: {temp_file}")
460
  except Exception as e:
461
  print(f"Error removing temporary file {temp_file}: {e}")
462
+
463
+ torch.cuda.empty_cache()
464
  return Response(audio_data, media_type=f"audio/{media_type}")
465
  except Exception as e:
466
  # Clean up temporary files in case of error
 
471
  print(f"Removed temporary file: {temp_file}")
472
  except Exception as cleanup_error:
473
  print(f"Error removing temporary file {temp_file}: {cleanup_error}")
474
+
475
+ torch.cuda.empty_cache()
476
  return JSONResponse(status_code=400, content={"message": f"tts failed", "Exception": str(e)})
477
 
478
 
 
614
  if temp_file and os.path.exists(temp_file):
615
  os.remove(temp_file)
616
  print(f"Removed temporary weights file: {temp_file}")
617
+
618
+ torch.cuda.empty_cache()
619
  return JSONResponse(status_code=200, content={"message": "success"})
620
  except Exception as e:
621
  # Clean up temp file in case of error
 
625
  print(f"Removed temporary weights file: {temp_file}")
626
  except Exception as cleanup_error:
627
  print(f"Error removing temporary file {temp_file}: {cleanup_error}")
628
+
629
+ torch.cuda.empty_cache()
630
  return JSONResponse(status_code=400, content={"message": f"change gpt weight failed", "Exception": str(e)})
631
 
632
  @APP.get("/set_sovits_weights")
 
650
  if temp_file and os.path.exists(temp_file):
651
  os.remove(temp_file)
652
  print(f"Removed temporary weights file: {temp_file}")
653
+
654
+ torch.cuda.empty_cache()
655
  return JSONResponse(status_code=200, content={"message": "success"})
656
  except Exception as e:
657
  # Clean up temp file in case of error
 
662
  except Exception as cleanup_error:
663
  print(f"Error removing temporary file {temp_file}: {cleanup_error}")
664
 
665
+ torch.cuda.empty_cache()
666
  return JSONResponse(status_code=400, content={"message": f"change sovits weight failed", "Exception": str(e)})
667
 
668