Michael Hu commited on
Commit
451d2b1
·
1 Parent(s): feebf14

fix gradio too many requests exception

Browse files
Files changed (1) hide show
  1. utils/tts.py +2 -49
utils/tts.py CHANGED
@@ -20,13 +20,7 @@ try:
20
  except AttributeError as e:
21
  # Specifically catch the EspeakWrapper.set_data_path error
22
  if "EspeakWrapper" in str(e) and "set_data_path" in str(e):
23
- logger.warning("Kokoro import failed due to EspeakWrapper.set_data_path issue")
24
- logger.info("Try to use Kokoro FastAPI server")
25
- client = Client("Remsky/Kokoro-TTS-Zero")
26
- result = client.predict(
27
- api_name="/lambda"
28
- )
29
- logger.debug(f"result get back from Kokora FastAPI server: {result}")
30
  if result:
31
  KOKORO_SPACE_AVAILABLE = True
32
  else:
@@ -36,47 +30,6 @@ except AttributeError as e:
36
  except ImportError:
37
  logger.warning("Kokoro TTS engine is not available")
38
 
39
- # Try to import Dia as fallback
40
- # if not KOKORO_AVAILABLE:
41
- # try:
42
- # logger.info("Attempting to import Dia TTS engine as fallback")
43
- # try:
44
- # # Check if required dependencies for Dia are available
45
- # import torch
46
- # logger.info("PyTorch is available for Dia TTS")
47
- # except ImportError as torch_err:
48
- # logger.error(f"PyTorch dependency for Dia TTS is missing: {str(torch_err)}")
49
- # raise ImportError(f"PyTorch dependency required for Dia TTS: {str(torch_err)}") from torch_err
50
-
51
- # # Try to import the Dia module
52
- # try:
53
- # from utils.tts_dia import _get_model as get_dia_model
54
- # logger.info("Successfully imported Dia TTS module")
55
-
56
- # # Verify the model can be accessed
57
- # logger.info("Verifying Dia model can be accessed")
58
- # model_info = get_dia_model.__module__
59
- # logger.info(f"Dia model module: {model_info}")
60
-
61
- # DIA_AVAILABLE = True
62
- # logger.info("Dia TTS engine is available as fallback")
63
- # except ImportError as module_err:
64
- # logger.error(f"Failed to import Dia TTS module: {str(module_err)}")
65
- # logger.error(f"Module path: {module_err.__traceback__.tb_frame.f_globals.get('__file__', 'unknown')}")
66
- # raise
67
- # except AttributeError as attr_err:
68
- # logger.error(f"Dia TTS module attribute error: {str(attr_err)}")
69
- # logger.error(f"This may indicate the module exists but has incorrect structure")
70
- # raise
71
- # except ImportError as e:
72
- # logger.error(f"Dia TTS engine is not available due to import error: {str(e)}")
73
- # logger.error(f"Import path attempted: {e.__traceback__.tb_frame.f_globals.get('__name__', 'unknown')}")
74
- # logger.warning("Will use dummy TTS implementation as fallback")
75
- # except Exception as e:
76
- # logger.error(f"Unexpected error initializing Dia TTS: {str(e)}")
77
- # logger.error(f"Error type: {type(e).__name__}")
78
- # logger.error("Will use dummy TTS implementation as fallback")
79
-
80
  class TTSEngine:
81
  def __init__(self, lang_code='z'):
82
  """Initialize TTS Engine with Kokoro or Dia as fallback
@@ -108,7 +61,7 @@ class TTSEngine:
108
  self.engine_type = "kokoro_space"
109
  logger.info("TTS engine successfully initialized with Kokoro FastAPI server")
110
  except Exception as kokoro_err:
111
- logger.error(f"Failed to initialize Kokoro pipeline: {str(kokoro_err)}")
112
  logger.error(f"Error type: {type(kokoro_err).__name__}")
113
  logger.info("Will try to fall back to Dia TTS engine")
114
 
 
20
  except AttributeError as e:
21
  # Specifically catch the EspeakWrapper.set_data_path error
22
  if "EspeakWrapper" in str(e) and "set_data_path" in str(e):
23
+ logger.warning("Kokoro import failed due to EspeakWrapper.set_data_path issue, falling back to Kokoro FastAPI server")
 
 
 
 
 
 
24
  if result:
25
  KOKORO_SPACE_AVAILABLE = True
26
  else:
 
30
  except ImportError:
31
  logger.warning("Kokoro TTS engine is not available")
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  class TTSEngine:
34
  def __init__(self, lang_code='z'):
35
  """Initialize TTS Engine with Kokoro or Dia as fallback
 
61
  self.engine_type = "kokoro_space"
62
  logger.info("TTS engine successfully initialized with Kokoro FastAPI server")
63
  except Exception as kokoro_err:
64
+ logger.error(f"Failed to initialize Kokoro space: {str(kokoro_err)}")
65
  logger.error(f"Error type: {type(kokoro_err).__name__}")
66
  logger.info("Will try to fall back to Dia TTS engine")
67