ceymox commited on
Commit
fea2fe4
Β·
verified Β·
1 Parent(s): f6583c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -61
app.py CHANGED
@@ -37,20 +37,22 @@ os.makedirs(AUDIO_DIR, exist_ok=True)
37
  audio_cache = {}
38
 
39
  def load_chatterbox_model():
40
- """Try multiple ways to load ChatterboxTTS"""
41
  global MODEL, CHATTERBOX_AVAILABLE
42
 
43
- # Method 1: Try original ChatterboxTTS import
44
  try:
45
  from chatterbox.src.chatterbox.tts import ChatterboxTTS
46
- logger.info("βœ… Found ChatterboxTTS in chatterbox.src.chatterbox.tts")
47
  MODEL = ChatterboxTTS.from_pretrained(DEVICE)
48
  CHATTERBOX_AVAILABLE = True
49
  return True
50
  except ImportError as e:
51
- logger.warning(f"Method 1 failed: {e}")
 
 
52
 
53
- # Method 2: Try direct chatterbox import
54
  try:
55
  from chatterbox.tts import ChatterboxTTS
56
  logger.info("βœ… Found ChatterboxTTS in chatterbox.tts")
@@ -59,58 +61,77 @@ def load_chatterbox_model():
59
  return True
60
  except ImportError as e:
61
  logger.warning(f"Method 2 failed: {e}")
 
 
62
 
63
- # Method 3: Try if it's installed as a package
64
  try:
65
- from chatterbox import ChatterboxTTS
66
- logger.info("βœ… Found ChatterboxTTS as package")
67
- MODEL = ChatterboxTTS.from_pretrained(DEVICE)
 
 
 
 
 
68
  CHATTERBOX_AVAILABLE = True
69
  return True
70
  except ImportError as e:
71
  logger.warning(f"Method 3 failed: {e}")
 
 
72
 
73
- # Method 4: Try alternative package name
74
  try:
75
- import chatterbox_tts
76
- logger.info("βœ… Found chatterbox_tts package")
77
- MODEL = chatterbox_tts.ChatterboxTTS.from_pretrained(DEVICE)
78
- CHATTERBOX_AVAILABLE = True
79
- return True
 
 
 
 
 
 
 
 
 
 
 
 
80
  except ImportError as e:
81
  logger.warning(f"Method 4 failed: {e}")
 
 
82
 
83
- # Method 5: Try loading from local files
84
  try:
85
- import sys
86
- # Add current directory to path
87
- current_dir = os.path.dirname(os.path.abspath(__file__))
88
- chatterbox_path = os.path.join(current_dir, "chatterbox", "src")
89
- if os.path.exists(chatterbox_path):
90
- sys.path.insert(0, chatterbox_path)
91
- from chatterbox.tts import ChatterboxTTS
92
- logger.info("βœ… Found ChatterboxTTS in local files")
93
- MODEL = ChatterboxTTS.from_pretrained(DEVICE)
94
- CHATTERBOX_AVAILABLE = True
95
- return True
 
 
 
 
 
 
96
  except Exception as e:
97
- logger.warning(f"Method 5 failed: {e}")
98
 
99
- # Method 6: Check if files exist and guide user
100
- possible_locations = [
101
- "./chatterbox/src/chatterbox/tts.py",
102
- "./chatterbox/tts.py",
103
- "./chatterbox_tts.py",
104
- "./src/chatterbox/tts.py"
105
- ]
106
-
107
- existing_files = [loc for loc in possible_locations if os.path.exists(loc)]
108
- if existing_files:
109
- logger.error(f"❌ Found ChatterboxTTS files at {existing_files} but couldn't import!")
110
- logger.error("πŸ’‘ Check your file structure and __init__.py files")
111
- else:
112
- logger.error("❌ No ChatterboxTTS files found!")
113
- logger.error("πŸ’‘ Upload your ChatterboxTTS package to the Space")
114
 
115
  return False
116
 
@@ -453,26 +474,20 @@ def create_gradio_interface():
453
  gr.Markdown("""
454
  ### 🚨 Currently Using Fallback Model
455
 
456
- You're hearing beep sounds because the real ChatterboxTTS isn't loaded. To fix this:
 
 
 
 
 
 
 
 
 
457
 
458
- 1. **Upload your ChatterboxTTS package** to this Space
459
- 2. **Ensure proper file structure**: `chatterbox/src/chatterbox/tts.py`
460
- 3. **Add `__init__.py` files** in each directory
461
- 4. **Restart the Space** after uploading
462
 
463
- πŸ“ Expected structure:
464
- ```
465
- your-space/
466
- β”œβ”€β”€ app.py
467
- β”œβ”€β”€ requirements.txt
468
- └── chatterbox/
469
- β”œβ”€β”€ __init__.py
470
- └── src/
471
- β”œβ”€β”€ __init__.py
472
- └── chatterbox/
473
- β”œβ”€β”€ __init__.py
474
- └── tts.py
475
- ```
476
  """)
477
 
478
  with gr.Row():
 
37
  audio_cache = {}
38
 
39
  def load_chatterbox_model():
40
+ """Try multiple ways to load ChatterboxTTS from Resemble AI"""
41
  global MODEL, CHATTERBOX_AVAILABLE
42
 
43
+ # Method 1: Try Resemble AI ChatterboxTTS (most likely)
44
  try:
45
  from chatterbox.src.chatterbox.tts import ChatterboxTTS
46
+ logger.info("βœ… Found Resemble AI ChatterboxTTS in chatterbox.src.chatterbox.tts")
47
  MODEL = ChatterboxTTS.from_pretrained(DEVICE)
48
  CHATTERBOX_AVAILABLE = True
49
  return True
50
  except ImportError as e:
51
+ logger.warning(f"Method 1 (Resemble AI standard path) failed: {e}")
52
+ except Exception as e:
53
+ logger.warning(f"Method 1 failed with error: {e}")
54
 
55
+ # Method 2: Try alternative import path for Resemble AI repo
56
  try:
57
  from chatterbox.tts import ChatterboxTTS
58
  logger.info("βœ… Found ChatterboxTTS in chatterbox.tts")
 
61
  return True
62
  except ImportError as e:
63
  logger.warning(f"Method 2 failed: {e}")
64
+ except Exception as e:
65
+ logger.warning(f"Method 2 failed with error: {e}")
66
 
67
+ # Method 3: Try direct chatterbox import
68
  try:
69
+ import chatterbox
70
+ if hasattr(chatterbox, 'ChatterboxTTS'):
71
+ MODEL = chatterbox.ChatterboxTTS.from_pretrained(DEVICE)
72
+ elif hasattr(chatterbox, 'tts') and hasattr(chatterbox.tts, 'ChatterboxTTS'):
73
+ MODEL = chatterbox.tts.ChatterboxTTS.from_pretrained(DEVICE)
74
+ else:
75
+ raise ImportError("ChatterboxTTS not found in chatterbox module")
76
+ logger.info("βœ… Found ChatterboxTTS via direct import")
77
  CHATTERBOX_AVAILABLE = True
78
  return True
79
  except ImportError as e:
80
  logger.warning(f"Method 3 failed: {e}")
81
+ except Exception as e:
82
+ logger.warning(f"Method 3 failed with error: {e}")
83
 
84
+ # Method 4: Try exploring the installed package
85
  try:
86
+ import chatterbox
87
+ import inspect
88
+
89
+ # Log what's available in the chatterbox package
90
+ logger.info(f"Chatterbox module path: {chatterbox.__file__}")
91
+ logger.info(f"Chatterbox contents: {dir(chatterbox)}")
92
+
93
+ # Try to find ChatterboxTTS class anywhere in the module
94
+ for name, obj in inspect.getmembers(chatterbox):
95
+ if name == 'ChatterboxTTS' or (inspect.isclass(obj) and 'TTS' in name):
96
+ logger.info(f"Found potential TTS class: {name}")
97
+ MODEL = obj.from_pretrained(DEVICE)
98
+ CHATTERBOX_AVAILABLE = True
99
+ return True
100
+
101
+ raise ImportError("ChatterboxTTS class not found in chatterbox package")
102
+
103
  except ImportError as e:
104
  logger.warning(f"Method 4 failed: {e}")
105
+ except Exception as e:
106
+ logger.warning(f"Method 4 failed with error: {e}")
107
 
108
+ # Method 5: Check if the GitHub repo was installed correctly
109
  try:
110
+ import pkg_resources
111
+ try:
112
+ pkg_resources.get_distribution('chatterbox')
113
+ logger.info("βœ… Chatterbox package is installed")
114
+ except pkg_resources.DistributionNotFound:
115
+ logger.warning("❌ Chatterbox package not found in installed packages")
116
+
117
+ # Try to import and inspect what we got
118
+ import chatterbox
119
+ chatterbox_path = chatterbox.__path__[0] if hasattr(chatterbox, '__path__') else str(chatterbox.__file__)
120
+ logger.info(f"Chatterbox installed at: {chatterbox_path}")
121
+
122
+ # List all available modules/classes
123
+ import pkgutil
124
+ for importer, modname, ispkg in pkgutil.walk_packages(chatterbox.__path__, chatterbox.__name__ + "."):
125
+ logger.info(f"Available module: {modname}")
126
+
127
  except Exception as e:
128
+ logger.warning(f"Package inspection failed: {e}")
129
 
130
+ # If we get here, the GitHub repo might have a different structure
131
+ logger.error("❌ Could not load ChatterboxTTS from Resemble AI repository")
132
+ logger.error("πŸ’‘ The GitHub repo might have a different structure than expected")
133
+ logger.error("πŸ”— Repository: https://github.com/resemble-ai/chatterbox.git")
134
+ logger.error("πŸ“‹ Check the repo's README for correct import instructions")
 
 
 
 
 
 
 
 
 
 
135
 
136
  return False
137
 
 
474
  gr.Markdown("""
475
  ### 🚨 Currently Using Fallback Model
476
 
477
+ You're hearing beep sounds because the real ChatterboxTTS isn't loaded.
478
+
479
+ **The Resemble AI ChatterboxTTS from GitHub should auto-install from requirements.txt.**
480
+
481
+ If you're still seeing this message:
482
+
483
+ 1. **Check build logs** for any installation errors
484
+ 2. **Verify requirements.txt** contains: `git+https://github.com/resemble-ai/chatterbox.git`
485
+ 3. **Restart the Space** if needed
486
+ 4. **Check logs** for import errors
487
 
488
+ πŸ“ GitHub repo being used: https://github.com/resemble-ai/chatterbox.git
 
 
 
489
 
490
+ If the GitHub installation fails, you can alternatively upload the package manually.
 
 
 
 
 
 
 
 
 
 
 
 
491
  """)
492
 
493
  with gr.Row():